Skip to content
Permalink
Browse files

Fix type_get_quantity return value

It should now do as the API says:
- real, integer, enum: empty string
- string, boolean: nullptr
  • Loading branch information
filip-stenstrom committed Feb 13, 2020
1 parent 9b6304d commit 59f9d8cd686e8e7941d9b24742ea40c40a2e78b2
@@ -44,6 +44,7 @@ set(XML_ME_PATH ${FMU_DUMMY_FOLDER}/modelDescription_me.xml)
set(XML_CS_PATH ${FMU_DUMMY_FOLDER}/modelDescription_cs.xml)
set(XML_CS_TC_PATH ${FMU_DUMMY_FOLDER}/modelDescription_cs_tc.xml)
set(XML_MF_PATH ${FMU_DUMMY_FOLDER}/modelDescription_malformed.xml)
set(TYPE_DEFINITIONS_MODEL_DESC_DIR ${RTTESTDIR}/FMI1/parser_test_xmls/type_definitions)

set(SHARED_LIBRARY_ME_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}fmu1_dll_me${CMAKE_SHARED_LIBRARY_SUFFIX})
set(SHARED_LIBRARY_CS_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}fmu1_dll_cs${CMAKE_SHARED_LIBRARY_SUFFIX})
@@ -66,6 +67,8 @@ compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs_tc"

add_executable (fmi1_import_default_experiment_test ${RTTESTDIR}/FMI1/fmi1_import_default_experiment_test.c)
target_link_libraries (fmi1_import_default_experiment_test ${FMILIBFORTEST} )
add_executable(fmi1_type_definitions_test ${RTTESTDIR}/FMI1/fmi1_import_type_definitions_test.c)
target_link_libraries(fmi1_type_definitions_test ${FMILIBFORTEST})

add_executable (fmi1_xml_parsing_test ${RTTESTDIR}/FMI1/fmi1_xml_parsing_test.c)
target_link_libraries (fmi1_xml_parsing_test ${FMILIBFORTEST} )
@@ -88,6 +91,7 @@ to_native_c_path(${TEST_OUTPUT_FOLDER}/tempfolder FMU_TEMPFOLDER)

add_test(ctest_fmi1_xml_parsing_test fmi1_import_default_experiment_test ${RTTESTDIR}/FMI1/parser_test_xmls/default_experiment/)
add_test(ctest_fmi1_xml_parsing_test fmi1_xml_parsing_test ${RTTESTDIR}/FMI1/parser_test_xmls/)
add_test(ctest_fmi1_type_definitions_test fmi1_type_definitions_test ${TYPE_DEFINITIONS_MODEL_DESC_DIR})
ADD_TEST(ctest_fmi_import_me_test fmi_import_me_test ${FMU_ME_PATH} ${FMU_TEMPFOLDER})
ADD_TEST(ctest_fmi_import_cs_test fmi_import_cs_test ${FMU_CS_PATH} ${FMU_TEMPFOLDER} "modelDescription_cs.xml")
ADD_TEST(ctest_fmi_import_cs_tc_test fmi_import_cs_test ${FMU_CS_TC_PATH} ${FMU_TEMPFOLDER} "modelDescription_cs_tc.xml")
@@ -137,6 +141,7 @@ if(FMILIB_BUILD_BEFORE_TESTS)
ctest_fmi1_capi_me_test
ctest_fmi1_logger_test_run
ctest_fmi1_xml_parsing_test
ctest_fmi1_type_definitions_test
PROPERTIES DEPENDS ctest_build_all)
endif()

@@ -48,6 +48,8 @@ set(VARIABLE_NO_TYPE_MODEL_DESC_DIR
${RTTESTDIR}/FMI2/parser_test_xmls/variable_no_type)
set(VARIABLE_BAD_VARIABILITY_CAUSALITY_MODEL_DESC_DIR
${RTTESTDIR}/FMI2/parser_test_xmls/variable_bad_variability_causality)
set(TYPE_DEFINITIONS_MODEL_DESC_DIR
${RTTESTDIR}/FMI2/parser_test_xmls/type_definitions)

set(SHARED_LIBRARY_ME_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}fmu2_dll_me${CMAKE_SHARED_LIBRARY_SUFFIX})
set(SHARED_LIBRARY_CS_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}fmu2_dll_cs${CMAKE_SHARED_LIBRARY_SUFFIX})
@@ -83,6 +85,8 @@ add_executable(fmi2_import_variable_test ${RTTESTDIR}/FMI2/fmi2_import_variable_
target_link_libraries(fmi2_import_variable_test ${FMILIBFORTEST})
add_executable(fmi2_import_default_experiment_test ${RTTESTDIR}/FMI2/fmi2_import_default_experiment_test.c)
target_link_libraries(fmi2_import_default_experiment_test ${FMILIBFORTEST})
add_executable(fmi2_type_definitions_test ${RTTESTDIR}/FMI2/fmi2_import_type_definitions_test.c)
target_link_libraries(fmi2_type_definitions_test ${FMILIBFORTEST})
add_executable(fmi2_variable_no_type_test
${RTTESTDIR}/FMI2/fmi2_variable_no_type_test.c)
target_link_libraries(fmi2_variable_no_type_test ${FMILIBFORTEST})
@@ -124,6 +128,9 @@ add_test(ctest_fmi2_variable_no_type_test
add_test(ctest_fmi2_variable_bad_variability_causality_test
fmi2_variable_bad_variability_causality_test
${VARIABLE_BAD_VARIABILITY_CAUSALITY_MODEL_DESC_DIR})
add_test(ctest_fmi2_type_definitions_test
fmi2_type_definitions_test
${TYPE_DEFINITIONS_MODEL_DESC_DIR})
add_test(ctest_fmi2_enum_test
fmi2_enum_test)

@@ -139,6 +146,7 @@ if(FMILIB_BUILD_BEFORE_TESTS)
ctest_fmi2_import_variable_test
ctest_fmi2_import_default_experiment_test
ctest_fmi2_variable_no_type_test
ctest_fmi2_type_definitions_test
ctest_fmi2_enum_test
ctest_fmi2_variable_bad_variability_causality_test
PROPERTIES DEPENDS ctest_build_all)
@@ -0,0 +1,76 @@
#include <stdio.h>
#include <float.h>

#include "fmilib.h"
#include "config_test.h"
#include "fmil_test.h"

static fmi1_import_t *parse_xml(const char *model_desc_path)
{
jm_callbacks *cb = jm_get_default_callbacks();
fmi_import_context_t *ctx = fmi_import_allocate_context(cb);
fmi1_import_t *xml;

if (ctx == NULL) {
return NULL;
}

xml = fmi1_import_parse_xml(ctx, model_desc_path, NULL);

fmi_import_free_context(ctx);
return xml;
}

/* verify correct default values when quantity is not specified */
static int test_quantity_default(fmi1_import_t *xml)
{
fmi1_import_variable_typedef_t *t;
fmi1_import_type_definitions_t* tds;
unsigned int n_tds;
unsigned int i; /* td_idx */
const char* tname;
const char* str_empty = "";

tds = fmi1_import_get_type_definitions(xml);
ASSERT_MSG(tds != NULL, "could not get type definitions");
n_tds = fmi1_import_get_type_definition_number(tds);
ASSERT_MSG(n_tds >= 5, "too few typedefs found");

/* check types that should by default return empty string */
for (i = 0; i < n_tds ; i++) {
t = fmi1_import_get_typedef(tds, i);
tname = fmi1_import_get_type_name(t);
if ( !strcmp("name_real", tname) ||
!strcmp("name_integer", tname) ||
!strcmp("name_enumeration", tname)) {
ASSERT_MSG(strcmp(str_empty, fmi1_import_get_type_quantity(t)) == 0, "expected default quantity to be an empty string");
} else if ( !strcmp("name_string", tname) ||
!strcmp("name_boolean", tname)) {
ASSERT_MSG(fmi1_import_get_type_quantity(t) == NULL, "expected default quantity to be null ptr");
}
}

return TEST_OK;
}

int main(int argc, char **argv)
{
fmi1_import_t *xml;
int ret = 1;
if (argc != 2) {
printf("Usage: %s <path_to_dir_containing_float_modelDescription>\n", argv[0]);
return CTEST_RETURN_FAIL;
}

printf("Running fmi1_import_variable_types_test\n");

xml = parse_xml(argv[1]);
if (xml == NULL) {
return CTEST_RETURN_FAIL;
}

ret &= test_quantity_default(xml);

fmi1_import_free(xml);
return ret == 0 ? CTEST_RETURN_FAIL : CTEST_RETURN_SUCCESS;
}
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="3.0"
modelName="test_type_definitions"
modelIdentifier="model_identifier"
numberOfContinuousStates="0"
numberOfEventIndicators="0"
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f9e0}"
description="N/A"
version="1.0"
generationDateAndTime="2011-09-23T16:57:33Z"
variableNamingConvention="structured">

<TypeDefinitions>

<!-- test that no specified quantity defaults to empty string -->
<Type name="name_real">
<RealType/>
</Type>
<Type name="name_integer">
<IntegerType/>
</Type>
<Type name="name_enum">
<EnumerationType>
<Item name="EnumVar0"/>
</EnumerationType>
</Type>

<!-- test that no specified quantity defaults to null pointer -->
<Type name="name_string">
<StringType/>
</Type>
<Type name="name_boolean">
<BooleanType/>
</Type>

</TypeDefinitions>

<ModelVariables>
</ModelVariables>

</fmiModelDescription>
@@ -0,0 +1,76 @@
#include <stdio.h>
#include <float.h>

#include "fmilib.h"
#include "config_test.h"
#include "fmil_test.h"

static fmi2_import_t *parse_xml(const char *model_desc_path)
{
jm_callbacks *cb = jm_get_default_callbacks();
fmi_import_context_t *ctx = fmi_import_allocate_context(cb);
fmi2_import_t *xml;

if (ctx == NULL) {
return NULL;
}

xml = fmi2_import_parse_xml(ctx, model_desc_path, NULL);

fmi_import_free_context(ctx);
return xml;
}

/* verify correct default values when quantity is not specified */
static int test_quantity_default(fmi2_import_t *xml)
{
fmi2_import_variable_typedef_t *t;
fmi2_import_type_definitions_t* tds;
unsigned int n_tds;
unsigned int i; /* td_idx */
const char* tname;
const char* str_empty = "";

tds = fmi2_import_get_type_definitions(xml);
ASSERT_MSG(tds != NULL, "could not get type definitions");
n_tds = fmi2_import_get_type_definition_number(tds);
ASSERT_MSG(n_tds >= 5, "too few typedefs found");

/* check types that should by default return empty string */
for (i = 0; i < n_tds ; i++) {
t = fmi2_import_get_typedef(tds, i);
tname = fmi2_import_get_type_name(t);
if ( !strcmp("name_real", tname) ||
!strcmp("name_integer", tname) ||
!strcmp("name_enumeration", tname)) {
ASSERT_MSG(strcmp(str_empty, fmi2_import_get_type_quantity(t)) == 0, "expected default quantity to be an empty string");
} else if ( !strcmp("name_string", tname) ||
!strcmp("name_boolean", tname)) {
ASSERT_MSG(fmi2_import_get_type_quantity(t) == NULL, "expected default quantity to be null ptr");
}
}

return TEST_OK;
}

int main(int argc, char **argv)
{
fmi2_import_t *xml;
int ret = 1;
if (argc != 2) {
printf("Usage: %s <path_to_dir_containing_float_modelDescription>\n", argv[0]);
return CTEST_RETURN_FAIL;
}

printf("Running fmi2_import_variable_types_test\n");

xml = parse_xml(argv[1]);
if (xml == NULL) {
return CTEST_RETURN_FAIL;
}

ret &= test_quantity_default(xml);

fmi2_import_free(xml);
return ret == 0 ? CTEST_RETURN_FAIL : CTEST_RETURN_SUCCESS;
}
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="3.0"
modelName="test_type_definitions"
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f9e0}"
description="N/A"
version="1.0"
generationDateAndTime="2011-09-23T16:57:33Z"
variableNamingConvention="structured">
<ModelExchange modelIdentifier="model_identifier"/>

<TypeDefinitions>

<!-- test that no specified quantity defaults to empty string -->
<SimpleType name="name_real">
<Real/>
</SimpleType>
<SimpleType name="name_integer">
<Integer/>
</SimpleType>
<SimpleType name="name_enum">
<Enumeration>
<Item name="EnumVar0" value="0"/>
</Enumeration>
</SimpleType>

<!-- test that no specified quantity defaults to null pointer -->
<SimpleType name="name_string">
<String/>
</SimpleType>
<SimpleType name="name_boolean">
<Boolean/>
</SimpleType>

</TypeDefinitions>

<ModelVariables>
</ModelVariables>

<ModelStructure>
</ModelStructure>

</fmiModelDescription>
@@ -55,10 +55,10 @@ FMILIB_EXPORT unsigned int fmi2_import_get_type_definition_number(fmi2_import_ty

/** \brief Get a type definition specified by the index
@param td the type definition list object
@param index the index of type definition. Must be less than the numbere returned by fmi2_import_get_type_definition_number()
@param index the index of type definition. Must be less than the number returned by fmi2_import_get_type_definition_number()
@return A type definition object or NULL if index is out of range.
*/
FMILIB_EXPORT fmi2_import_variable_typedef_t* fmi2_import_get_typedef(fmi2_import_type_definitions_t* td, unsigned int index);
FMILIB_EXPORT fmi2_import_variable_typedef_t* fmi2_import_get_typedef(fmi2_import_type_definitions_t* td, unsigned int index);

/** \brief Get associated display unit for a type defition if any. */
FMILIB_EXPORT fmi2_import_display_unit_t* fmi2_import_get_type_display_unit(fmi2_import_real_typedef_t*);
@@ -355,7 +355,7 @@ fmi1_xml_real_type_props_t* fmi1_xml_parse_real_type_properties(fmi1_xml_parser_
jm_named_ptr named, *pnamed;
fmi1_xml_model_description_t* md = context->modelDescription;
fmi1_xml_real_type_props_t* props;
const char* quantity = 0;
const char* quantity = "";
int boolBuf;

/* jm_vector(char)* bufName = fmi_get_parse_buffer(context,1);
@@ -435,7 +435,7 @@ fmi1_xml_integer_type_props_t * fmi1_xml_parse_integer_type_properties(fmi1_xml_

fmi1_xml_model_description_t* md = context->modelDescription;
fmi1_xml_integer_type_props_t * props = 0;
const char* quantity = 0;
const char* quantity = "";

/* jm_vector(char)* bufName = fmi_get_parse_buffer(context,1);
jm_vector(char)* bufDescr = fmi_get_parse_buffer(context,2); */
@@ -381,7 +381,7 @@ fmi2_xml_real_type_props_t* fmi2_xml_parse_real_type_properties(fmi2_xml_parser_
jm_named_ptr named, *pnamed;
fmi2_xml_model_description_t* md = context->modelDescription;
fmi2_xml_real_type_props_t* props;
const char* quantity = 0;
const char* quantity = "";
unsigned int relQuanBuf, unboundedBuf;

/* jm_vector(char)* bufName = fmi_get_parse_buffer(context,1);
@@ -463,7 +463,7 @@ fmi2_xml_integer_type_props_t * fmi2_xml_parse_integer_type_properties(fmi2_xml_

fmi2_xml_model_description_t* md = context->modelDescription;
fmi2_xml_integer_type_props_t * props = 0;
const char* quantity = 0;
const char* quantity = "";

/* jm_vector(char)* bufName = fmi_get_parse_buffer(context,1);
jm_vector(char)* bufDescr = fmi_get_parse_buffer(context,2); */

0 comments on commit 59f9d8c

Please sign in to comment.
You can’t perform that action at this time.