diff --git a/src/stubser/stubser.c b/src/stubser/stubser.c index c443f40..774d4c1 100644 --- a/src/stubser/stubser.c +++ b/src/stubser/stubser.c @@ -420,7 +420,6 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a char parameterIndex = STUBDEFAULT_PARAMETER_INDEX_CHAR; char *dataTypeTemp = NULL; bool pointerAvailable = false; - bool variableParameterAvailable = false; 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) { pointerAvailable = true; - } - if (CPARAMETER_TYPE_VARIABLE == parameter->type) - { - variableParameterAvailable = true; + break; } 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); NEWLINE(aFile); -// TODO variable parameter structure - if (variableParameterAvailable) - { - ; - } - // parameter structure fprintf(aFile, "// Expected parameter and return value structures" NEWLINES); fprintf(aFile, "typedef struct _STUBPARAMETER_%s" NEWLINES, aFunction->name); @@ -892,7 +882,7 @@ int file_exist(const char *filename) return (stat(filename, &buffer) == 0); } -STATIC void createUserHeader(char *aOutput, char *aNoSuffix) +STATIC void createUserFiles(char *aOutput, char *aNoSuffix, bool aVaList) { FILE *fileDesc = 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, "#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, "void "STUBFUNCTION_USER_INITEXPECTED_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, "#include "NEWLINES); - fprintf(fileDesc, "#include \"xasserts.h\""NEWLINES); - fprintf(fileDesc, "#include \"xtypes.h\""NEWLINES); - fprintf(fileDesc, "#include \"stub.h\""NEWLINES); + fprintf(fileDesc, "#include "NEWLINES); 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_INITGLOBALS_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 *cHeaderName = NULL; cfunction_t *function = NULL; + bool vaListAvailable = false; if (NULL == aOutput || NULL == aCfile) { @@ -996,15 +991,18 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile) 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, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES); fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES); fprintf(cfile, "#include "NEWLINES); - fprintf(cfile, "#include \"xasserts.h\""NEWLINES); - fprintf(cfile, "#include \"xtypes.h\""NEWLINES); - fprintf(cfile, "#include \"stub.h\""NEWLINES); + fprintf(cfile, "#include "NEWLINES); + if(vaListAvailable) + { + fprintf(cfile, "#include // stub uses a va_list"NEWLINES); + } fprintf(cfile, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix); fprintf(cfile, "#include \"%s\""NEWLINES NEWLINES, gnu_basename(cHeaderName));