From 6c339d8aab380a191fe3fce7ca7dc7c09e252ebd Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 1 Jan 2023 15:48:43 +0100 Subject: Tests and coverage on gcc and clang --- Makefile | 2 +- common.mk | 3 ++- debian/control | 2 +- tests/Makefile | 14 +++++++++----- tests/test-config.cpp | 4 ++-- tests/test-storage.cpp | 24 ++++++++++++------------ whiteboard.cpp | 2 +- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 140b1ba..cce7045 100755 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ test: $(MAKE) -C tests clean: - -rm -f *.o *.fcgi + -rm -f *.o *.fcgi *.gcov $(MAKE) -C tests clean deb: diff --git a/common.mk b/common.mk index ccacd6c..118310f 100644 --- a/common.mk +++ b/common.mk @@ -1,4 +1,5 @@ CXX=clang++-14 +#CXX=g++-12 ifeq ($(shell which $(CXX)),) CXX=clang++-13 @@ -43,5 +44,5 @@ endif CXXFLAGS+=$(shell pkg-config --cflags qrcodegencpp Magick++ fmt sqlite3) LIBS+=-lfcgi -lboost_filesystem -LIBS+=$(shell pkg-config --libs qrcodegencpp Magick++ fmt sqlite3) -lSQLiteCpp +LIBS+=-lSQLiteCpp $(shell pkg-config --libs qrcodegencpp Magick++ fmt sqlite3) diff --git a/debian/control b/debian/control index 4b38950..ed6ee77 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: whiteboard Section: web Priority: optional Maintainer: Roland Reichwein -Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest +Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr Standards-Version: 4.5.0 Homepage: http://www.reichwein.it/whiteboard/ diff --git a/tests/Makefile b/tests/Makefile index e36198b..94789f9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,16 +1,16 @@ CXXFLAGS=-g -O0 +include ../common.mk + ifeq ($(CXX),clang++-14) CXXFLAGS+=-fprofile-instr-generate -fcoverage-mapping +LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping else # GCC CXXFLAGS+=--coverage +LDFLAGS+=--coverage endif -include ../common.mk - -LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping - UNITS=storage.cpp config.cpp file.cpp compiledsql.cpp qrcode.cpp whiteboard.cpp UNITTESTS=test-config.cpp \ @@ -29,6 +29,10 @@ ifeq ($(CXX),clang++-14) LLVM_PROFILE_FILE="unittests.profraw" ./unittests llvm-profdata-14 merge -sparse unittests.profraw -o unittests.profdata llvm-cov-14 report --ignore-filename-regex='google' --ignore-filename-regex='test-' --show-region-summary=0 -instr-profile unittests.profdata unittests +else + ./unittests + #gcov-12 storage.o + gcovr -r .. endif coverage: @@ -65,4 +69,4 @@ libgmock.a: ar -rv libgmock.a gmock-all.o gtest-all.o gmock_main.o clean: - -rm -f *.o *.a unittests *.gcno *.profraw *.profdata + -rm -f *.o *.a unittests *.gcda *.gcno *.profraw *.profdata *.gcov diff --git a/tests/test-config.cpp b/tests/test-config.cpp index 065dedf..cd358a6 100644 --- a/tests/test-config.cpp +++ b/tests/test-config.cpp @@ -33,7 +33,7 @@ TEST_F(ConfigTest, defaultData) { Config config{filename}; EXPECT_EQ(config.getDataPath(), "/var/lib/whiteboard"); - EXPECT_EQ(config.getMaxage(), 0); + EXPECT_EQ(config.getMaxage(), 0UL); ASSERT_TRUE(!fs::exists(filename)); } @@ -52,7 +52,7 @@ TEST_F(ConfigTest, testData) { Config config{testConfigFilename}; EXPECT_EQ(config.getDataPath(), "/some/other/location"); - EXPECT_EQ(config.getMaxage(), 2592000); + EXPECT_EQ(config.getMaxage(), 2592000UL); } std::error_code ec; diff --git a/tests/test-storage.cpp b/tests/test-storage.cpp index 11d8a20..87168fc 100644 --- a/tests/test-storage.cpp +++ b/tests/test-storage.cpp @@ -64,29 +64,29 @@ TEST_F(StorageTest, create) TEST_F(StorageTest, getNumberOfDocuments) { Storage storage(m_config); - EXPECT_EQ(storage.getNumberOfDocuments(), 0); + EXPECT_EQ(storage.getNumberOfDocuments(), 0UL); storage.setDocument("123", "abc"); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); storage.setDocument("def", "xyz"); - EXPECT_EQ(storage.getNumberOfDocuments(), 2); + EXPECT_EQ(storage.getNumberOfDocuments(), 2UL); } TEST_F(StorageTest, cleanup_empty) { Storage storage(m_config); - EXPECT_EQ(storage.getNumberOfDocuments(), 0); + EXPECT_EQ(storage.getNumberOfDocuments(), 0UL); storage.cleanup(); - EXPECT_EQ(storage.getNumberOfDocuments(), 0); + EXPECT_EQ(storage.getNumberOfDocuments(), 0UL); } TEST_F(StorageTest, cleanup) { Storage storage(m_config); - EXPECT_EQ(storage.getNumberOfDocuments(), 0); + EXPECT_EQ(storage.getNumberOfDocuments(), 0UL); storage.setDocument("123", "abc"); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); storage.cleanup(); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); } TEST_F(StorageTest, exists) @@ -111,7 +111,7 @@ TEST_F(StorageTest, setDocument) { Storage storage(m_config); storage.setDocument("0", "abc"); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); EXPECT_EQ(storage.getDocument("0"), "abc"); } @@ -121,7 +121,7 @@ TEST_F(StorageTest, setRevision) storage.setDocument("0", "abc"); storage.setRevision("0", 123); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); EXPECT_EQ(storage.getRevision("0"), 123); } @@ -131,7 +131,7 @@ TEST_F(StorageTest, setCursorPos) storage.setDocument("0", "abc"); storage.setCursorPos("0", 1234); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); EXPECT_EQ(storage.getCursorPos("0"), 1234); } @@ -140,7 +140,7 @@ TEST_F(StorageTest, setRow) Storage storage(m_config); storage.setRow("0", "abc", 56, 67); - EXPECT_EQ(storage.getNumberOfDocuments(), 1); + EXPECT_EQ(storage.getNumberOfDocuments(), 1UL); EXPECT_EQ(storage.getDocument("0"), "abc"); EXPECT_EQ(storage.getRevision("0"), 56); EXPECT_EQ(storage.getCursorPos("0"), 67); diff --git a/whiteboard.cpp b/whiteboard.cpp index 2718937..cebd0b1 100644 --- a/whiteboard.cpp +++ b/whiteboard.cpp @@ -38,7 +38,7 @@ namespace { uint32_t checksum32(const std::string& s) { uint32_t result{0}; - for (int i = 0; i < s.size(); i++) { + for (unsigned int i = 0; i < s.size(); i++) { result = ((result >> 1) | ((result & 1) << 31)) ^ (s[i] & 0xFF); } return result & 0x7FFFFFFF; -- cgit v1.2.3