Added unit tests for FloatNode
This commit is contained in:
parent
d65bc18342
commit
d78bd2553c
5 changed files with 59 additions and 1 deletions
|
@ -23,6 +23,22 @@ PackStream::~PackStream()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackStream::PackStream(const PackStream *other)
|
||||||
|
{
|
||||||
|
file = NULL;
|
||||||
|
buffer = new QByteArray();
|
||||||
|
if (other->file)
|
||||||
|
{
|
||||||
|
Logs::error() << "Try to read from a substream bound to a file: " << other->file->fileName().toStdString() << std::endl;
|
||||||
|
stream = new QDataStream(buffer, QIODevice::ReadOnly);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stream = new QDataStream(other->buffer, QIODevice::ReadOnly);
|
||||||
|
}
|
||||||
|
stream->setVersion(QDataStream::Qt_5_2);
|
||||||
|
}
|
||||||
|
|
||||||
bool PackStream::bindToFile(const std::string &filepath, bool write)
|
bool PackStream::bindToFile(const std::string &filepath, bool write)
|
||||||
{
|
{
|
||||||
if (not file)
|
if (not file)
|
||||||
|
|
|
@ -20,6 +20,13 @@ public:
|
||||||
PackStream();
|
PackStream();
|
||||||
~PackStream();
|
~PackStream();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a reading stream for another stream.
|
||||||
|
*
|
||||||
|
* The other stream must not have been bound to a file (still a memory buffer).
|
||||||
|
*/
|
||||||
|
PackStream(const PackStream *other);
|
||||||
|
|
||||||
bool bindToFile(const std::string &filepath, bool write=false);
|
bool bindToFile(const std::string &filepath, bool write=false);
|
||||||
|
|
||||||
void write(const int *value);
|
void write(const int *value);
|
||||||
|
|
|
@ -39,6 +39,7 @@ TEST(DefinitionNode, attachDetach)
|
||||||
TEST(DefinitionNode, saveLoad)
|
TEST(DefinitionNode, saveLoad)
|
||||||
{
|
{
|
||||||
PackStream *stream;
|
PackStream *stream;
|
||||||
|
int check_in = 42, check_out = 0;
|
||||||
|
|
||||||
DefinitionNode* before = new DefinitionNode(NULL, "root");
|
DefinitionNode* before = new DefinitionNode(NULL, "root");
|
||||||
DefinitionNode* before1 = new DefinitionNode(before, "before1");
|
DefinitionNode* before1 = new DefinitionNode(before, "before1");
|
||||||
|
@ -52,6 +53,7 @@ TEST(DefinitionNode, saveLoad)
|
||||||
stream = new PackStream();
|
stream = new PackStream();
|
||||||
stream->bindToFile("/tmp/test_paysages_pack", true);
|
stream->bindToFile("/tmp/test_paysages_pack", true);
|
||||||
before->save(stream);
|
before->save(stream);
|
||||||
|
stream->write(&check_in);
|
||||||
delete stream;
|
delete stream;
|
||||||
|
|
||||||
// Same definition tree, but with missing nodes, and added ones
|
// Same definition tree, but with missing nodes, and added ones
|
||||||
|
@ -65,12 +67,14 @@ TEST(DefinitionNode, saveLoad)
|
||||||
stream = new PackStream();
|
stream = new PackStream();
|
||||||
stream->bindToFile("/tmp/test_paysages_pack");
|
stream->bindToFile("/tmp/test_paysages_pack");
|
||||||
after->load(stream);
|
after->load(stream);
|
||||||
|
stream->read(&check_out);
|
||||||
delete stream;
|
delete stream;
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(-4.3, after12->getValue());
|
EXPECT_DOUBLE_EQ(-4.3, after12->getValue());
|
||||||
EXPECT_DOUBLE_EQ(0.0, after13->getValue());
|
EXPECT_DOUBLE_EQ(0.0, after13->getValue());
|
||||||
EXPECT_DOUBLE_EQ(6.7, after3->getValue());
|
EXPECT_DOUBLE_EQ(6.7, after3->getValue());
|
||||||
EXPECT_DOUBLE_EQ(0.0, after4->getValue());
|
EXPECT_DOUBLE_EQ(0.0, after4->getValue());
|
||||||
|
EXPECT_EQ(42, check_out);
|
||||||
|
|
||||||
delete before;
|
delete before;
|
||||||
delete after;
|
delete after;
|
||||||
|
|
30
src/tests/FloatNode_Test.cpp
Normal file
30
src/tests/FloatNode_Test.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include "BaseTestCase.h"
|
||||||
|
|
||||||
|
#include "FloatNode.h"
|
||||||
|
#include "PackStream.h"
|
||||||
|
|
||||||
|
TEST(FloatNode, toString)
|
||||||
|
{
|
||||||
|
FloatNode test(NULL, "test", 2.1);
|
||||||
|
|
||||||
|
EXPECT_EQ("test 2.1", test.toString(0));
|
||||||
|
EXPECT_EQ(" test 2.1", test.toString(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FloatNode, saveLoadAndSkip)
|
||||||
|
{
|
||||||
|
DefinitionNode root1(NULL, "root");
|
||||||
|
FloatNode testa1(&root1, "testa", 1.5);
|
||||||
|
FloatNode testb1(&root1, "testb", 4.3);
|
||||||
|
|
||||||
|
PackStream stream1;
|
||||||
|
root1.save(&stream1);
|
||||||
|
|
||||||
|
DefinitionNode root2(NULL, "root");
|
||||||
|
FloatNode testb2(&root2, "testb");
|
||||||
|
|
||||||
|
PackStream stream2(&stream1);
|
||||||
|
root2.load(&stream2);
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(4.3, testb2.getValue());
|
||||||
|
}
|
|
@ -23,7 +23,8 @@ SOURCES += main.cpp \
|
||||||
CanvasPreview_Test.cpp \
|
CanvasPreview_Test.cpp \
|
||||||
AtmosphereDefinition_Test.cpp \
|
AtmosphereDefinition_Test.cpp \
|
||||||
Scenery_Test.cpp \
|
Scenery_Test.cpp \
|
||||||
DefinitionNode_Test.cpp
|
DefinitionNode_Test.cpp \
|
||||||
|
FloatNode_Test.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
BaseTestCase.h
|
BaseTestCase.h
|
||||||
|
|
Loading…
Reference in a new issue