diff --git a/src/stubser/stubser.c b/src/stubser/stubser.c index 1dc93be..785514d 100644 --- a/src/stubser/stubser.c +++ b/src/stubser/stubser.c @@ -38,7 +38,7 @@ STATIC bool isDatatypeVoid(char *aType) return true; } -STATIC bool isDatatypeStandard(cfile_variable_t *aVariable) +STATIC bool isDatatypeStandard(char *aDataType) { regex_t regXvariable; @@ -48,7 +48,7 @@ STATIC bool isDatatypeStandard(cfile_variable_t *aVariable) return false; } - if (0 == regexec(®Xvariable, aVariable->dataType, 0, NULL, 0)) + if (0 == regexec(®Xvariable, aDataType, 0, NULL, 0)) { return true; } @@ -79,7 +79,7 @@ STATIC void createVariableSpecificInit(const char* aVariableTemplate, FILE *aFil } } - else if (isDatatypeStandard(aVariable)) + else if (isDatatypeStandard(aVariable->dataType)) { fprintf(aFile, "\t"); fprintf(aFile, aVariableTemplate, aVariable->name); @@ -113,7 +113,7 @@ STATIC void createVariableSpecificCheck(FILE *aFile, cfile_variable_t *aVariable } } - else if (isDatatypeStandard(aVariable)) + else if (isDatatypeStandard(aVariable->dataType)) { fprintf(aFile, "\tCU_ASSERT_EQUAL(%s, "STUBVARIABLE_EXTENDED_S1");"NEWLINES, aVariable->name, aVariable->name); } @@ -124,6 +124,38 @@ STATIC void createVariableSpecificCheck(FILE *aFile, cfile_variable_t *aVariable } } +STATIC void createParameterSpecificCheck(FILE *aFile, cfunction_t *aFunction, cfunction_parameter_t *aParameter, char aParameterIndex) +{ + if (NULL != strstr(aParameter->type, "*") && NULL != strstr(aParameter->type, "char")) + { + fprintf(aFile, "\tCU_ASSERT_MEMORY_CHECK(\"%s(%s)\", ", aFunction->name, aParameter->name); + fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, + aFunction->name, aParameterIndex); + fprintf(aFile, ", strlen("STUBINIT_PARAM_PARAMETER_S1"));"NEWLINES, aParameterIndex); + } + else if (NULL != strstr(aParameter->type, "*")) + { + fprintf(aFile, "\tCU_ASSERT_PTR_EQUAL("); + fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, + aFunction->name, aParameterIndex); + fprintf(aFile, ");"NEWLINES); + } + else if (isDatatypeStandard(aParameter->type)) + { + fprintf(aFile, "\tCU_ASSERT_EQUAL("); + fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, + aFunction->name, aParameterIndex); + fprintf(aFile, ");"NEWLINES); + } + else + { + fprintf(aFile, "\tCU_ASSERT_MEMORY_CHECK(\"%s(%s)\", ", aFunction->name, aParameter->name); + fprintf(aFile, "&"STUBINIT_PARAM_PARAMETER_S1", &"STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1, aParameterIndex, aFunction->name, + aFunction->name, aParameterIndex); + fprintf(aFile, ", sizeof("STUBINIT_PARAM_PARAMETER_S1"));"NEWLINES, aParameterIndex); + } +} + STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList) { cfile_variable_t *work = NULL; @@ -341,6 +373,8 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a fprintf(aFile, "\t\tCU_FAIL_FATAL(\"init_%s() - "STUBINIT_PARAM_INSTANCE_S" out of bounce\");" NEWLINES, aFunction->name); fprintf(aFile, "\t}" NEWLINES); fprintf(aFile, "\t"STUBINSTANCE_S1" = 0;" NEWLINES, aFunction->name); + fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINIT_PARAM_INSTANCE_S"]."STUBPARAMETER_CALLTEST_S" = "STUBINIT_PARAM_CALLTEST_S";" NEWLINES, + aFunction->name); if (!isDatatypeVoid(aFunction->dataType)) { fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINIT_PARAM_INSTANCE_S"]."STUBPARAMETER_RETURN_S" = "STUBINIT_PARAM_RETURN_S";" NEWLINES, @@ -381,16 +415,7 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a parameterIndex = 'a'; while (parameter) { - if (NULL != strstr(parameter->type, "*")) - { - fprintf(aFile, "\tCU_ASSERT_PTR_EQUAL("); - } - else - { - fprintf(aFile, "\tCU_ASSERT_EQUAL("); - } - fprintf(aFile, STUBINIT_PARAM_PARAMETER_S1", "STUBPARAMETER_STRUCT_S1"["STUBINSTANCE_S1"]."STUBPARAMETER_PARAM_S1");" NEWLINES, parameterIndex, - aFunction->name, aFunction->name, parameterIndex); + createParameterSpecificCheck(aFile, aFunction, parameter, parameterIndex); ++parameterIndex; parameter = parameter->next; }