Skip to content

Commit

Permalink
Add JSON Unit Tests
Browse files Browse the repository at this point in the history
This PR adds unit tests from PR #1139 of C SDK Development Branch.
  • Loading branch information
yourslab authored Aug 29, 2020
2 parents 03bcaea + 30934ad commit 3d44e11
Show file tree
Hide file tree
Showing 7 changed files with 1,728 additions and 86 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Include filepaths for source and include.
include(jsonFilePaths.cmake)

# JSON library target.
add_library( json
${JSON_SOURCES} )

# JSON public include path.
target_include_directories( json PUBLIC ${JSON_INCLUDE_PUBLIC_DIRS}
${LOGGING_INCLUDE_DIRS} )

# Organization of JSON in IDE projects.
set_target_properties( json PROPERTIES FOLDER libraries/standard )
source_group( include FILES include/json.h )
source_group( src FILES ${JSON_SOURCES} )

if(BUILD_TESTS)
add_subdirectory(utest)
endif()
8 changes: 7 additions & 1 deletion include/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ typedef enum
JSONSuccess,
JSONIllegalDocument,
JSONMaxDepthExceeded,
JSONNotFound
JSONNotFound,
JSONNullParameter,
JSONBadParameter
} JSONStatus_t;

/**
Expand All @@ -40,6 +42,8 @@ typedef enum
* @param[in] max The size of the buffer.
*
* @return #JSONSuccess if the buffer contents are valid JSON;
* #JSONNullParameter if buf is NULL;
* #JSONBadParameter if max is 0;
* #JSONIllegalDocument if the buffer contents are NOT valid JSON;
* #JSONMaxDepthExceeded if object and array nesting exceeds a threshold;
* #JSONPartial if the buffer contents are potentially valid but incomplete.
Expand Down Expand Up @@ -91,6 +95,8 @@ JSONStatus_t JSON_Validate( const char * buf,
* }
*
* @return #JSONSuccess if the queryKey is found and the value output;
* #JSONNullParameter if any pointer parameters are NULL;
* #JSONBadParameter if the queryKey is empty, or any subpart is empty, or max is 0;
* #JSONIllegalDocument if the buffer contents are NOT valid JSON;
* #JSONMaxDepthExceeded if object and array nesting exceeds a threshold;
* #JSONNotFound if the queryKey is NOT found.
Expand Down
14 changes: 14 additions & 0 deletions jsonFilePaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is to add source files and include directories
# into variables so that it can be reused from different repositories
# in their Cmake based build system by including this file.
#
# Files specific to the repository such as test runner, platform tests
# are not added to the variables.

# JSON library source files.
set( JSON_SOURCES
${MODULES_DIR}/standard/json/src/json.c )

# JSON library Public Include directories.
set( JSON_INCLUDE_PUBLIC_DIRS
${MODULES_DIR}/standard/json/include )
15 changes: 15 additions & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
abc
ascii
bf
bmp
buf
buflength
com
Expand All @@ -10,6 +11,7 @@ df
dfff
ef
endif
enums
fb
fc
fd
Expand All @@ -19,14 +21,19 @@ foo
ifndef
inc
json
jsonbadparameter
jsonillegaldocument
jsonmaxdepthexceeded
jsonnotfound
jsonnullparameter
jsonpartial
jsonsuccess
keylength
len
misra
msb
multibyte
nextkeyvaluepair
noninfringement
nul
outvalue
Expand All @@ -37,6 +44,14 @@ querykey
querykeylength
requirelowsurrogate
sizeof
skiparrayscalars
skipdecimals
skipdigits
skipescape
skipexponent
skiphexescape
skipobjectscalars
skipstring
src
sublicense
unescaped
Expand Down
Loading

0 comments on commit 3d44e11

Please sign in to comment.