diff --git a/.gitignore b/.gitignore index 522c725..32c2539 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,4 @@ Sandbox/* *.out *.app dstargateway - +Tests/dstargateway_tests diff --git a/.vscode/launch.json b/.vscode/launch.json index b2c785b..ef85a5f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,6 +27,30 @@ "ignoreFailures": true } ] + }, + { + "name": "Tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/Tests/dstargateway_tests", + "args": [ ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Activer l'impression en mode Pretty pour gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Définir la version désassemblage sur Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index d43f3db..a509b7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -30,5 +30,9 @@ } } ] - } + }, + "gtest-adapter.debugConfig": [ + "Tests" + ], + "gtest-adapter.supportLocation": true } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f50a809..2fa8b11 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -10,10 +10,7 @@ "args": [ "-j3" ], - "group": { - "kind": "build", - "isDefault": true - }, + "group": "build", "problemMatcher": [] }, { @@ -24,7 +21,10 @@ "-j3", "tests" ], - "group": "build", + "group": { + "kind": "build", + "isDefault": true + }, "problemMatcher": [] } ] diff --git a/Makefile b/Makefile index 97c6838..a768147 100644 --- a/Makefile +++ b/Makefile @@ -22,15 +22,15 @@ export DATA_DIR=/usr/local/share/dstargateway.d/ export LOG_DIR=/var/log/dstargateway/ # choose this if you want debugging help -CPPFLAGS=-g -ggdb -W -Wall -Werror -std=c++17 +export CPPFLAGS=-g -ggdb -W -Wall -Werror -std=c++17 # or, you can choose this for a much smaller executable without debugging help #CPPFLAGS=-W -Wall -Werror -std=c++17 - -LDFLAGS:=-lcurl -pthread +export CC=g++ +export LDFLAGS:=-lcurl -pthread ifeq ($(USE_GPSD), 1) -CPPFLAGS+= -DUSE_GPSD -LDFLAGS+= -lgps +export CPPFLAGS+= -DUSE_GPSD +export LDFLAGS+= -lgps endif SRCS = $(wildcard *.cpp) @@ -38,13 +38,13 @@ OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) .PHONY: all -all: dstargateway +all: dstargateway tests dstargateway : GitVersion.h $(OBJS) - g++ $(CPPFLAGS) -o dstargateway $(OBJS) $(LDFLAGS) + $(CC) $(CPPFLAGS) -o dstargateway $(OBJS) $(LDFLAGS) %.o : %.cpp - g++ $(CPPFLAGS) -MMD -MD -c $< -o $@ + $(CC) $(CPPFLAGS) -MMD -MD -c $< -o $@ GitVersion.h : FORCE ifneq ("$(wildcard .git/index)","") @@ -66,7 +66,8 @@ endif .PHONY: clean clean: - $(RM) GitVersion.h $(OBJS) $(DEPS) dstargateway + @$(RM) GitVersion.h $(OBJS) $(DEPS) dstargateway + @$(MAKE) -C Tests clean -include $(DEPS) @@ -129,6 +130,8 @@ removehostfiles : @rm -f $(DATA_DIR)/DCS_Hosts.txt @rm -f $(DATA_DIR)/DPlus_Hosts.txt - +.PHONY tests: +tests : GitVersion.h $(OBJS) + $(MAKE) -C Tests tests FORCE: \ No newline at end of file diff --git a/Tests/Makefile b/Tests/Makefile new file mode 100644 index 0000000..18c1255 --- /dev/null +++ b/Tests/Makefile @@ -0,0 +1,25 @@ + +SRCS = $(wildcard *.cpp) $(wildcard ../*.cpp) +OBJS = $(SRCS:.cpp=.o) +DEPS = $(SRCS:.cpp=.d) + +.PHONY tests: +tests: rmdstargatewayapp $(OBJS) + $(CC) $(CPPFLAGS) -o dstargateway_tests $(OBJS) $(LDFLAGS) -lgtest -lgtest_main + +%.o : %.cpp + $(CC) $(CPPFLAGS) -DUNIT_TESTS -I../ -MMD -MD -c $< -o $@ + +-include $(DEPS) + +.PHONY clean : +clean : + @$(RM) $(OBJS) $(DEPS) dstargateway_tests + + +.PHONY rmdstargatewayapp : +rmdstargatewayapp: FORCE + @$(RM) ../DStarGatewayApp.o + @$(RM) ../DStarGatewayApp.d + +FORCE: \ No newline at end of file diff --git a/Tests/TestTest.cpp b/Tests/TestTest.cpp new file mode 100644 index 0000000..be6372e --- /dev/null +++ b/Tests/TestTest.cpp @@ -0,0 +1,54 @@ + + +#include + +#include + + + +// The fixture for testing class Foo. +class FooTest : public ::testing::Test { + protected: + // You can remove any or all of the following functions if their bodies would + // be empty. + + FooTest() { + // You can do set-up work for each test here. + } + + ~FooTest() override { + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + void SetUp() override { + // Code here will be called immediately after the constructor (right + // before each test). + } + + void TearDown() override { + // Code here will be called immediately after each test (right + // before the destructor). + } + + // Class members declared here can be used by all tests in the test suite + // for Foo. +}; + +// Tests that the Foo::Bar() method does Abc. +TEST_F(FooTest, MethodBarDoesAbc) { + const std::string input_filepath = "this/package/testdata/myinputfile.dat"; + const std::string output_filepath = "this/package/testdata/myoutputfile.dat"; + + TAPRSFrame frame; + CAPRSParser::parseFrame("bla", frame); + + EXPECT_EQ(frame.m_type, APFT_MESSAGE); +} + +// Tests that Foo does Xyz. +TEST_F(FooTest, DoesXyz) { + // Exercises the Xyz feature of Foo. +}