From adf425bb1aad837dda9a1d889dcd7a1b1f6aee93 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Fri, 10 Mar 2017 22:48:29 +0000 Subject: [PATCH] - added creating function to work with stub global variables (init expected, init globals, check globals) --- src/stubser/stubser.c | 105 ++++++++++++++++++++++++++++++++++++++ src/stubser/stubser_loc.h | 5 ++ 2 files changed, 110 insertions(+) diff --git a/src/stubser/stubser.c b/src/stubser/stubser.c index 168f844..5ce87e6 100644 --- a/src/stubser/stubser.c +++ b/src/stubser/stubser.c @@ -38,6 +38,107 @@ STATIC bool isDatatypeVoid(char *aType) return true; } +STATIC int8_t createStubExpected(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList) +{ + cfile_variable_t *work = NULL; + if (NULL == aFile || NULL == aHeader || NULL == aList) + { + return -1; + } + + work = aList->head; + while (work) + { + if (CVARIABLE_TYPE_REGULAR != work->type) + { + work = work->next; + continue; + } + fprintf(aFile, "%s "STUBVARIABLE_EXTENDED_S1";"NEWLINES, work->dataType, work->name); + fprintf(aHeader, "extern %s "STUBVARIABLE_EXTENDED_S1";"NEWLINES, work->dataType, work->name); + work = work->next; + } + + fprintf(aHeader, "void "STUBFUNCTION_INITEXPECTED_S1"();"NEWLINES NEWLINES, aNoSuffix); + fprintf(aFile, NEWLINES"void "STUBFUNCTION_INITEXPECTED_S1"()"NEWLINES"{"NEWLINES, aNoSuffix); + + work = aList->head; + while (work) + { + if (CVARIABLE_TYPE_REGULAR != work->type) + { + work = work->next; + continue; + } + // TODO type specific initialization + fprintf(aFile, "\t"STUBVARIABLE_EXTENDED_S1" = 0x55;"NEWLINES, work->name); + work = work->next; + } + + fprintf(aFile, "}"NEWLINES); + + return 0; +} + +STATIC int8_t createStubGlobals(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList) +{ + cfile_variable_t *work = NULL; + if (NULL == aFile || NULL == aHeader || NULL == aList) + { + return -1; + } + + fprintf(aFile, NEWLINES"void "STUBFUNCTION_INITGLOBALS_S1"()"NEWLINES"{"NEWLINES, aNoSuffix); + + work = aList->head; + while (work) + { + if (CVARIABLE_TYPE_REGULAR != work->type) + { + work = work->next; + continue; + } + // TODO type specific initialization + fprintf(aFile, "\t%s = 0x55;"NEWLINES, work->name); + fprintf(aHeader, "extern %s %s;"NEWLINES, work->dataType, work->name); + work = work->next; + } + + fprintf(aFile, "}"NEWLINES); + fprintf(aHeader, "void "STUBFUNCTION_INITGLOBALS_S1"();"NEWLINES NEWLINES, aNoSuffix); + + return 0; +} + +STATIC int8_t createStubCheck(char *aNoSuffix, FILE *aFile, FILE *aHeader, cfile_variableList_t *aList) +{ + cfile_variable_t *work = NULL; + if (NULL == aFile || NULL == aHeader || NULL == aList) + { + return -1; + } + + fprintf(aHeader, "void "STUBFUNCTION_CHECK_S1"();"NEWLINES NEWLINES, aNoSuffix); + fprintf(aFile, NEWLINES"void "STUBFUNCTION_CHECK_S1"()"NEWLINES"{"NEWLINES, aNoSuffix); + + work = aList->head; + while (work) + { + if (CVARIABLE_TYPE_REGULAR != work->type) + { + work = work->next; + continue; + } + // TODO type specific initialization + fprintf(aFile, "\tCU_ASSERT_EQUAL(%s, "STUBVARIABLE_EXTENDED_S1");"NEWLINES, work->name, work->name); + work = work->next; + } + + fprintf(aFile, "}"NEWLINES NEWLINES); + + return 0; +} + STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *aFunction) { cfunction_parameter_t *parameter = NULL; @@ -297,6 +398,10 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile) fprintf(cheader, "#ifndef _STUB_%s_H"NEWLINES, aNoSuffix); fprintf(cheader, "#define _STUB_%s_H"NEWLINES NEWLINES, aNoSuffix); + createStubExpected(aNoSuffix, cfile, cheader, &aCfile->variables); + createStubGlobals(aNoSuffix, cfile, cheader, &aCfile->variables); + createStubCheck(aNoSuffix, cfile, cheader, &aCfile->variables); + function = aCfile->functions.head; while (function) { diff --git a/src/stubser/stubser_loc.h b/src/stubser/stubser_loc.h index 78a77e4..63dc3b1 100644 --- a/src/stubser/stubser_loc.h +++ b/src/stubser/stubser_loc.h @@ -38,6 +38,11 @@ #define STUBINIT_PARAM_PARAMETER_S1 "aParameter_%c" // aParameter_a #define STUBINIT_PARAM_RETURN_S "aReturnValue" +#define STUBFUNCTION_INITEXPECTED_S1 "stub_%s_initExpected" // stub_testfunction_checkGlobals +#define STUBFUNCTION_INITGLOBALS_S1 "stub_%s_initGlobals" // stub_testfunction_checkGlobals +#define STUBFUNCTION_CHECK_S1 "stub_%s_checkGlobals" // stub_testfunction_checkGlobals +#define STUBVARIABLE_EXTENDED_S1 "%s_expected" // variable_expected + #define STUB_CONSOLE_OK "[ OK ]" #define STUB_CONSOLE_FAIL "[FAIL]" #define STUB_CONSOLE_PARSE_ERROR_S2 STUB_CONSOLE_FAIL " %s parsing failed (%d)\n"