ACF $AcfVersion:0$
CBitMemoryArchiveTest.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QObject>
7#include <QtTest/QtTest>
8
9// ACF includes
12#include <iser/ISerializable.h>
13#include <iser/IArchive.h>
14#include <iser/CArchiveTag.h>
15
16
17class CBitMemoryArchiveTest: public QObject
18{
19 Q_OBJECT
20
21private Q_SLOTS:
22 void BasicBitSerializationTest();
23 void MultipleBoolsTest();
24 void MixedDataTest();
25
26private:
27 class BoolModel: virtual public iser::ISerializable
28 {
29 public:
30 virtual bool Serialize(iser::IArchive& archive) override
31 {
32 static iser::CArchiveTag tag("BoolValue", "Boolean value");
33 bool retVal = archive.BeginTag(tag);
34 retVal = retVal && archive.Process(value);
35 retVal = retVal && archive.EndTag(tag);
36 return retVal;
37 }
38
39 bool value = false;
40 };
41
42 class MultiBoolModel: virtual public iser::ISerializable
43 {
44 public:
45 virtual bool Serialize(iser::IArchive& archive) override
46 {
47 static iser::CArchiveTag tag1("Bool1", "First boolean");
48 static iser::CArchiveTag tag2("Bool2", "Second boolean");
49 static iser::CArchiveTag tag3("Bool3", "Third boolean");
50
51 bool retVal = archive.BeginTag(tag1);
52 retVal = retVal && archive.Process(value1);
53 retVal = retVal && archive.EndTag(tag1);
54
55 retVal = retVal && archive.BeginTag(tag2);
56 retVal = retVal && archive.Process(value2);
57 retVal = retVal && archive.EndTag(tag2);
58
59 retVal = retVal && archive.BeginTag(tag3);
60 retVal = retVal && archive.Process(value3);
61 retVal = retVal && archive.EndTag(tag3);
62
63 return retVal;
64 }
65
66 bool value1 = false;
67 bool value2 = false;
68 bool value3 = false;
69
70 bool operator==(const MultiBoolModel& other) const
71 {
72 return value1 == other.value1 &&
73 value2 == other.value2 &&
74 value3 == other.value3;
75 }
76 };
77
78 class MixedModel: virtual public iser::ISerializable
79 {
80 public:
81 virtual bool Serialize(iser::IArchive& archive) override
82 {
83 static iser::CArchiveTag boolTag("BoolValue", "Boolean value");
84 static iser::CArchiveTag intTag("IntValue", "Integer value");
85
86 bool retVal = archive.BeginTag(boolTag);
87 retVal = retVal && archive.Process(boolValue);
88 retVal = retVal && archive.EndTag(boolTag);
89
90 retVal = retVal && archive.BeginTag(intTag);
91 retVal = retVal && archive.Process(intValue);
92 retVal = retVal && archive.EndTag(intTag);
93
94 return retVal;
95 }
96
97 bool boolValue = false;
98 int intValue = 0;
99
100 bool operator==(const MixedModel& other) const
101 {
102 return boolValue == other.boolValue && intValue == other.intValue;
103 }
104 };
105};
106
107
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
virtual bool Process(bool &value)=0
Processes (reads or writes) a boolean value.
virtual bool EndTag(const CArchiveTag &tag)=0
Ends a tagged section in the archive.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begins a tagged section in the archive.
Common class for all classes which objects can be archived or restored from archive.