]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMILibrary/Test/fmi_import_test.c
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / Test / fmi_import_test.c
diff --git a/org.simantics.fmil.core/native/FMILibrary/Test/fmi_import_test.c b/org.simantics.fmil.core/native/FMILibrary/Test/fmi_import_test.c
new file mode 100644 (file)
index 0000000..8121c22
--- /dev/null
@@ -0,0 +1,96 @@
+/*\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
+\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
+\r
+#define BUFFER 1000\r
+\r
+extern int fmi1_test(fmi_import_context_t* context, const char* dirPath);\r
+extern int fmi2_test(fmi_import_context_t* context, const char* dirPath);\r
+\r
+void importlogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message)\r
+{\r
+        printf("module = %s, log level = %d: %s\n", module, log_level, message);\r
+}\r
+\r
+void do_exit(int code)\r
+{\r
+       printf("Press 'Enter' to exit\n");\r
+       /* getchar(); */\r
+       exit(code);\r
+}\r
+          \r
+int main(int argc, char *argv[])\r
+{\r
+       const char* FMUPath;\r
+       const char* tmpPath;\r
+       jm_callbacks callbacks;\r
+       fmi_import_context_t* context;\r
+       fmi_version_enu_t version;\r
+       int ret;\r
+\r
+       if(argc < 3) {\r
+               printf("Usage: %s <fmu_file> <temporary_dir>\n", argv[0]);\r
+               do_exit(CTEST_RETURN_FAIL);\r
+       }\r
+\r
+       FMUPath = argv[1];\r
+       tmpPath = argv[2];\r
+\r
+\r
+       callbacks.malloc = malloc;\r
+    callbacks.calloc = calloc;\r
+    callbacks.realloc = realloc;\r
+    callbacks.free = free;\r
+    callbacks.logger = importlogger;\r
+       callbacks.log_level = jm_log_level_all;\r
+    callbacks.context = 0;\r
+\r
+#ifdef FMILIB_GENERATE_BUILD_STAMP\r
+       printf("Library build stamp:\n%s\n", fmilib_get_build_stamp());\r
+#endif\r
+\r
+       context = fmi_import_allocate_context(&callbacks);\r
+\r
+       version = fmi_import_get_fmi_version(context, FMUPath, tmpPath);\r
+\r
+       if(version == fmi_version_1_enu) {\r
+               ret = fmi1_test(context, tmpPath);\r
+       }\r
+       else if(version == fmi_version_2_0_enu) {\r
+               ret = fmi2_test(context, tmpPath);\r
+       }\r
+       else {\r
+        fmi_import_free_context(context);\r
+               printf("Only versions 1.0 and 2.0 are supported so far\n");\r
+               do_exit(CTEST_RETURN_FAIL);\r
+       }\r
+\r
+       fmi_import_free_context(context);\r
+       \r
+       if(ret == CTEST_RETURN_SUCCESS)\r
+               printf("Everything seems to be OK since you got this far=)!\n");\r
+\r
+       do_exit(ret);\r
+\r
+       return 0;\r
+}\r
+\r
+\r