Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
18261c7
Added a .gitignore to ignore the build folder
Jun 7, 2018
d612b5e
Added a CMakeLists and a basic implementation of a double linked list
Jun 7, 2018
20fb735
Added the pet model
Jun 7, 2018
779e39f
changed the behaviour when a list gets freed - the data of each eleme…
PowerOfCreation Jun 7, 2018
f85e1d4
Added the tool uncrustify in order to make code look better
PowerOfCreation Jun 7, 2018
354e18f
Uncrustified code
PowerOfCreation Jun 7, 2018
71fc991
added an implementation(constructor and deconstructor) for the catego…
PowerOfCreation Jun 8, 2018
af82b47
Added a third party JSON library
PowerOfCreation Jun 8, 2018
a4ae6e3
The pet struct now uses pointers for its members; the pet struct now …
PowerOfCreation Jun 8, 2018
fcf467b
The pet model now gets fully serialized into JSON
PowerOfCreation Jun 11, 2018
788fa30
Fixed the example url...
PowerOfCreation Jun 11, 2018
4113aef
Added third party library libcurl
PowerOfCreation Jun 12, 2018
9ea8297
Modified category struct and added an unit test
PowerOfCreation Jun 12, 2018
1c3f9ed
Added a foreach macro and added two functions
PowerOfCreation Jun 12, 2018
42d239b
Added a tag model and an unit test
PowerOfCreation Jun 12, 2018
5e6d18e
the pet struct now uses no double pointer for it's name anymore and n…
PowerOfCreation Jun 12, 2018
ab5a695
Added the struct APIClient and an unit test
PowerOfCreation Jun 12, 2018
79f48c6
Uncrustified the unit test for category
PowerOfCreation Jun 12, 2018
a05166a
Added ifdef in pet.h to prevent errors
PowerOfCreation Jun 12, 2018
3e97209
Added one API endpoint to get a pet by id
PowerOfCreation Jun 12, 2018
01e1553
Added a "== 0" comparison that I forgot
PowerOfCreation Jun 12, 2018
a7ac435
Added some kind of debug functionality to test-petApi.c
PowerOfCreation Jun 12, 2018
4a45f84
Removed the DEBUG define
PowerOfCreation Jun 12, 2018
a662cfa
Moved the c petstore example from samples/client/c to samples/client/…
PowerOfCreation Jun 13, 2018
880968c
Renamed function getPetById to petApi_getPetById to avoid name collis…
PowerOfCreation Jun 13, 2018
38caebb
Removed unecessary method in list.c
PowerOfCreation Jun 14, 2018
4ac1a05
Added POST functionality; added petApi_addPet method and improved uni…
PowerOfCreation Jun 14, 2018
2801d75
removed two methods in list.c(string/tag to JSON) and moved their cod…
PowerOfCreation Jun 14, 2018
f5301cd
Removed old, already commented out, puts artifact in apiClient.c
PowerOfCreation Jun 14, 2018
fcfe8f5
Added a convertToJSON method to the category model
PowerOfCreation Jun 15, 2018
070599e
Added a convertToJSON method to the tag model
PowerOfCreation Jun 15, 2018
ef5d749
changed how the convertToJSON method works in the pet model
PowerOfCreation Jun 15, 2018
1be4f9f
Adjusted the unit-tests on how the convertToJSON method now works(now…
PowerOfCreation Jun 15, 2018
3c0f740
apiClient_t now needs to be given to API methods as a parameter. This…
PowerOfCreation Jun 26, 2018
658aa4b
Added an untested concept for how authentication could be handled
PowerOfCreation Jun 26, 2018
68e8487
Tested basicAuth using wireshark and added untested OAuth2 feature
PowerOfCreation Jul 3, 2018
cf1333b
Added support for api key authentication using the http-header and te…
PowerOfCreation Jul 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/client/petstore/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
69 changes: 69 additions & 0 deletions samples/client/petstore/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required (VERSION 2.6)
project (CGenerator)

file(GLOB SRC_C src/*.c)
file(GLOB UNIT_TESTS_C unit-tests/*.c)
file(GLOB MODEL_C model/*.c)
file(GLOB API_C api/*.c)
file(GLOB EXTERNAL_SRC_C external/src/*.c)
set(ALL_SRC_LIST ${SRC_C} ${UNIT_TESTS_C} ${MODEL_C} ${API_C})

include(CTest)
include_directories(include)
include_directories(external/include)

find_program(VALGRIND valgrind)
if(VALGRIND)
set(CMAKE_MEMORYCHECK_COMMAND valgrind)
set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --track-origins=yes --read-var-info=yes --show-leak-kinds=all --error-exitcode=1")
set(VALGRIND_LIST "")
endif()

find_package(CURL REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
else(CURL_FOUND)
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif()

foreach(ELEMENT ${UNIT_TESTS_C})
get_filename_component(ELEMENT_NAME ${ELEMENT} NAME_WE)
string(REGEX REPLACE "\\.c$" "" ELEMENT_REPLACED ${ELEMENT_NAME})
set(EXE_NAME unit-${ELEMENT_REPLACED})
add_executable(${EXE_NAME} ${ELEMENT} ${SRC_C} ${MODEL_C} ${API_C} ${EXTERNAL_SRC_C})
target_link_libraries(${EXE_NAME} ${CURL_LIBRARIES})
add_test(NAME ${EXE_NAME} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME})

if(VALGRIND)
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
separate_arguments(memcheck_command)

add_test(
NAME valgrind-test-${ELEMENT_REPLACED}
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endforeach()

#For common coding standard (code beautifier/pretty printing)
find_program(UNCRUSTIFY uncrustify)
if(UNCRUSTIFY)
add_custom_target(
uncrustify
)

foreach(ELEMENT ${ALL_SRC_LIST})
string(REGEX REPLACE "/" "_" ELEMENT_NAME ${ELEMENT})
set(DEP_NAME "uncrustify-${ELEMENT_NAME}")
add_custom_target(
${DEP_NAME}
uncrustify -c uncrustify-rules.cfg --no-backup ${ELEMENT}
DEPENDS ${ELEMENT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM
)
add_dependencies(uncrustify ${DEP_NAME})
endforeach()
endif()
47 changes: 47 additions & 0 deletions samples/client/petstore/c/api/petAPI.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdlib.h>
#include <stdio.h>
#include "apiClient.h"
#include "cJSON.h"
#include "pet.h"

#define MAX_BUFFER_LENGTH 9

pet_t *petApi_getPetById(apiClient_t *apiClient, long petId) {
pet_t *pet;
char *petIdString = malloc(MAX_BUFFER_LENGTH);

snprintf(petIdString, MAX_BUFFER_LENGTH, "%li", petId);

apiClient_invoke(apiClient,
"pet",
petIdString,
NULL);
pet = pet_parseFromJSON(apiClient->dataReceived);
free(apiClient->dataReceived);
if(pet == NULL) {
return 0;
} else {
cJSON *jsonObject = pet_convertToJSON(pet);
cJSON_Delete(jsonObject);
}
free(petIdString);

return pet;
}

void *petApi_addPet(apiClient_t *apiClient, pet_t *pet) {
cJSON *petJSONObject;
char *petJSONString;

petJSONObject = pet_convertToJSON(pet);
petJSONString = cJSON_Print(petJSONObject);
apiClient_invoke(apiClient,
"pet",
NULL,
petJSONString);
free(apiClient->dataReceived);
free(petJSONString);
cJSON_Delete(petJSONObject);

return pet;
}
19 changes: 19 additions & 0 deletions samples/client/petstore/c/external/cJSON.licence
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading