--- /dev/null
+/*\r
+ Copyright (C) 2012 Modelon AB\r
+\r
+ This program is free software: you can redistribute it and/or modify\r
+ it under the terms of the BSD style license.
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ FMILIB_License.txt file for more details.\r
+\r
+ You should have received a copy of the FMILIB_License.txt file\r
+ along with this program. If not, contact Modelon AB <http://www.modelon.com>.\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <stdarg.h>\r
+\r
+#include <config_test.h>\r
+#include <fmilib.h>\r
+#include <JM/jm_portability.h>\r
+\r
+#define BUFFER 1000\r
+\r
+/* Logger function used by the FMU internally */\r
+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
+{\r
+ int len;\r
+ char msg[BUFFER];\r
+ va_list argp; \r
+ va_start(argp, message);\r
+ len = jm_vsnprintf(msg, BUFFER, message, argp);\r
+ printf("fmiStatus = %s; %s (%s): %s\n", fmi2_status_to_string(status), instanceName, category, msg);\r
+}\r
+\r
+static void stepFinished(fmi2_component_environment_t env, fmi2_status_t status) {\r
+ printf("stepFinished is called wiht fmiStatus = %s\n", fmi2_status_to_string(status));\r
+}\r
+ \r
+int fmi2_test(fmi_import_context_t* context, const char* dirPath)\r
+{\r
+ fmi2_callback_functions_t callBackFunctions;\r
+ const char* modelIdentifier;\r
+ const char* modelName;\r
+ const char* GUID;\r
+ jm_status_enu_t status;\r
+\r
+ fmi2_import_t* fmu; \r
+ fmi2_fmu_kind_enu_t fmukind;\r
+\r
+ callBackFunctions.logger = fmi2logger;\r
+ callBackFunctions.allocateMemory = calloc;\r
+ callBackFunctions.freeMemory = free;\r
+ callBackFunctions.stepFinished = stepFinished;\r
+ callBackFunctions.componentEnvironment = 0;\r
+\r
+ fmu = fmi2_import_parse_xml(context, dirPath, 0);\r
+\r
+ if(!fmu) {\r
+ printf("Error parsing XML, exiting\n");\r
+ return (CTEST_RETURN_FAIL);\r
+ }\r
+ modelName = fmi2_import_get_model_name(fmu);\r
+ GUID = fmi2_import_get_GUID(fmu);\r
+\r
+ printf("Model name: %s\n", modelName);\r
+ if(fmi2_import_get_fmu_kind(fmu) != fmi2_fmu_kind_cs) {\r
+ modelIdentifier = fmi2_import_get_model_identifier_ME(fmu);\r
+ printf("Model identifier for ME: %s\n", modelIdentifier);\r
+ fmukind = fmi2_fmu_kind_me;\r
+ }\r
+ else if(fmi2_import_get_fmu_kind(fmu) != fmi2_fmu_kind_me) {\r
+ modelIdentifier = fmi2_import_get_model_identifier_CS(fmu);\r
+ printf("Model identifier for CS: %s\n", modelIdentifier);\r
+ fmukind = fmi2_fmu_kind_cs;\r
+ }\r
+ else {\r
+ printf("Unxepected FMU kind, exiting\n");\r
+ return (CTEST_RETURN_FAIL);\r
+ }\r
+ printf("Model GUID: %s\n", GUID);\r
+\r
+ status = fmi2_import_create_dllfmu(fmu, fmukind, &callBackFunctions);\r
+ if (status == jm_status_error) {\r
+ printf("Could not create the DLL loading mechanism(C-API).\n");\r
+ return(CTEST_RETURN_FAIL);\r
+ }\r
+\r
+ printf("Version returned from FMU: %s\n", fmi2_import_get_version(fmu));\r
+\r
+ fmi2_import_destroy_dllfmu(fmu);\r
+\r
+ fmi2_import_free(fmu);\r
+\r
+ return (CTEST_RETURN_SUCCESS);\r
+}\r
+\r
+\r