ACF $AcfVersion:0$
CModelUpdateBridgeTest.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 <imod/TModelWrap.h>
12#include <iser/CSerializableBase.h>
13
14
23class CModelUpdateBridgeTest: public QObject
24{
25 Q_OBJECT
26
27private slots:
28 void initTestCase();
29 void cleanupTestCase();
30
31 // Basic functionality tests
32 void testBridgeCreation();
33 void testAttachModelToBridge();
34 void testDetachModelFromBridge();
35 void testEnsureModelsDetached();
36 void testGetModelCount();
37 void testGetObservedModel();
38
39 // Update delegation tests
40 void testDelegatedUpdateFlag();
41 void testSourceUpdateFlag();
42 void testMultipleModelsUpdate();
43
44 // Edge cases
45 void testBridgeWithNullChangeable();
46 void testMultipleAttachDetachCycles();
47
48private:
49 // Helper class: Simple data model for testing
50 class TestDataModel: public iser::CSerializableBase
51 {
52 public:
53 enum ChangeFlags
54 {
55 CF_DATA_CHANGED = 0x1,
56 CF_STATUS_CHANGED = 0x2
57 };
58
59 TestDataModel() : m_data(0), m_status(0) {}
60
61 void SetData(int data)
62 {
63 if (m_data != data)
64 {
66 changeSet.Set(CF_DATA_CHANGED);
67 BeginChanges(changeSet);
68 m_data = data;
69 EndChanges(changeSet);
70 }
71 }
72
73 int GetData() const { return m_data; }
74
75 void SetStatus(int status)
76 {
77 if (m_status != status)
78 {
80 changeSet.Set(CF_STATUS_CHANGED);
81 BeginChanges(changeSet);
82 m_status = status;
83 EndChanges(changeSet);
84 }
85 }
86
87 int GetStatus() const { return m_status; }
88
89 // IChangeable interface
90 virtual int GetSupportedOperations() const override
91 {
93 }
94
97 {
98 TestDataModel* clone = new TestDataModel();
99 clone->m_data = m_data;
100 clone->m_status = m_status;
102 }
103
104 virtual bool CopyFrom(const istd::IChangeable& object,
106 {
107 const TestDataModel* other = dynamic_cast<const TestDataModel*>(&object);
108 if (other)
109 {
110 m_data = other->m_data;
111 m_status = other->m_status;
112 return true;
113 }
114 return false;
115 }
116
118 {
119 m_data = 0;
120 m_status = 0;
121 return true;
122 }
123
124 virtual bool Serialize(iser::IArchive& archive) override
125 {
126 archive.SerializeValue("data", m_data);
127 archive.SerializeValue("status", m_status);
128 return true;
129 }
130
131 private:
132 int m_data;
133 int m_status;
134 };
135
136 // Helper class: Target object that receives bridged changes
137 class TargetChangeable: public iser::CSerializableBase
138 {
139 public:
140 TargetChangeable() : m_changeCount(0) {}
141
142 int GetChangeCount() const { return m_changeCount; }
143 const istd::IChangeable::ChangeSet& GetLastChangeSet() const { return m_lastChangeSet; }
144
145 void Reset()
146 {
147 m_changeCount = 0;
148 m_lastChangeSet.Clear();
149 }
150
151 // Override BeginChanges to track notifications
152 virtual void BeginChanges(const istd::IChangeable::ChangeSet& changeSet) override
153 {
154 CSerializableBase::BeginChanges(changeSet);
155 m_changeCount++;
156 m_lastChangeSet = changeSet;
157 }
158
159 // IChangeable interface
160 virtual int GetSupportedOperations() const override
161 {
163 }
164
167 {
168 return istd::TUniqueInterfacePtr<istd::IChangeable>(new TargetChangeable());
169 }
170
171 virtual bool CopyFrom(const istd::IChangeable& object,
173 {
174 return true;
175 }
176
178 {
179 return true;
180 }
181
182 virtual bool Serialize(iser::IArchive& archive) override
183 {
184 return true;
185 }
186
187 private:
188 int m_changeCount;
189 istd::IChangeable::ChangeSet m_lastChangeSet;
190 };
191
193
194 TargetChangeable* m_targetChangeable;
195 imod::CModelUpdateBridge* m_bridge;
196 TestModel* m_model1;
197 TestModel* m_model2;
198};
Test class for CModelUpdateBridge functionality.
Reflects the changes of observed objects as changes of some other object (over istd::IChangeable),...
This model wrapper provides a simple connection between a concrete istd::IChangeable implementation a...
Definition TModelWrap.h:24
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Set of change flags (its IDs).
Definition IChangeable.h:36
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
@ SO_COPY
Copying from other object.
@ SO_RESET
Resetting of object state.
@ SO_CLONE
Creating of copy of this object.
Unique ownership smart pointer for interface types.