]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMILibrary/Test/FMI1/fmi1_import_test.c
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / Test / FMI1 / fmi1_import_test.c
diff --git a/org.simantics.fmil.core/native/FMILibrary/Test/FMI1/fmi1_import_test.c b/org.simantics.fmil.core/native/FMILibrary/Test/FMI1/fmi1_import_test.c
new file mode 100644 (file)
index 0000000..98e4e89
--- /dev/null
@@ -0,0 +1,81 @@
+/*\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 fmi1logger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_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 = %d;  %s (%s): %s\n", status, instanceName, category, msg);\r
+}\r
+\r
+          \r
+int fmi1_test(fmi_import_context_t* context, const char* dirPath)\r
+{\r
+       fmi1_callback_functions_t callBackFunctions;\r
+       const char* modelIdentifier;\r
+       const char* modelName;\r
+       const char*  GUID;\r
+       jm_status_enu_t status;\r
+\r
+       fmi1_import_t* fmu;     \r
+\r
+       callBackFunctions.logger = fmi1logger;\r
+       callBackFunctions.allocateMemory = calloc;\r
+       callBackFunctions.freeMemory = free;\r
+\r
+       fmu = fmi1_import_parse_xml(context, dirPath);\r
+\r
+       if(!fmu) {\r
+               printf("Error parsing XML, exiting\n");\r
+               return (CTEST_RETURN_FAIL);\r
+       }\r
+       modelIdentifier = fmi1_import_get_model_identifier(fmu);\r
+       modelName = fmi1_import_get_model_name(fmu);\r
+       GUID = fmi1_import_get_GUID(fmu);\r
+\r
+       printf("Model name: %s\n", modelName);\r
+    printf("Model identifier: %s\n", modelIdentifier);\r
+    printf("Model GUID: %s\n", GUID);\r
+\r
+       status = fmi1_import_create_dllfmu(fmu, callBackFunctions, 0);\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", fmi1_import_get_version(fmu));\r
+\r
+       fmi1_import_destroy_dllfmu(fmu);\r
+\r
+       fmi1_import_free(fmu);\r
+\r
+       return (CTEST_RETURN_SUCCESS);\r
+}\r
+\r
+\r