Browse Source

add unit test using Googletest framework. Works only on Debian for now. Please generalize the Makefile!!!

JSON-80
Lars Rohwedder 5 years ago
parent
commit
4702391e34
3 changed files with 26 additions and 3 deletions
  1. +9
    -3
      server/Makefile
  2. +3
    -0
      server/Makefile.conf
  3. +14
    -0
      server/unittest_json.cc

+ 9
- 3
server/Makefile View File

@ -22,7 +22,7 @@ ifdef BUILD_CONFIG
$(info ================================================)
endif
NO_SOURCE=main.cc servertest.cc
NO_SOURCE=main.cc servertest.cc unittest_json.cc
ALL_SOURCE=$(filter-out $(NO_SOURCE),$(wildcard json_spirit/*.cpp))
ALL_SOURCE+= prefix-config.cc
@ -75,7 +75,7 @@ ifdef DEBUG
endif
.PHONY: all
all: $(TARGET) $(TARGET_TEST)
all: $(TARGET) $(TARGET_TEST) $(TARGET_GTEST)
$(TARGET): main.o libjson-adapter.a
$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
@ -83,7 +83,10 @@ $(TARGET): main.o libjson-adapter.a
$(TARGET)-static: main.o libjson-adapter.a
$(CXX) $^ $(LDFLAGS) $(LDLIBS) -static -o $@
$(TARGET_TEST): servertest.o
$(TARGET_TEST): servertest.o libjson-adapter.a
$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
$(TARGET_GTEST): unittest_json.o gtest-all.o libjson-adapter.a
$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
libjson-adapter.a: $(ALL_OBJECTS)
@ -92,6 +95,9 @@ libjson-adapter.a: $(ALL_OBJECTS)
prefix-config.cc:
echo '// This file is generated by make. Edit the Makefile, not this file!\n#include "prefix-config.hh" \nconst char* const html_directory = "'$(HTML_DIRECTORY)'";\n' > $@
gtest-all.o: /usr/src/googletest/googletest/src/gtest-all.cc
$(CXX) $(CXXFLAGS) -I/usr/src/googletest/googletest/ -o $@ -c $<
%.o: %.cc %.hh
$(CXX) $(CXXFLAGS) -c $<


+ 3
- 0
server/Makefile.conf View File

@ -35,6 +35,9 @@ TARGET=pep-json-server
# Filename of the pEp JSON Server Adapter testing binary
TARGET_TEST=servertest
# Filename of the unittest binary (TODO: will be changed when more tests will be there!)
TARGET_GTEST=unittest_json
# If empty, create a release build.
# Otherwise, create a debug build.
# This variable is ineffective in your local.conf file.


+ 14
- 0
server/unittest_json.cc View File

@ -0,0 +1,14 @@
#include <gtest/gtest.h>
#include "inout.hh" // for to_json() and from_json()
TEST(ToFromJsonTest, SimpleCases)
{
EXPECT_EQ( js::Value(""), to_json<std::string>("") );
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

Loading…
Cancel
Save