diff --git a/Makefile b/Makefile index 2b2250e..a8ada53 100644 --- a/Makefile +++ b/Makefile @@ -35,11 +35,14 @@ debug: release: +make BUILDMODE=release all +testscheck: + +make RUNNER='valgrind --leak-check=full' BUILDMODE=debug tests + tests:build ifdef TESTCASE - LD_LIBRARY_PATH=$(LIBRARY_PATH) ${BUILDPATH}/tests/paysages-tests --gtest_filter=$(TESTCASE).* + LD_LIBRARY_PATH=$(LIBRARY_PATH) ${RUNNER} ${BUILDPATH}/tests/paysages-tests --gtest_filter=$(TESTCASE).* else - LD_LIBRARY_PATH=$(LIBRARY_PATH) ${BUILDPATH}/tests/paysages-tests + LD_LIBRARY_PATH=$(LIBRARY_PATH) ${RUNNER} ${BUILDPATH}/tests/paysages-tests endif run:build diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index cdabef4..e9fa39c 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -49,20 +49,22 @@ void Scenery::validate() Scenery::FileOperationResult Scenery::saveGlobal(const std::string &filepath) const { PackStream stream; - double app_header, version_header; + double app_header = (double)APP_HEADER; + double version_header = (double)DATA_VERSION; if (not stream.bindToFile(filepath, true)) { return FILE_OPERATION_IOERROR; } - app_header = (double)APP_HEADER; stream.write(&app_header); - version_header = (double)DATA_VERSION; stream.write(&version_header); save(&stream); + stream.write(&version_header); + stream.write(&app_header); + return FILE_OPERATION_OK; } @@ -90,6 +92,18 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath) load(&stream); + stream.read(&version_header); + if ((int)version_header != DATA_VERSION) + { + return FILE_OPERATION_VERSION_MISMATCH; + } + + stream.read(&app_header); + if (app_header != APP_HEADER) + { + return FILE_OPERATION_APP_MISMATCH; + } + return FILE_OPERATION_OK; } diff --git a/src/tests/Scenery_Test.cpp b/src/tests/Scenery_Test.cpp new file mode 100644 index 0000000..2a251e1 --- /dev/null +++ b/src/tests/Scenery_Test.cpp @@ -0,0 +1,15 @@ +#include "BaseTestCase.h" + +#include "Scenery.h" + +TEST(Scenery, saveGlobal) +{ + Scenery scenery; + scenery.autoPreset(); + + Scenery::FileOperationResult result = scenery.saveGlobal("/tmp/test_paysages_scenery"); + EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result); + + result = scenery.loadGlobal("/tmp/test_paysages_scenery"); + EXPECT_EQ((int)Scenery::FILE_OPERATION_OK, result); +} diff --git a/src/tests/tests.pro b/src/tests/tests.pro index 4668460..cc1d578 100644 --- a/src/tests/tests.pro +++ b/src/tests/tests.pro @@ -21,7 +21,8 @@ SOURCES += main.cpp \ Canvas_Test.cpp \ CanvasPortion_Test.cpp \ CanvasPreview_Test.cpp \ - AtmosphereDefinition_Test.cpp + AtmosphereDefinition_Test.cpp \ + Scenery_Test.cpp HEADERS += \ BaseTestCase.h