6#include <QtCore/QObject>
7#include <QtTest/QtTest>
12#include <iser/CSerializableBase.h>
30 void cleanupTestCase();
33 void testAttachObserver();
34 void testDetachObserver();
35 void testDetachAllObservers();
36 void testIsAttached();
37 void testGetObserverCount();
38 void testGetObservers();
41 void testNotifyBeforeChange();
42 void testNotifyAfterChange();
43 void testChangeSetAccumulation();
44 void testMultipleObserversNotification();
47 void testAttachSameObserverTwice();
48 void testDetachUnattachedObserver();
49 void testNotifyWithNoObservers();
58 CF_VALUE_CHANGED = 0x1,
59 CF_NAME_CHANGED = 0x2,
60 CF_STATUS_CHANGED = 0x4
63 TestModel() : m_value(0) {}
65 void SetValue(
int value)
70 changeSet.Set(CF_VALUE_CHANGED);
77 int GetValue()
const {
return m_value; }
79 void SetName(
const QString& name)
84 changeSet.Set(CF_NAME_CHANGED);
91 QString GetName()
const {
return m_name; }
93 void BeginGroupChanges()
96 changeSet.Set(CF_VALUE_CHANGED);
97 changeSet.Set(CF_NAME_CHANGED);
101 void EndGroupChanges()
108 virtual void OnBeginGlobalChanges()
override {}
112 virtual int GetSupportedOperations()
const override
120 TestModel* clone =
new TestModel();
121 clone->m_value = m_value;
122 clone->m_name = m_name;
129 const TestModel* other =
dynamic_cast<const TestModel*
>(&object);
132 m_value = other->m_value;
133 m_name = other->m_name;
148 archive.SerializeValue(
"value", m_value);
149 archive.SerializeValue(
"name", m_name);
162 TestObserver() : m_beforeUpdateCount(0), m_afterUpdateCount(0) {}
164 int GetBeforeUpdateCount()
const {
return m_beforeUpdateCount; }
165 int GetAfterUpdateCount()
const {
return m_afterUpdateCount; }
170 m_beforeUpdateCount = 0;
171 m_afterUpdateCount = 0;
172 m_lastChangeSet.Clear();
176 virtual void BeforeUpdate(
imod::IModel* modelPtr)
override
178 CSingleModelObserverBase::BeforeUpdate(modelPtr);
179 m_beforeUpdateCount++;
184 m_afterUpdateCount++;
185 m_lastChangeSet = changeSet;
189 int m_beforeUpdateCount;
190 int m_afterUpdateCount;
195 TestObserver* m_observer;
Test class for CModelBase functionality.
Basic implementation of a model.
istd::IChangeable::ChangeSet GetCumulatedChanges() const
void NotifyBeforeChange(const istd::IChangeable::ChangeSet &changeSet, bool isGroup)
Called before each change.
void NotifyAfterChange(const istd::IChangeable::ChangeSet &changeSet)
Called after each change.
Basic implementation for a single model observer.
Common interface for model objects, that supports Model/Observer design pattern.
Represents an input/output persistence archive for object serialization.
Set of change flags (its IDs).
Common interface for data model objects, which can be changed.
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.