-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for models for C-libcurl generator (#5699)
* First try to generate unit tests for the models of the C-libcurl client. Models into models are not supported yet. * Added unit tests for the modules of the C-libcurl client to the git repository. * Support for objects having other objects as properties, for the C-libcurl client generator * Proper formatting of generated code
- Loading branch information
1 parent
166aae6
commit e9c1346
Showing
15 changed files
with
580 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 67 additions & 4 deletions
71
modules/openapi-generator/src/main/resources/C-libcurl/model_test.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,74 @@ | ||
{{#models}} | ||
{{#model}} | ||
#ifndef {{classFilename}}_TEST | ||
#define {{classFilename}}_TEST | ||
|
||
// the following is to include only the main from the first c file | ||
#ifndef TEST_MAIN | ||
#define TEST_MAIN | ||
#define {{classFilename}}_MAIN | ||
#endif // TEST_MAIN | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include "cJSON.h" | ||
{{#imports}}{{{import}}} | ||
{{/imports}} | ||
#include <stdbool.h> | ||
#include "../external/cJSON.h" | ||
|
||
#include "../model/{{classFilename}}.h" | ||
{{classname}}_t* instantiate_{{classname}}(int include_optional); | ||
|
||
{{#vars}}{{#isModel}}{{#isEnum}} | ||
// it is enum. Work in Progress | ||
{{/isEnum}}{{^isEnum}}#include "test_{{{dataType}}}.c" | ||
{{/isEnum}}{{/isModel}}{{/vars}} | ||
|
||
{{classname}}_t* instantiate_{{classname}}(int include_optional) { | ||
{{classname}}_t* {{classname}} = NULL; | ||
if (include_optional) { | ||
{{classname}} = {{classname}}_create( | ||
{{#vars}} {{#isEnum}}{{^isContainer}}{{#example}}{{projectName}}_{{classVarName}}_{{enumName}}_{{{.}}}{{/example}}{{/isContainer}}{{#isContainer}}{{#example}}{{{.}}}{{/example}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{#example}}{{{.}}}{{/example}}{{/isEnum}}{{^example}}{{#isModel}}{{#isEnum}}// enum {{datatypeWithEnum}}_e Work in Progress | ||
{{/isEnum}}{{^isEnum}} // false, not to have infinite recursion | ||
instantiate_{{{dataType}}}(0){{/isEnum}}{{/isModel}}{{^isModel}}0{{/isModel}}{{/example}}{{#hasMore}},{{/hasMore}} | ||
{{/vars}} | ||
); | ||
} else { | ||
{{classname}} = {{classname}}_create( | ||
{{#vars}} {{#isEnum}}{{^isContainer}}{{#example}}{{projectName}}_{{classVarName}}_{{enumName}}_{{{.}}}{{/example}}{{/isContainer}}{{#isContainer}}{{#example}}{{{.}}}{{/example}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{#example}}{{{.}}}{{/example}}{{/isEnum}}{{^example}}{{#isModel}}{{#isEnum}}// enum {{datatypeWithEnum}}_e Work in Progress | ||
{{/isEnum}}{{^isEnum}}NULL{{/isEnum}}{{/isModel}}{{^isModel}}0{{/isModel}}{{/example}}{{#hasMore}},{{/hasMore}} | ||
{{/vars}} | ||
); | ||
} | ||
|
||
return {{classname}}; | ||
} | ||
|
||
|
||
#ifdef {{classFilename}}_MAIN | ||
|
||
void test_{{classname}}(int include_optional) { | ||
{{classname}}_t* {{classname}}_1 = instantiate_{{classname}}(include_optional); | ||
|
||
cJSON* json{{classname}}_1 = {{classname}}_convertToJSON({{classname}}_1); | ||
printf("{{classname}} :\n%s\n", cJSON_Print(json{{classname}}_1)); | ||
{{classname}}_t* {{classname}}_2 = {{classname}}_parseFromJSON(json{{classname}}_1); | ||
cJSON* json{{classname}}_2 = {{classname}}_convertToJSON({{classname}}_2); | ||
printf("repeating {{classname}}:\n%s\n", cJSON_Print(json{{classname}}_2)); | ||
} | ||
|
||
int main() { | ||
printf("Hello world \n"); | ||
{{#models}} | ||
{{#model}} | ||
test_{{classname}}(1); | ||
test_{{classname}}(0); | ||
{{/model}} | ||
{{/models}} | ||
|
||
printf("Hello world \n"); | ||
return 0; | ||
} | ||
|
||
#endif // {{classFilename}}_MAIN | ||
#endif // {{classFilename}}_TEST | ||
{{/model}} | ||
{{/models}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef api_response_TEST | ||
#define api_response_TEST | ||
|
||
// the following is to include only the main from the first c file | ||
#ifndef TEST_MAIN | ||
#define TEST_MAIN | ||
#define api_response_MAIN | ||
#endif // TEST_MAIN | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include "../external/cJSON.h" | ||
|
||
#include "../model/api_response.h" | ||
api_response_t* instantiate_api_response(int include_optional); | ||
|
||
|
||
|
||
api_response_t* instantiate_api_response(int include_optional) { | ||
api_response_t* api_response = NULL; | ||
if (include_optional) { | ||
api_response = api_response_create( | ||
56, | ||
"0", | ||
"0" | ||
); | ||
} else { | ||
api_response = api_response_create( | ||
56, | ||
"0", | ||
"0" | ||
); | ||
} | ||
|
||
return api_response; | ||
} | ||
|
||
|
||
#ifdef api_response_MAIN | ||
|
||
void test_api_response(int include_optional) { | ||
api_response_t* api_response_1 = instantiate_api_response(include_optional); | ||
|
||
cJSON* jsonapi_response_1 = api_response_convertToJSON(api_response_1); | ||
printf("api_response :\n%s\n", cJSON_Print(jsonapi_response_1)); | ||
api_response_t* api_response_2 = api_response_parseFromJSON(jsonapi_response_1); | ||
cJSON* jsonapi_response_2 = api_response_convertToJSON(api_response_2); | ||
printf("repeating api_response:\n%s\n", cJSON_Print(jsonapi_response_2)); | ||
} | ||
|
||
int main() { | ||
test_api_response(1); | ||
test_api_response(0); | ||
|
||
printf("Hello world \n"); | ||
return 0; | ||
} | ||
|
||
#endif // api_response_MAIN | ||
#endif // api_response_TEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef category_TEST | ||
#define category_TEST | ||
|
||
// the following is to include only the main from the first c file | ||
#ifndef TEST_MAIN | ||
#define TEST_MAIN | ||
#define category_MAIN | ||
#endif // TEST_MAIN | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include "../external/cJSON.h" | ||
|
||
#include "../model/category.h" | ||
category_t* instantiate_category(int include_optional); | ||
|
||
|
||
|
||
category_t* instantiate_category(int include_optional) { | ||
category_t* category = NULL; | ||
if (include_optional) { | ||
category = category_create( | ||
56, | ||
"0" | ||
); | ||
} else { | ||
category = category_create( | ||
56, | ||
"0" | ||
); | ||
} | ||
|
||
return category; | ||
} | ||
|
||
|
||
#ifdef category_MAIN | ||
|
||
void test_category(int include_optional) { | ||
category_t* category_1 = instantiate_category(include_optional); | ||
|
||
cJSON* jsoncategory_1 = category_convertToJSON(category_1); | ||
printf("category :\n%s\n", cJSON_Print(jsoncategory_1)); | ||
category_t* category_2 = category_parseFromJSON(jsoncategory_1); | ||
cJSON* jsoncategory_2 = category_convertToJSON(category_2); | ||
printf("repeating category:\n%s\n", cJSON_Print(jsoncategory_2)); | ||
} | ||
|
||
int main() { | ||
test_category(1); | ||
test_category(0); | ||
|
||
printf("Hello world \n"); | ||
return 0; | ||
} | ||
|
||
#endif // category_MAIN | ||
#endif // category_TEST |
Oops, something went wrong.