Rearange header for separation between stubs, test and test subject

This commit is contained in:
2021-12-22 08:59:46 +01:00
parent f234d7613e
commit 8926a7dc75

View File

@@ -420,7 +420,6 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
char parameterIndex = STUBDEFAULT_PARAMETER_INDEX_CHAR; char parameterIndex = STUBDEFAULT_PARAMETER_INDEX_CHAR;
char *dataTypeTemp = NULL; char *dataTypeTemp = NULL;
bool pointerAvailable = false; bool pointerAvailable = false;
bool variableParameterAvailable = false;
if (NULL == aFile || NULL == aHeader || NULL == aFunction) if (NULL == aFile || NULL == aHeader || NULL == aFunction)
{ {
@@ -438,10 +437,7 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
if (NULL != strstr(NCHECK(parameter->dataType), "*") || parameter->array) if (NULL != strstr(NCHECK(parameter->dataType), "*") || parameter->array)
{ {
pointerAvailable = true; pointerAvailable = true;
} break;
if (CPARAMETER_TYPE_VARIABLE == parameter->type)
{
variableParameterAvailable = true;
} }
parameter = parameter->next; parameter = parameter->next;
} }
@@ -454,12 +450,6 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
fprintf(aFile, "#define "STUBINSTANCE_AMOUNT_S1" %d" NEWLINES, aFunction->name, STUB_INSTANCES_AMOUNT); fprintf(aFile, "#define "STUBINSTANCE_AMOUNT_S1" %d" NEWLINES, aFunction->name, STUB_INSTANCES_AMOUNT);
NEWLINE(aFile); NEWLINE(aFile);
// TODO variable parameter structure
if (variableParameterAvailable)
{
;
}
// parameter structure // parameter structure
fprintf(aFile, "// Expected parameter and return value structures" NEWLINES); fprintf(aFile, "// Expected parameter and return value structures" NEWLINES);
fprintf(aFile, "typedef struct _STUBPARAMETER_%s" NEWLINES, aFunction->name); fprintf(aFile, "typedef struct _STUBPARAMETER_%s" NEWLINES, aFunction->name);
@@ -892,7 +882,7 @@ int file_exist(const char *filename)
return (stat(filename, &buffer) == 0); return (stat(filename, &buffer) == 0);
} }
STATIC void createUserHeader(char *aOutput, char *aNoSuffix) STATIC void createUserFiles(char *aOutput, char *aNoSuffix, bool aVaList)
{ {
FILE *fileDesc = NULL; FILE *fileDesc = NULL;
char *cHeaderName = NULL; char *cHeaderName = NULL;
@@ -917,6 +907,12 @@ STATIC void createUserHeader(char *aOutput, char *aNoSuffix)
fprintf(fileDesc, "#ifndef _STUB_%s_USER_H"NEWLINES, aNoSuffix); fprintf(fileDesc, "#ifndef _STUB_%s_USER_H"NEWLINES, aNoSuffix);
fprintf(fileDesc, "#define _STUB_%s_USER_H"NEWLINES, aNoSuffix); fprintf(fileDesc, "#define _STUB_%s_USER_H"NEWLINES, aNoSuffix);
fprintf(fileDesc, NEWLINES"// mandatory header needed by stub"NEWLINES);
fprintf(fileDesc, "#include \"stub.h\""NEWLINES);
fprintf(fileDesc, "#include \"xasserts.h\""NEWLINES);
fprintf(fileDesc, NEWLINES"// TODO place user definitions, headers, typedefs,... here"NEWLINES);
fprintf(fileDesc, NEWLINES"// predefined stub user functions"NEWLINES); fprintf(fileDesc, NEWLINES"// predefined stub user functions"NEWLINES);
fprintf(fileDesc, "void "STUBFUNCTION_USER_INITEXPECTED_S1"();"NEWLINES, aNoSuffix); fprintf(fileDesc, "void "STUBFUNCTION_USER_INITEXPECTED_S1"();"NEWLINES, aNoSuffix);
fprintf(fileDesc, "void "STUBFUNCTION_USER_INITGLOBALS_S1"();"NEWLINES, aNoSuffix); fprintf(fileDesc, "void "STUBFUNCTION_USER_INITGLOBALS_S1"();"NEWLINES, aNoSuffix);
@@ -943,12 +939,10 @@ STATIC void createUserHeader(char *aOutput, char *aNoSuffix)
fprintf(fileDesc, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES); fprintf(fileDesc, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
fprintf(fileDesc, "#include <CUnit/CUnit.h>"NEWLINES); fprintf(fileDesc, "#include <CUnit/CUnit.h>"NEWLINES);
fprintf(fileDesc, "#include \"xasserts.h\""NEWLINES); fprintf(fileDesc, "#include <stdint.h>"NEWLINES);
fprintf(fileDesc, "#include \"xtypes.h\""NEWLINES);
fprintf(fileDesc, "#include \"stub.h\""NEWLINES);
fprintf(fileDesc, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix); fprintf(fileDesc, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix);
fprintf(fileDesc, "// predefined stub user functions"NEWLINES); fprintf(fileDesc, NEWLINES"// predefined stub user functions"NEWLINES);
fprintf(fileDesc, "void "STUBFUNCTION_USER_INITEXPECTED_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix); fprintf(fileDesc, "void "STUBFUNCTION_USER_INITEXPECTED_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix);
fprintf(fileDesc, "void "STUBFUNCTION_USER_INITGLOBALS_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix); fprintf(fileDesc, "void "STUBFUNCTION_USER_INITGLOBALS_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix);
fprintf(fileDesc, "void "STUBFUNCTION_USER_CHECK_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix); fprintf(fileDesc, "void "STUBFUNCTION_USER_CHECK_S1"()"NEWLINES"{"NEWLINES"\t"NEWLINES"}"NEWLINES NEWLINES, aNoSuffix);
@@ -966,6 +960,7 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
char *cFileName = NULL; char *cFileName = NULL;
char *cHeaderName = NULL; char *cHeaderName = NULL;
cfunction_t *function = NULL; cfunction_t *function = NULL;
bool vaListAvailable = false;
if (NULL == aOutput || NULL == aCfile) if (NULL == aOutput || NULL == aCfile)
{ {
@@ -996,15 +991,18 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
return -1; return -1;
} }
createUserHeader(aOutput, aNoSuffix); vaListAvailable = (0 == cfile_hasVaList(aCfile) ? true : false);
createUserFiles(aOutput, aNoSuffix, vaListAvailable);
fprintf(cfile, "/*! @file %s"NEWLINES, gnu_basename(cFileName)); fprintf(cfile, "/*! @file %s"NEWLINES, gnu_basename(cFileName));
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES); fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES); fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES); fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES);
fprintf(cfile, "#include \"xasserts.h\""NEWLINES); fprintf(cfile, "#include <stdint.h>"NEWLINES);
fprintf(cfile, "#include \"xtypes.h\""NEWLINES); if(vaListAvailable)
fprintf(cfile, "#include \"stub.h\""NEWLINES); {
fprintf(cfile, "#include <stdarg.h> // stub uses a va_list"NEWLINES);
}
fprintf(cfile, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix); fprintf(cfile, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix);
fprintf(cfile, "#include \"%s\""NEWLINES NEWLINES, gnu_basename(cHeaderName)); fprintf(cfile, "#include \"%s\""NEWLINES NEWLINES, gnu_basename(cHeaderName));