Ernesto Fernández 037cb12f34
Tests for recent C fixes (#20200)
* [C] Add test schemas for the recent changes

The recent commit 47665aaa97cb ("Fix a few issues with the C generator
(part 1 version 2) (#14434)") didn't include any test schemas. Add them
now, as requested:

  https://github.com/OpenAPITools/openapi-generator/pull/14434#issuecomment-2497497110

* Update samples

* Fix sample update with missing files

* More fixes for sample updates
2024-11-28 16:27:42 +08:00

57 lines
1.3 KiB
C

#ifndef preference_TEST
#define preference_TEST
// the following is to include only the main from the first c file
#ifndef TEST_MAIN
#define TEST_MAIN
#define preference_MAIN
#endif // TEST_MAIN
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "../external/cJSON.h"
#include "../model/preference.h"
preference_t* instantiate_preference(int include_optional);
preference_t* instantiate_preference(int include_optional) {
preference_t* preference = NULL;
if (include_optional) {
preference = preference_create(
);
} else {
preference = preference_create(
);
}
return preference;
}
#ifdef preference_MAIN
void test_preference(int include_optional) {
preference_t* preference_1 = instantiate_preference(include_optional);
cJSON* jsonpreference_1 = preference_convertToJSON(preference_1);
printf("preference :\n%s\n", cJSON_Print(jsonpreference_1));
preference_t* preference_2 = preference_parseFromJSON(jsonpreference_1);
cJSON* jsonpreference_2 = preference_convertToJSON(preference_2);
printf("repeating preference:\n%s\n", cJSON_Print(jsonpreference_2));
}
int main() {
test_preference(1);
test_preference(0);
printf("Hello world \n");
return 0;
}
#endif // preference_MAIN
#endif // preference_TEST