Added scenery save/load testing

This commit is contained in:
Michaël Lemaire 2015-08-04 00:00:56 +02:00
parent 0585bc4b6f
commit 7d79b6f772
4 changed files with 39 additions and 6 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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