]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/Test/FMI1/fmi1_import_test.c
Merge "Added getters and setters for all FMI data types."
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / Test / FMI1 / fmi1_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.
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 #include <JM/jm_portability.h>\r
23 \r
24 #define BUFFER 1000\r
25 \r
26 /* Logger function used by the FMU internally */\r
27 static void fmi1logger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message, ...)\r
28 {\r
29     int len;\r
30         char msg[BUFFER];\r
31         va_list argp;   \r
32         va_start(argp, message);\r
33         len = jm_vsnprintf(msg, BUFFER, message, argp);\r
34         printf("fmiStatus = %d;  %s (%s): %s\n", status, instanceName, category, msg);\r
35 }\r
36 \r
37            \r
38 int fmi1_test(fmi_import_context_t* context, const char* dirPath)\r
39 {\r
40         fmi1_callback_functions_t callBackFunctions;\r
41         const char* modelIdentifier;\r
42         const char* modelName;\r
43         const char*  GUID;\r
44         jm_status_enu_t status;\r
45 \r
46         fmi1_import_t* fmu;     \r
47 \r
48         callBackFunctions.logger = fmi1logger;\r
49         callBackFunctions.allocateMemory = calloc;\r
50         callBackFunctions.freeMemory = free;\r
51 \r
52         fmu = fmi1_import_parse_xml(context, dirPath);\r
53 \r
54         if(!fmu) {\r
55                 printf("Error parsing XML, exiting\n");\r
56                 return (CTEST_RETURN_FAIL);\r
57         }\r
58         modelIdentifier = fmi1_import_get_model_identifier(fmu);\r
59         modelName = fmi1_import_get_model_name(fmu);\r
60         GUID = fmi1_import_get_GUID(fmu);\r
61 \r
62         printf("Model name: %s\n", modelName);\r
63     printf("Model identifier: %s\n", modelIdentifier);\r
64     printf("Model GUID: %s\n", GUID);\r
65 \r
66         status = fmi1_import_create_dllfmu(fmu, callBackFunctions, 0);\r
67         if (status == jm_status_error) {\r
68                 printf("Could not create the DLL loading mechanism(C-API).\n");\r
69                 return(CTEST_RETURN_FAIL);\r
70         }\r
71 \r
72         printf("Version returned from FMU:   %s\n", fmi1_import_get_version(fmu));\r
73 \r
74         fmi1_import_destroy_dllfmu(fmu);\r
75 \r
76         fmi1_import_free(fmu);\r
77 \r
78         return (CTEST_RETURN_SUCCESS);\r
79 }\r
80 \r
81 \r