Merge branch 'master' into 0.y.z

- fix for "C++ Builder" IDE
- Travis CI/AppVeyor
- **cmake** tweak
- fix memory leak in unit-test

See #268 and #252.
This commit is contained in:
Christopher Dunn 2015-04-27 18:31:32 -07:00
commit c334ac0376
13 changed files with 84 additions and 38 deletions

View File

@ -2,12 +2,20 @@
# http://about.travis-ci.org/docs/user/build-configuration/ # http://about.travis-ci.org/docs/user/build-configuration/
# This file can be validated on: # This file can be validated on:
# http://lint.travis-ci.org/ # http://lint.travis-ci.org/
before_install: sudo apt-get install cmake
#before_install: sudo apt-get install -y cmake
# cmake is pre-installed in Travis for both linux and osx
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq valgrind
os:
- linux
language: cpp language: cpp
compiler: compiler:
- gcc - gcc
- clang - clang
script: cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DJSONCPP_LIB_BUILD_SHARED=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE . && make && make jsoncpp_check script: ./travis.sh
env: env:
matrix: matrix:
- SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false - SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false

View File

@ -9,6 +9,8 @@ OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON) OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF) OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON)
# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
IF(NOT WIN32) IF(NOT WIN32)

View File

@ -58,7 +58,7 @@ Steps for generating solution/makefiles using `cmake-gui`:
* Make "source code" point to the source directory. * Make "source code" point to the source directory.
* Make "where to build the binary" point to the directory to use for the build. * Make "where to build the binary" point to the directory to use for the build.
* Click on the "Grouped" check box. * Click on the "Grouped" check box.
* Review JsonCpp build options (tick `JSONCPP_LIB_BUILD_SHARED` to build as a * Review JsonCpp build options (tick `BUILD_SHARED_LIBS` to build as a
dynamic library). dynamic library).
* Click the configure button at the bottom, then the generate button. * Click the configure button at the bottom, then the generate button.
* The generated solution/makefiles can be found in the binary directory. * The generated solution/makefiles can be found in the binary directory.
@ -67,7 +67,7 @@ Alternatively, from the command-line on Unix in the source directory:
mkdir -p build/debug mkdir -p build/debug
cd build/debug cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../.. cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -G "Unix Makefiles" ../..
make make
Running `cmake -`" will display the list of available generators (passed using Running `cmake -`" will display the list of available generators (passed using

View File

@ -16,7 +16,7 @@ dox:
# Then 'git add -A' and 'git push' in jsoncpp-docs. # Then 'git add -A' and 'git push' in jsoncpp-docs.
build: build:
mkdir -p build/debug mkdir -p build/debug
cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_SHARED=ON -G "Unix Makefiles" ../.. cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_SHARED_LIBS=ON -G "Unix Makefiles" ../..
make -C build/debug make -C build/debug
# Currently, this depends on include/json/version.h generated # Currently, this depends on include/json/version.h generated
@ -26,6 +26,9 @@ test-amalgamate:
python3.4 amalgamate.py python3.4 amalgamate.py
cd dist; gcc -I. -c jsoncpp.cpp cd dist; gcc -I. -c jsoncpp.cpp
valgrind:
valgrind --error-exitcode=42 --leak-check=full ./build/debug/src/test_lib_json/jsoncpp_test
clean: clean:
\rm -rf *.gz *.asc dist/ \rm -rf *.gz *.asc dist/

View File

@ -19,8 +19,8 @@
}, },
{"name": "shared_dll", {"name": "shared_dll",
"variables": [ "variables": [
["JSONCPP_LIB_BUILD_SHARED=true"], ["BUILD_SHARED_LIBS=true"],
["JSONCPP_LIB_BUILD_SHARED=false"] ["BUILD_SHARED_LIBS=false"]
] ]
}, },
{"name": "build_type", {"name": "build_type",

View File

@ -12,8 +12,8 @@
}, },
{"name": "shared_dll", {"name": "shared_dll",
"variables": [ "variables": [
["JSONCPP_LIB_BUILD_SHARED=true"], ["BUILD_SHARED_LIBS=true"],
["JSONCPP_LIB_BUILD_SHARED=false"] ["BUILD_SHARED_LIBS=false"]
] ]
}, },
{"name": "build_type", {"name": "build_type",

View File

@ -302,13 +302,13 @@ public:
/** Called by ctor, but you can use this to reset settings_. /** Called by ctor, but you can use this to reset settings_.
* \pre 'settings' != NULL (but Json::null is fine) * \pre 'settings' != NULL (but Json::null is fine)
* \remark Defaults: * \remark Defaults:
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
*/ */
static void setDefaults(Json::Value* settings); static void setDefaults(Json::Value* settings);
/** Same as old Features::strictMode(). /** Same as old Features::strictMode().
* \pre 'settings' != NULL (but Json::null is fine) * \pre 'settings' != NULL (but Json::null is fine)
* \remark Defaults: * \remark Defaults:
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
*/ */
static void strictMode(Json::Value* settings); static void strictMode(Json::Value* settings);
}; };

View File

@ -214,7 +214,7 @@ private:
void swap(CZString& other); void swap(CZString& other);
struct StringStorage { struct StringStorage {
DuplicationPolicy policy_: 2; unsigned policy_: 2;
unsigned length_: 30; // 1GB max unsigned length_: 30; // 1GB max
}; };

View File

@ -1,18 +1,15 @@
FIND_PACKAGE(PythonInterp 2.6) FIND_PACKAGE(PythonInterp 2.6)
IF(JSONCPP_LIB_BUILD_SHARED)
ADD_DEFINITIONS( -DJSON_DLL )
ENDIF(JSONCPP_LIB_BUILD_SHARED)
ADD_EXECUTABLE(jsontestrunner_exe ADD_EXECUTABLE(jsontestrunner_exe
main.cpp main.cpp
) )
IF(JSONCPP_LIB_BUILD_SHARED) IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS( -DJSON_DLL )
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib) TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib)
ELSE(JSONCPP_LIB_BUILD_SHARED) ELSE(BUILD_SHARED_LIBS)
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib_static) TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib_static)
ENDIF(JSONCPP_LIB_BUILD_SHARED) ENDIF(BUILD_SHARED_LIBS)
SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe) SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)

View File

@ -1,10 +1,3 @@
OPTION(JSONCPP_LIB_BUILD_SHARED "Build jsoncpp_lib as a shared library." OFF)
OPTION(JSONCPP_LIB_BUILD_STATIC "Build jsoncpp_lib static library." ON)
IF(BUILD_SHARED_LIBS)
SET(JSONCPP_LIB_BUILD_SHARED ON)
ENDIF(BUILD_SHARED_LIBS)
if( CMAKE_COMPILER_IS_GNUCXX ) if( CMAKE_COMPILER_IS_GNUCXX )
#Get compiler version. #Get compiler version.
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
@ -46,7 +39,7 @@ ELSE(JSONCPP_WITH_CMAKE_PACKAGE)
SET(INSTALL_EXPORT) SET(INSTALL_EXPORT)
ENDIF(JSONCPP_WITH_CMAKE_PACKAGE) ENDIF(JSONCPP_WITH_CMAKE_PACKAGE)
IF(JSONCPP_LIB_BUILD_SHARED) IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS( -DJSON_DLL_BUILD ) ADD_DEFINITIONS( -DJSON_DLL_BUILD )
ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources}) ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources})
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR}) SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
@ -65,7 +58,7 @@ IF(JSONCPP_LIB_BUILD_SHARED)
ENDIF() ENDIF()
IF(JSONCPP_LIB_BUILD_STATIC) IF(BUILD_STATIC_LIBS)
ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources}) ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources})
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR}) SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp ) SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp )

View File

@ -1,9 +1,5 @@
# vim: et ts=4 sts=4 sw=4 tw=0 # vim: et ts=4 sts=4 sw=4 tw=0
IF(JSONCPP_LIB_BUILD_SHARED)
ADD_DEFINITIONS( -DJSON_DLL )
ENDIF(JSONCPP_LIB_BUILD_SHARED)
ADD_EXECUTABLE( jsoncpp_test ADD_EXECUTABLE( jsoncpp_test
jsontest.cpp jsontest.cpp
jsontest.h jsontest.h
@ -11,11 +7,12 @@ ADD_EXECUTABLE( jsoncpp_test
) )
IF(JSONCPP_LIB_BUILD_SHARED) IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS( -DJSON_DLL )
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib) TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib)
ELSE(JSONCPP_LIB_BUILD_SHARED) ELSE(BUILD_SHARED_LIBS)
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static) TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static)
ENDIF(JSONCPP_LIB_BUILD_SHARED) ENDIF(BUILD_SHARED_LIBS)
# another way to solve issue #90 # another way to solve issue #90
#set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store) #set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store)
@ -23,19 +20,19 @@ ENDIF(JSONCPP_LIB_BUILD_SHARED)
# Run unit tests in post-build # Run unit tests in post-build
# (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?) # (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
IF(JSONCPP_WITH_POST_BUILD_UNITTEST) IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
IF(JSONCPP_LIB_BUILD_SHARED) IF(BUILD_SHARED_LIBS)
# First, copy the shared lib, for Microsoft. # First, copy the shared lib, for Microsoft.
# Then, run the test executable. # Then, run the test executable.
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test> COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test>
COMMAND $<TARGET_FILE:jsoncpp_test>) COMMAND $<TARGET_FILE:jsoncpp_test>)
ELSE(JSONCPP_LIB_BUILD_SHARED) ELSE(BUILD_SHARED_LIBS)
# Just run the test executable. # Just run the test executable.
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
POST_BUILD POST_BUILD
COMMAND $<TARGET_FILE:jsoncpp_test>) COMMAND $<TARGET_FILE:jsoncpp_test>)
ENDIF(JSONCPP_LIB_BUILD_SHARED) ENDIF(BUILD_SHARED_LIBS)
ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST) ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST)
SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test) SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)

View File

@ -257,6 +257,20 @@ JSONTEST_FIXTURE(ValueTest, arrays) {
JSONTEST_ASSERT_EQUAL(Json::Value(17), got); JSONTEST_ASSERT_EQUAL(Json::Value(17), got);
JSONTEST_ASSERT_EQUAL(false, array1_.removeIndex(2, &got)); // gone now JSONTEST_ASSERT_EQUAL(false, array1_.removeIndex(2, &got)); // gone now
} }
JSONTEST_FIXTURE(ValueTest, arrayIssue252)
{
int count = 5;
Json::Value root;
Json::Value item;
root["array"] = Json::Value::nullRef;
for (int i = 0; i < count; i++)
{
item["a"] = i;
item["b"] = i;
root["array"][i] = item;
}
//JSONTEST_ASSERT_EQUAL(5, root["array"].size());
}
JSONTEST_FIXTURE(ValueTest, null) { JSONTEST_FIXTURE(ValueTest, null) {
JSONTEST_ASSERT_EQUAL(Json::nullValue, null_.type()); JSONTEST_ASSERT_EQUAL(Json::nullValue, null_.type());
@ -2139,6 +2153,7 @@ JSONTEST_FIXTURE(CharReaderAllowSingleQuotesTest, issue182) {
JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString()); JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString());
JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString()); JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString());
} }
delete reader;
} }
struct CharReaderAllowZeroesTest : JsonTest::TestCase {}; struct CharReaderAllowZeroesTest : JsonTest::TestCase {};
@ -2171,6 +2186,7 @@ JSONTEST_FIXTURE(CharReaderAllowZeroesTest, issue176) {
JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString()); JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString());
JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString()); JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString());
} }
delete reader;
} }
struct BuilderTest : JsonTest::TestCase {}; struct BuilderTest : JsonTest::TestCase {};
@ -2254,6 +2270,7 @@ int main(int argc, const char* argv[]) {
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, objects); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, objects);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrays); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrays);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrayIssue252);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, null); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, null);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, strings); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, strings);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, bools); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, bools);

29
travis.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env sh
# This is called by `.travis.yml` via Travis CI.
# Travis supplies $TRAVIS_OS_NAME.
# http://docs.travis-ci.com/user/multi-os/
# Our .travis.yml also defines:
# - SHARED_LIB=ON/OFF
# - STATIC_LIB=ON/OFF
# - CMAKE_PKG=ON/OFF
# - BUILD_TYPE=release/debug
# - VERBOSE_MAKE=false/true
# - VERBOSE (set or not)
# -e: fail on error
# -v: show commands
# -x: show expanded commands
set -vex
env | sort
cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DBUILD_SHARED_LIBS=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE .
make
# Python is not available in Travis for osx.
# https://github.com/travis-ci/travis-ci/issues/2320
if [ "$TRAVIS_OS_NAME" != "osx" ]
then
make jsoncpp_check
valgrind --error-exitcode=42 --leak-check=full ./src/test_lib_json/jsoncpp_test
fi