forked from bblanchon/ArduinoJson
ArduinoJson is now a header-only library (issue #199)
This commit is contained in:
@ -5,31 +5,69 @@
|
||||
# https://github.com/bblanchon/ArduinoJson
|
||||
# If you like this project, please add a star!
|
||||
|
||||
set(GTEST_DIR ../third-party/gtest-1.7.0)
|
||||
include(gtest.cmake)
|
||||
|
||||
file(GLOB TESTS_FILES *.hpp *.cpp)
|
||||
|
||||
include_directories(
|
||||
${GTEST_DIR}
|
||||
${GTEST_DIR}/include)
|
||||
|
||||
add_definitions(-DGTEST_HAS_PTHREAD=0)
|
||||
|
||||
# Workaround for Visual Studio 2012
|
||||
if (MSVC AND MSVC_VERSION EQUAL 1700)
|
||||
add_definitions(-D_VARIADIC_MAX=10)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(
|
||||
-fno-exceptions
|
||||
-fno-rtti
|
||||
-pedantic
|
||||
-Wall
|
||||
-Wcast-align
|
||||
-Wcast-qual
|
||||
-Wconversion
|
||||
-Wctor-dtor-privacy
|
||||
-Wdisabled-optimization
|
||||
-Werror
|
||||
-Wextra
|
||||
-Wformat=2
|
||||
-Winit-self
|
||||
-Wmissing-include-dirs
|
||||
-Wno-parentheses
|
||||
-Wno-sign-conversion
|
||||
-Wno-unused
|
||||
-Wno-variadic-macros
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Woverloaded-virtual
|
||||
-Wredundant-decls
|
||||
-Wshadow
|
||||
-Wsign-promo
|
||||
-Wstrict-overflow=5
|
||||
-Wundef
|
||||
)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
add_compile_options(
|
||||
-Wstrict-null-sentinel
|
||||
)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
|
||||
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
|
||||
add_compile_options(-Wnoexcept)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(
|
||||
-Wc++11-compat
|
||||
-Wdeprecated-register
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_options(-W4)
|
||||
endif()
|
||||
|
||||
add_executable(ArduinoJsonTests
|
||||
${TESTS_FILES}
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
${GTEST_DIR}/src/gtest_main.cc)
|
||||
|
||||
|
||||
target_link_libraries(ArduinoJsonTests ArduinoJson)
|
||||
add_executable(ArduinoJsonTests ${TESTS_FILES})
|
||||
target_include_directories(ArduinoJsonTests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../include)
|
||||
target_link_libraries(ArduinoJsonTests gtest)
|
||||
|
||||
add_test(ArduinoJsonTests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ArduinoJsonTests)
|
||||
|
@ -6,11 +6,7 @@
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define protected public
|
||||
#include <ArduinoJson/DynamicJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class DynamicJsonBuffer_Basic_Tests : public testing::Test {
|
||||
protected:
|
||||
|
@ -44,7 +44,7 @@ TEST(JsonArray_CopyTo_Tests, TwoOneDimensionIntegerArray) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonArray& array = jsonBuffer.parseArray(json);
|
||||
|
||||
int destination[3][2] = {0};
|
||||
int destination[3][2] = {{0}};
|
||||
array.copyTo(destination);
|
||||
|
||||
ASSERT_EQ(1, destination[0][0]);
|
||||
|
@ -6,9 +6,7 @@
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/JsonVariant.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class JsonVariant_Comparison_Tests : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -6,11 +6,7 @@
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define protected public
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class StaticJsonBuffer_Basic_Tests : public testing::Test {
|
||||
protected:
|
||||
|
@ -10,9 +10,13 @@
|
||||
|
||||
class StaticJsonBuffer_ParseArray_Tests : public testing::Test {
|
||||
protected:
|
||||
void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; }
|
||||
void with(JsonBuffer& jsonBuffer) {
|
||||
_jsonBuffer = &jsonBuffer;
|
||||
}
|
||||
|
||||
void whenInputIs(const char* json) { strcpy(_jsonString, json); }
|
||||
void whenInputIs(const char* json) {
|
||||
strcpy(_jsonString, json);
|
||||
}
|
||||
|
||||
void parseMustSucceed() {
|
||||
EXPECT_TRUE(_jsonBuffer->parseArray(_jsonString).success());
|
||||
@ -73,9 +77,12 @@ TEST_F(StaticJsonBuffer_ParseArray_Tests,
|
||||
}
|
||||
|
||||
TEST_F(StaticJsonBuffer_ParseArray_Tests, CharPtrNull) {
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>().parseArray((char*)0).success());
|
||||
ASSERT_FALSE(
|
||||
StaticJsonBuffer<100>().parseArray(static_cast<char*>(0)).success());
|
||||
}
|
||||
|
||||
TEST_F(StaticJsonBuffer_ParseArray_Tests, ConstCharPtrNull) {
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>().parseArray((const char*)0).success());
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>()
|
||||
.parseArray(static_cast<const char*>(0))
|
||||
.success());
|
||||
}
|
||||
|
@ -10,9 +10,13 @@
|
||||
|
||||
class StaticJsonBuffer_ParseObject_Tests : public testing::Test {
|
||||
protected:
|
||||
void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; }
|
||||
void with(JsonBuffer& jsonBuffer) {
|
||||
_jsonBuffer = &jsonBuffer;
|
||||
}
|
||||
|
||||
void whenInputIs(const char* json) { strcpy(_jsonString, json); }
|
||||
void whenInputIs(const char* json) {
|
||||
strcpy(_jsonString, json);
|
||||
}
|
||||
|
||||
void parseMustSucceed() {
|
||||
EXPECT_TRUE(_jsonBuffer->parseObject(_jsonString).success());
|
||||
@ -74,9 +78,12 @@ TEST_F(StaticJsonBuffer_ParseObject_Tests,
|
||||
}
|
||||
|
||||
TEST_F(StaticJsonBuffer_ParseObject_Tests, CharPtrNull) {
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>().parseObject((char*)0).success());
|
||||
ASSERT_FALSE(
|
||||
StaticJsonBuffer<100>().parseObject(static_cast<char*>(0)).success());
|
||||
}
|
||||
|
||||
TEST_F(StaticJsonBuffer_ParseObject_Tests, ConstCharPtrNull) {
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>().parseObject((const char*)0).success());
|
||||
ASSERT_FALSE(StaticJsonBuffer<100>()
|
||||
.parseObject(static_cast<const char*>(0))
|
||||
.success());
|
||||
}
|
||||
|
24
test/gtest.cmake
Normal file
24
test/gtest.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(GTEST_DIR ../third-party/gtest-1.7.0)
|
||||
|
||||
add_library(gtest
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
${GTEST_DIR}/src/gtest_main.cc
|
||||
)
|
||||
|
||||
target_include_directories(gtest
|
||||
PUBLIC
|
||||
${GTEST_DIR}
|
||||
${GTEST_DIR}/include
|
||||
)
|
||||
|
||||
|
||||
target_compile_definitions(gtest PUBLIC -DGTEST_HAS_PTHREAD=0)
|
||||
|
||||
if (MSVC)
|
||||
if (MSVC_VERSION EQUAL 1700)
|
||||
# Workaround for Visual Studio 2012
|
||||
target_compile_definitions(gtest PUBLIC -D_VARIADIC_MAX=10)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(gtest PUBLIC -D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
Reference in New Issue
Block a user