FMI Library: part of JModelica.org
fmi_import_test.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Modelon AB
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the BSD style license.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  FMILIB_License.txt file for more details.
11 
12  You should have received a copy of the FMILIB_License.txt file
13  along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 
20 #include <config_test.h>
21 #include <fmilib.h>
22 
23 #define BUFFER 1000
24 
25 extern int fmi1_test(fmi_import_context_t* context, const char* dirPath);
26 extern int fmi2_test(fmi_import_context_t* context, const char* dirPath);
27 
29 {
30  printf("module = %s, log level = %d: %s\n", module, log_level, message);
31 }
32 
33 void do_exit(int code)
34 {
35  printf("Press 'Enter' to exit\n");
36  /* getchar(); */
37  exit(code);
38 }
39 
40 int main(int argc, char *argv[])
41 {
42  const char* FMUPath;
43  const char* tmpPath;
45  fmi_import_context_t* context;
46  fmi_version_enu_t version;
47  int ret;
48 
49  if(argc < 3) {
50  printf("Usage: %s <fmu_file> <temporary_dir>\n", argv[0]);
51  do_exit(CTEST_RETURN_FAIL);
52  }
53 
54  FMUPath = argv[1];
55  tmpPath = argv[2];
56 
57 
58  callbacks.malloc = malloc;
59  callbacks.calloc = calloc;
60  callbacks.realloc = realloc;
61  callbacks.free = free;
62  callbacks.logger = importlogger;
63  callbacks.log_level = jm_log_level_all;
64  callbacks.context = 0;
65 
66 #ifdef FMILIB_GENERATE_BUILD_STAMP
67  printf("Library build stamp:\n%s\n", fmilib_get_build_stamp());
68 #endif
69 
70  context = fmi_import_allocate_context(&callbacks);
71 
72  version = fmi_import_get_fmi_version(context, FMUPath, tmpPath);
73 
74  if(version == fmi_version_1_enu) {
75  ret = fmi1_test(context, tmpPath);
76  }
77  else if(version == fmi_version_2_0_enu) {
78  ret = fmi2_test(context, tmpPath);
79  }
80  else {
81  fmi_import_free_context(context);
82  printf("Only versions 1.0 and 2.0 are supported so far\n");
83  do_exit(CTEST_RETURN_FAIL);
84  }
85 
86  fmi_import_free_context(context);
87 
88  if(ret == CTEST_RETURN_SUCCESS)
89  printf("Everything seems to be OK since you got this far=)!\n");
90 
91  do_exit(ret);
92 
93  return 0;
94 }
95 
96 
void importlogger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
jm_calloc_f calloc
Allocate zero initialized memory.
Definition: jm_callbacks.h:77
size_t jm_callbacks * c
int fmi2_test(fmi_import_context_t *context, const char *dirPath)
fmi_version_enu_t
Suported versions of FMI standard.
Definition: fmi_version.h:34
int fmi1_test(fmi_import_context_t *context, const char *dirPath)
jm_log_level_enu_t
Log levels supported via the logger functions in jm_callbacks.
Definition: jm_types.h:51
Debug messages. Only enabled if library is configured with FMILIB_ENABLE_LOG_LEVEL_DEBUG.
Definition: jm_types.h:59
jm_log_level_enu_t log_level
Logging level.
Definition: jm_callbacks.h:85
void do_exit(int code)
v callbacks
Include file to be used in client applications of the FMI Library.
int main(int argc, char *argv[])
jm_malloc_f malloc
Allocate non-initialized memory.
Definition: jm_callbacks.h:75
jm_voidp context
Arbitrary context pointer passed to the logger function.
Definition: jm_callbacks.h:87
const char * jm_string
A constant string.
Definition: jm_types.h:33
The callbacks struct is sent to all the modules in the library.
Definition: jm_callbacks.h:73
struct fmi_xml_context_t fmi_import_context_t
FMI version independent library context. Opaque struct returned from fmi_import_allocate_context() ...
FMILIB_EXPORT fmi_import_context_t * fmi_import_allocate_context(jm_callbacks *callbacks)
Create fmi_import_context_t structure.
FMILIB_EXPORT fmi_version_enu_t fmi_import_get_fmi_version(fmi_import_context_t *c, const char *fileName, const char *dirName)
Unzip an FMU specified by the fileName into directory dirName and parse XML to get FMI standard versi...
FMILIB_EXPORT void fmi_import_free_context(fmi_import_context_t *c)
Free memory allocated for the library context.
jm_realloc_f realloc
Re-allocate memory.
Definition: jm_callbacks.h:79
jm_free_f free
Free-allocated memory.
Definition: jm_callbacks.h:81
jm_logger_f logger
Logging callback.
Definition: jm_callbacks.h:83