--------------------------------------------------------------------------
| 36 | |
| 37 | //-------------------------------------------------------------------------- |
| 38 | TEST(StreamSerialiserTests,WriteBasic) |
| 39 | { |
| 40 | FileSystemArchiveFactory factory; |
| 41 | Archive* arch = factory.createInstance("./", false); |
| 42 | arch->load(); |
| 43 | |
| 44 | String fileName = "testSerialiser.dat"; |
| 45 | Vector3 aTestVector(0.3, 15.2, -12.0); |
| 46 | String aTestString = "Some text here"; |
| 47 | int aTestValue = 99; |
| 48 | uint32 chunkID = StreamSerialiser::makeIdentifier("TEST"); |
| 49 | |
| 50 | // write the data |
| 51 | { |
| 52 | DataStreamPtr stream = arch->create(fileName); |
| 53 | |
| 54 | StreamSerialiser serialiser(stream); |
| 55 | |
| 56 | serialiser.writeChunkBegin(chunkID); |
| 57 | |
| 58 | serialiser.write(&aTestVector); |
| 59 | serialiser.write(&aTestString); |
| 60 | serialiser.write(&aTestValue); |
| 61 | serialiser.writeChunkEnd(chunkID); |
| 62 | } |
| 63 | |
| 64 | // read it back |
| 65 | { |
| 66 | DataStreamPtr stream = arch->open(fileName); |
| 67 | |
| 68 | StreamSerialiser serialiser(stream); |
| 69 | |
| 70 | const StreamSerialiser::Chunk* c = serialiser.readChunkBegin(); |
| 71 | |
| 72 | EXPECT_EQ(chunkID, c->id); |
| 73 | EXPECT_EQ(sizeof(Vector3) + sizeof(int) + aTestString.size() + 4, (size_t)c->length); |
| 74 | |
| 75 | Vector3 inVector; |
| 76 | String inString; |
| 77 | int inValue; |
| 78 | |
| 79 | serialiser.read(&inVector); |
| 80 | serialiser.read(&inString); |
| 81 | serialiser.read(&inValue); |
| 82 | serialiser.readChunkEnd(chunkID); |
| 83 | |
| 84 | EXPECT_EQ(aTestVector, inVector); |
| 85 | EXPECT_EQ(aTestString, inString); |
| 86 | EXPECT_EQ(aTestValue, inValue); |
| 87 | } |
| 88 | |
| 89 | arch->remove(fileName); |
| 90 | |
| 91 | EXPECT_TRUE(!arch->exists(fileName)); |
| 92 | |
| 93 | factory.destroyInstance(arch); |
| 94 | } |
| 95 | //-------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected