-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from filip-stenstrom/variable_no_type
Check variability!=continuous for non-real variables
- Loading branch information
Showing
15 changed files
with
246 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "fmilib.h" | ||
#include "fmil_test.h" | ||
#include "config_test.h" | ||
|
||
/* global used by logger - make sure to reset between different XML parsings */ | ||
int g_n_logger_found_err_msg = 0; | ||
|
||
static void log_default(jm_string module, jm_log_level_enu_t log_level, jm_string message) | ||
{ | ||
printf("module = %s, log level = %d: %s\n", module, log_level, message); | ||
} | ||
|
||
static void logger_verify(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message) { | ||
const char* msg_exp = "Only Real variables can have variability='continuous'"; | ||
if (!strncmp(msg_exp, message, strlen(msg_exp))) { | ||
g_n_logger_found_err_msg++; | ||
} | ||
log_default(module, log_level, message); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
fmi1_import_t *xml; | ||
jm_callbacks * cb = jm_get_default_callbacks(); | ||
fmi_import_context_t *ctx; | ||
|
||
if (argc != 2) { | ||
printf("Usage: %s <variable_bad_causality_variability_dir>\n", argv[0]); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
cb->logger = logger_verify; | ||
ctx = fmi_import_allocate_context(cb); | ||
if (ctx == NULL) { | ||
printf("Failed to allocate memory"); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
xml = fmi1_import_parse_xml(ctx, argv[1]); | ||
fmi_import_free_context(ctx); | ||
if (xml == NULL) { | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
if (g_n_logger_found_err_msg != 4) { | ||
printf("incorrect number of variables found with invalid variability\n"); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
return CTEST_RETURN_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Test/FMI1/parser_test_xmls/variable_bad_type_variability/modelDescription.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<fmiModelDescription | ||
fmiVersion="1.0" | ||
modelName="modelName" | ||
modelIdentifier="modelIdentifier" | ||
guid="d7d98edb-d924-4104-87db-227bb677fc95" | ||
numberOfContinuousStates="0" | ||
numberOfEventIndicators="0" | ||
> | ||
|
||
<TypeDefinitions> | ||
<Type name="MyEnum"> | ||
<EnumerationType quantity="TypeQuantity"> | ||
<Item name="item1"/> | ||
</EnumerationType> | ||
</Type> | ||
</TypeDefinitions> | ||
|
||
<ModelVariables> | ||
<!-- non-Reals can't have variability='continuous' (default value) --> | ||
<ScalarVariable name="var0" valueReference="0"> | ||
<Boolean/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var1" valueReference="1"> | ||
<Integer/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var2" valueReference="2"> | ||
<Enumeration declaredType="MyEnum"/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var3" valueReference="3"> | ||
<String/> | ||
</ScalarVariable> | ||
|
||
<ScalarVariable name="var4" valueReference="4"> <!-- OK, should not give error --> | ||
<Real/> | ||
</ScalarVariable> | ||
</ModelVariables> | ||
|
||
</fmiModelDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "fmilib.h" | ||
#include "fmil_test.h" | ||
#include "config_test.h" | ||
|
||
/* global used by logger - make sure to reset between different XML parsings */ | ||
int g_n_logger_found_err_msg = 0; | ||
|
||
static void log_default(jm_string module, jm_log_level_enu_t log_level, jm_string message) | ||
{ | ||
printf("module = %s, log level = %d: %s\n", module, log_level, message); | ||
} | ||
|
||
static void logger_verify(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message) { | ||
const char* msg_exp = "Only Real variables can have variability='continuous'"; | ||
if (!strncmp(msg_exp, message, strlen(msg_exp))) { | ||
g_n_logger_found_err_msg++; | ||
} | ||
log_default(module, log_level, message); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
fmi2_import_t *xml; | ||
jm_callbacks * cb = jm_get_default_callbacks(); | ||
fmi_import_context_t *ctx; | ||
|
||
if (argc != 2) { | ||
printf("Usage: %s <variable_bad_causality_variability_dir>\n", argv[0]); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
cb->logger = logger_verify; | ||
ctx = fmi_import_allocate_context(cb); | ||
if (ctx == NULL) { | ||
printf("Failed to allocate memory"); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
xml = fmi2_import_parse_xml(ctx, argv[1], NULL); | ||
fmi_import_free_context(ctx); | ||
if (xml == NULL) { | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
if (g_n_logger_found_err_msg != 4) { | ||
printf("incorrect number of variables found with invalid variability\n"); | ||
return CTEST_RETURN_FAIL; | ||
} | ||
|
||
return CTEST_RETURN_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Test/FMI2/parser_test_xmls/variable_bad_type_variability/modelDescription.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<fmiModelDescription | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
fmiVersion="2.0" | ||
modelName="modelName" | ||
guid="d7d98edb-d924-4104-87db-227bb677fc95"> | ||
|
||
<CoSimulation modelIdentifier="modelIdentifier" /> | ||
|
||
<TypeDefinitions> | ||
<SimpleType name="MyEnum"> | ||
<Enumeration quantity="TypeQuantity"> | ||
<Item name="item1" value="1"/> | ||
</Enumeration> | ||
</SimpleType> | ||
</TypeDefinitions> | ||
|
||
<ModelVariables> | ||
<!-- non-Reals can't have variability='continuous' (default value) --> | ||
<ScalarVariable name="var0" valueReference="0"> | ||
<Boolean/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var1" valueReference="1"> | ||
<Integer/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var2" valueReference="2"> | ||
<Enumeration declaredType="MyEnum"/> | ||
</ScalarVariable> | ||
<ScalarVariable name="var3" valueReference="3"> | ||
<String/> | ||
</ScalarVariable> | ||
|
||
<ScalarVariable name="var4" valueReference="4"> <!-- OK, should not give error --> | ||
<Real/> | ||
</ScalarVariable> | ||
</ModelVariables> | ||
|
||
<ModelStructure /> | ||
|
||
</fmiModelDescription> |
Oops, something went wrong.