Michele Albano e9c1346386
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
2020-04-06 01:42:50 +08:00

73 lines
1.2 KiB
C

#ifndef user_TEST
#define user_TEST
// the following is to include only the main from the first c file
#ifndef TEST_MAIN
#define TEST_MAIN
#define user_MAIN
#endif // TEST_MAIN
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "../external/cJSON.h"
#include "../model/user.h"
user_t* instantiate_user(int include_optional);
user_t* instantiate_user(int include_optional) {
user_t* user = NULL;
if (include_optional) {
user = user_create(
56,
"0",
"0",
"0",
"0",
"0",
"0",
56
);
} else {
user = user_create(
56,
"0",
"0",
"0",
"0",
"0",
"0",
56
);
}
return user;
}
#ifdef user_MAIN
void test_user(int include_optional) {
user_t* user_1 = instantiate_user(include_optional);
cJSON* jsonuser_1 = user_convertToJSON(user_1);
printf("user :\n%s\n", cJSON_Print(jsonuser_1));
user_t* user_2 = user_parseFromJSON(jsonuser_1);
cJSON* jsonuser_2 = user_convertToJSON(user_2);
printf("repeating user:\n%s\n", cJSON_Print(jsonuser_2));
}
int main() {
test_user(1);
test_user(0);
printf("Hello world \n");
return 0;
}
#endif // user_MAIN
#endif // user_TEST