ACF $AcfVersion:0$
CJsonMemoryReadArchiveTest.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
11#include <iser/ISerializable.h>
12#include <iser/IArchive.h>
13#include <iser/CArchiveTag.h>
14
15
16class CJsonMemoryReadArchiveTest: public QObject
17{
18 Q_OBJECT
19
20private Q_SLOTS:
21 void DoTest();
22 void DoArrayTest();
23
24private:
25 class Model: virtual public iser::ISerializable
26 {
27 public:
28 virtual bool Serialize(iser::IArchive& archive) override
29 {
30 static iser::CArchiveTag typeTag("Type", "Type of the meta information");
31 bool retVal = archive.BeginTag(typeTag);
32 retVal = retVal && archive.Process(value);
33 retVal = retVal && archive.EndTag(typeTag);
34
35 return retVal;
36 }
37
38 int value = 42;
39 };
40
41 class NestedArray : public iser::ISerializable
42 {
43 public:
44 NestedArray() = default;
45
46 NestedArray(QList<QList<double>> data)
47 : m_data(data)
48 {
49 }
50
51 virtual bool Serialize(iser::IArchive& archive) override
52 {
53 static iser::CArchiveTag outerListTag("Data", "DataDesc", iser::CArchiveTag::TT_MULTIPLE);
54 static iser::CArchiveTag innerListTag("Element", "ElementDesc1", iser::CArchiveTag::TT_MULTIPLE, &outerListTag);
55 static iser::CArchiveTag elementTag("Element1", "ElementDesc2", iser::CArchiveTag::TT_LEAF, &innerListTag);
56
57 bool retVal = true;
58
59 int outerCount = m_data.size();
60 retVal = retVal && archive.BeginMultiTag(outerListTag, innerListTag, outerCount);
61 if (!archive.IsStoring()) {
62 m_data.resize(outerCount);
63 }
64
65 for (qsizetype i = 0; i < m_data.size(); ++i) {
66 int innerCount = m_data[i].size();
67 retVal = retVal && archive.BeginMultiTag(innerListTag, elementTag, innerCount);
68 if (!archive.IsStoring()) {
69 m_data[i].resize(innerCount);
70 }
71
72 for (qsizetype j = 0; j < m_data[i].size(); ++j) {
73 retVal = retVal && archive.BeginTag(elementTag);
74 retVal = retVal && archive.Process(m_data[i][j]);
75 retVal = retVal && archive.EndTag(elementTag);
76 }
77
78 retVal = retVal && archive.EndTag(innerListTag);
79 }
80
81 retVal = retVal && archive.EndTag(outerListTag);
82
83 return retVal;
84 }
85
86 bool operator==(const NestedArray& other) const
87 {
88 return m_data == other.m_data;
89 }
90
91 private:
92 QList<QList<double>> m_data;
93 };
94
95};
96
97
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
@ TT_LEAF
Leaf tag, it can contain only one primitive element.
Definition CArchiveTag.h:48
@ TT_MULTIPLE
Multiple tag containing variable number of child tags.
Definition CArchiveTag.h:42
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 BeginMultiTag(const CArchiveTag &tag, const CArchiveTag &subTag, int &count)=0
Begins a tagged section containing multiple elements of the same type.
virtual bool IsStoring() const =0
Checks if this archive is in storing (writing) or loading (reading) mode.
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.