1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing (testing the Notify subsystem)
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "datamodel/dmehandle.h"
#include "tier2/tier2.h"
class CNotifyTest : public IDmNotify
{
public:
CNotifyTest() : m_nValueCount(0), m_nTopologyCount(0), m_nArrayCount(0) {}
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
if ( nNotifyFlags & NOTIFY_CHANGE_ATTRIBUTE_VALUE )
{
m_nValueCount++;
}
if ( nNotifyFlags & NOTIFY_CHANGE_ATTRIBUTE_ARRAY_SIZE )
{
m_nArrayCount++;
}
if ( nNotifyFlags & NOTIFY_CHANGE_TOPOLOGICAL )
{
m_nTopologyCount++;
}
}
int m_nTopologyCount;
int m_nArrayCount;
int m_nValueCount;
};
DEFINE_TESTCASE_NOSUITE( DmxNotifyTest )
{
Msg( "Running dmx notify tests...\n" );
CNotifyTest test1, test2;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<RunNotifyTests>" );
g_pDataModel->InstallNotificationCallback( &test1 );
CDmElement *element = NULL;
{
CUndoScopeGuard guard( NOTIFY_SOURCE_APPLICATION, 0, "create" );
element = CreateElement< CDmElement >( "test", fileid );
}
Shipping_Assert( test1.m_nTopologyCount == 1 );
Shipping_Assert( test1.m_nArrayCount == 0 );
g_pDataModel->Undo();
Shipping_Assert( test1.m_nTopologyCount == 2 );
Shipping_Assert( test1.m_nArrayCount == 0 );
{
CNotifyScopeGuard notify( "test1", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
CDisableUndoScopeGuard guard;
element = CreateElement< CDmElement >( "test", fileid );
}
Shipping_Assert( test1.m_nTopologyCount == 3 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 1 );
Shipping_Assert( test2.m_nArrayCount == 0 );
{
CDisableUndoScopeGuard guard;
// NOTE: Nested scope guards referring to the same callback shouldn't double call it
CNotifyScopeGuard notify( "test2", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
{
CNotifyScopeGuard notify( "test3", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
DestroyElement( element );
}
}
Shipping_Assert( test1.m_nTopologyCount == 4 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 2 );
Shipping_Assert( test2.m_nArrayCount == 0 );
{
CUndoScopeGuard guard( NOTIFY_SOURCE_APPLICATION, 0, "create" );
{
element = CreateElement< CDmElement >( "test", fileid );
element->SetValue( "test", 1.0f );
}
guard.Abort();
}
Shipping_Assert( test1.m_nTopologyCount == 4 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 2 );
Shipping_Assert( test2.m_nArrayCount == 0 );
g_pDataModel->RemoveNotificationCallback( &test1 );
g_pDataModel->RemoveFileId( fileid );
}
|