- fix: calltest was not initialized

- create parameter type sepcific checks
This commit is contained in:
2017-03-15 05:40:44 +00:00
parent 506bb44c58
commit a2c91798c5

View File

@@ -38,7 +38,7 @@ STATIC bool isDatatypeVoid(char *aType)
return true; return true;
} }
STATIC bool isDatatypeStandard(cfile_variable_t *aVariable) STATIC bool isDatatypeStandard(char *aDataType)
{ {
regex_t regXvariable; regex_t regXvariable;
@@ -48,7 +48,7 @@ STATIC bool isDatatypeStandard(cfile_variable_t *aVariable)
return false; return false;
} }
if (0 == regexec(&regXvariable, aVariable->dataType, 0, NULL, 0)) if (0 == regexec(&regXvariable, aDataType, 0, NULL, 0))
{ {
return true; 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, "\t");
fprintf(aFile, aVariableTemplate, aVariable->name); 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); 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) STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList)
{ {
cfile_variable_t *work = NULL; 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\tCU_FAIL_FATAL(\"init_%s() - "STUBINIT_PARAM_INSTANCE_S" out of bounce\");" NEWLINES, aFunction->name);
fprintf(aFile, "\t}" NEWLINES); fprintf(aFile, "\t}" NEWLINES);
fprintf(aFile, "\t"STUBINSTANCE_S1" = 0;" NEWLINES, aFunction->name); 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)) if (!isDatatypeVoid(aFunction->dataType))
{ {
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINIT_PARAM_INSTANCE_S"]."STUBPARAMETER_RETURN_S" = "STUBINIT_PARAM_RETURN_S";" NEWLINES, 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'; parameterIndex = 'a';
while (parameter) while (parameter)
{ {
if (NULL != strstr(parameter->type, "*")) createParameterSpecificCheck(aFile, aFunction, parameter, parameterIndex);
{
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);
++parameterIndex; ++parameterIndex;
parameter = parameter->next; parameter = parameter->next;
} }