]> gerrit.simantics Code Review - simantics/fmil.git/blob - 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
1 /*\r
2     Copyright (C) 2012 Modelon AB\r
3 \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.\r
6 \r
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
11 \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
14 */\r
15 \r
16 #include <stdio.h>\r
17 #include <stdlib.h>\r
18 #include <stdarg.h>\r
19 \r
20 #include <config_test.h>\r
21 #include <fmilib.h>\r
22 \r
23 #define BUFFER 1000\r
24 \r
25 extern int fmi1_test(fmi_import_context_t* context, const char* dirPath);\r
26 extern int fmi2_test(fmi_import_context_t* context, const char* dirPath);\r
27 \r
28 void importlogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message)\r
29 {\r
30         printf("module = %s, log level = %d: %s\n", module, log_level, message);\r
31 }\r
32 \r
33 void do_exit(int code)\r
34 {\r
35         printf("Press 'Enter' to exit\n");\r
36         /* getchar(); */\r
37         exit(code);\r
38 }\r
39            \r
40 int main(int argc, char *argv[])\r
41 {\r
42         const char* FMUPath;\r
43         const char* tmpPath;\r
44         jm_callbacks callbacks;\r
45         fmi_import_context_t* context;\r
46         fmi_version_enu_t version;\r
47         int ret;\r
48 \r
49         if(argc < 3) {\r
50                 printf("Usage: %s <fmu_file> <temporary_dir>\n", argv[0]);\r
51                 do_exit(CTEST_RETURN_FAIL);\r
52         }\r
53 \r
54         FMUPath = argv[1];\r
55         tmpPath = argv[2];\r
56 \r
57 \r
58         callbacks.malloc = malloc;\r
59     callbacks.calloc = calloc;\r
60     callbacks.realloc = realloc;\r
61     callbacks.free = free;\r
62     callbacks.logger = importlogger;\r
63         callbacks.log_level = jm_log_level_all;\r
64     callbacks.context = 0;\r
65 \r
66 #ifdef FMILIB_GENERATE_BUILD_STAMP\r
67         printf("Library build stamp:\n%s\n", fmilib_get_build_stamp());\r
68 #endif\r
69 \r
70         context = fmi_import_allocate_context(&callbacks);\r
71 \r
72         version = fmi_import_get_fmi_version(context, FMUPath, tmpPath);\r
73 \r
74         if(version == fmi_version_1_enu) {\r
75                 ret = fmi1_test(context, tmpPath);\r
76         }\r
77         else if(version == fmi_version_2_0_enu) {\r
78                 ret = fmi2_test(context, tmpPath);\r
79         }\r
80         else {\r
81         fmi_import_free_context(context);\r
82                 printf("Only versions 1.0 and 2.0 are supported so far\n");\r
83                 do_exit(CTEST_RETURN_FAIL);\r
84         }\r
85 \r
86         fmi_import_free_context(context);\r
87         \r
88         if(ret == CTEST_RETURN_SUCCESS)\r
89                 printf("Everything seems to be OK since you got this far=)!\n");\r
90 \r
91         do_exit(ret);\r
92 \r
93         return 0;\r
94 }\r
95 \r
96 \r