2 Copyright (C) 2012 Modelon AB
\r
4 This program is free software: you can redistribute it and/or modify
\r
5 it under the terms of the BSD style license.
7 This program is distributed in the hope that it will be useful,
\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
10 FMILIB_License.txt file for more details.
\r
12 You should have received a copy of the FMILIB_License.txt file
\r
13 along with this program. If not, contact Modelon AB <http://www.modelon.com>.
\r
20 #include <config_test.h>
\r
22 #include <JM/jm_portability.h>
\r
26 /* Logger function used by the FMU internally */
\r
27 static void fmi2logger(fmi2_component_environment_t env, fmi2_string_t instanceName, fmi2_status_t status, fmi2_string_t category, fmi2_string_t message, ...)
\r
32 va_start(argp, message);
\r
33 len = jm_vsnprintf(msg, BUFFER, message, argp);
\r
34 printf("fmiStatus = %s; %s (%s): %s\n", fmi2_status_to_string(status), instanceName, category, msg);
\r
37 static void stepFinished(fmi2_component_environment_t env, fmi2_status_t status) {
\r
38 printf("stepFinished is called wiht fmiStatus = %s\n", fmi2_status_to_string(status));
\r
41 int fmi2_test(fmi_import_context_t* context, const char* dirPath)
\r
43 fmi2_callback_functions_t callBackFunctions;
\r
44 const char* modelIdentifier;
\r
45 const char* modelName;
\r
47 jm_status_enu_t status;
\r
49 fmi2_import_t* fmu;
\r
50 fmi2_fmu_kind_enu_t fmukind;
\r
52 callBackFunctions.logger = fmi2logger;
\r
53 callBackFunctions.allocateMemory = calloc;
\r
54 callBackFunctions.freeMemory = free;
\r
55 callBackFunctions.stepFinished = stepFinished;
\r
56 callBackFunctions.componentEnvironment = 0;
\r
58 fmu = fmi2_import_parse_xml(context, dirPath, 0);
\r
61 printf("Error parsing XML, exiting\n");
\r
62 return (CTEST_RETURN_FAIL);
\r
64 modelName = fmi2_import_get_model_name(fmu);
\r
65 GUID = fmi2_import_get_GUID(fmu);
\r
67 printf("Model name: %s\n", modelName);
\r
68 if(fmi2_import_get_fmu_kind(fmu) != fmi2_fmu_kind_cs) {
\r
69 modelIdentifier = fmi2_import_get_model_identifier_ME(fmu);
\r
70 printf("Model identifier for ME: %s\n", modelIdentifier);
\r
71 fmukind = fmi2_fmu_kind_me;
\r
73 else if(fmi2_import_get_fmu_kind(fmu) != fmi2_fmu_kind_me) {
\r
74 modelIdentifier = fmi2_import_get_model_identifier_CS(fmu);
\r
75 printf("Model identifier for CS: %s\n", modelIdentifier);
\r
76 fmukind = fmi2_fmu_kind_cs;
\r
79 printf("Unxepected FMU kind, exiting\n");
\r
80 return (CTEST_RETURN_FAIL);
\r
82 printf("Model GUID: %s\n", GUID);
\r
84 status = fmi2_import_create_dllfmu(fmu, fmukind, &callBackFunctions);
\r
85 if (status == jm_status_error) {
\r
86 printf("Could not create the DLL loading mechanism(C-API).\n");
\r
87 return(CTEST_RETURN_FAIL);
\r
90 printf("Version returned from FMU: %s\n", fmi2_import_get_version(fmu));
\r
92 fmi2_import_destroy_dllfmu(fmu);
\r
94 fmi2_import_free(fmu);
\r
96 return (CTEST_RETURN_SUCCESS);
\r