forked from loafle/openapi-generator-original
* New modified model header and body mustache for c client generator * remove uncrustify from cmake as it is used during code generation, also remove valgrind as it is not used * add function to encode and decode binary data * update model mustache * update api body and header mustache for handling all types of parameters * update model mustache with variable names and address few more issues to generate working codes * updated api body and header mustaches with support for various new parameters and fix some issues as per new changes in code flow structure * update apiClient header and body mustache as per new modifications for handling binary data and few more stuff * updated samples generated by new modified mustache * update handling of file and binary data type to binary_t * update samples with recent commit on master regarding c-generator * update cmakelist which was ignored by .openapi-generator-ignore, cleanup external folder * update CMakeList mustache to show how to use compiled libary to compile source files * update samples with new cmake * Add comments explaining what each command is doing inshort * remove freeing of base path as it is not memory allocated * update samples to free apiclient object when the requirement is over * add missing cJSON delete to fix memory not freed bugs * use uncrustify to beautify manual written test code
104 lines
2.6 KiB
C
104 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include "../api/StoreAPI.h"
|
|
|
|
|
|
#define ORDER_ID 1234
|
|
#define PET_ID 12345
|
|
#define QUANTITY 50
|
|
#define SHIP_DATE "2018-09-24T10:19:09.592Z"
|
|
#define STATUS placed
|
|
#define COMPLETE true
|
|
|
|
/*
|
|
Creates one pet and adds it. Then gets the pet with the just added ID and compare if the values are equal.
|
|
Could fail if someone else makes changes to the added pet, before it can be fetched again.
|
|
*/
|
|
int main() {
|
|
// place order test
|
|
apiClient_t *apiClient = apiClient_create();
|
|
|
|
char *shipdate = malloc(strlen(SHIP_DATE) + 1);
|
|
strcpy(shipdate, SHIP_DATE);
|
|
|
|
order_t *neworder = order_create(ORDER_ID,
|
|
PET_ID,
|
|
QUANTITY,
|
|
shipdate,
|
|
STATUS,
|
|
COMPLETE);
|
|
|
|
order_t *returnorder = StoreAPI_placeOrder(apiClient, neworder);
|
|
|
|
cJSON *JSONNODE = order_convertToJSON(returnorder);
|
|
|
|
char *dataToPrint = cJSON_Print(JSONNODE);
|
|
|
|
printf("Placed order: \n%s\n", dataToPrint);
|
|
order_free(neworder);
|
|
order_free(returnorder);
|
|
cJSON_Delete(JSONNODE);
|
|
free(dataToPrint);
|
|
apiClient_free(apiClient);
|
|
|
|
// order get by id test
|
|
apiClient_t *apiClient2 = apiClient_create();
|
|
|
|
neworder = StoreAPI_getOrderById(apiClient2, 1234);
|
|
|
|
JSONNODE = order_convertToJSON(neworder);
|
|
|
|
char *dataToPrint1 = cJSON_Print(JSONNODE);
|
|
|
|
printf("Order received: \n%s\n", dataToPrint1);
|
|
|
|
order_free(neworder);
|
|
cJSON_Delete(JSONNODE);
|
|
free(dataToPrint1);
|
|
apiClient_free(apiClient2);
|
|
|
|
// delete order test
|
|
apiClient_t *apiClient3 = apiClient_create();
|
|
|
|
char *orderid = malloc(strlen("1234") + 1);
|
|
strcpy(orderid, "1234");
|
|
|
|
StoreAPI_deleteOrder(apiClient3, orderid);
|
|
|
|
printf("Order Deleted \n");
|
|
free(orderid);
|
|
apiClient_free(apiClient3);
|
|
|
|
|
|
// get order by id test
|
|
apiClient_t *apiClient4 = apiClient_create();
|
|
|
|
neworder = StoreAPI_getOrderById(apiClient4, 1234);
|
|
|
|
if(neworder == NULL) {
|
|
printf("Order Not present \n");
|
|
}
|
|
order_free(neworder);
|
|
apiClient_free(apiClient4);
|
|
|
|
// get inventory test
|
|
apiClient_t *apiClient5 = apiClient_create();
|
|
list_t *elementToReturn;
|
|
elementToReturn = StoreAPI_getInventory(apiClient5);
|
|
listEntry_t *listEntry;
|
|
list_ForEach(listEntry, elementToReturn) {
|
|
keyValuePair_t *pair = (keyValuePair_t *) listEntry->data;
|
|
printf("%s - %s\n", pair->key, (char *) pair->value);
|
|
}
|
|
list_ForEach(listEntry, elementToReturn) {
|
|
keyValuePair_t *pair = (keyValuePair_t *) listEntry->data;
|
|
free(pair->key);
|
|
free(pair->value);
|
|
keyValuePair_free(pair);
|
|
}
|
|
list_free(elementToReturn);
|
|
apiClient_free(apiClient5);
|
|
}
|