1 krisbash 1.1 #include <vector>
2 #include <cassert>
3 #include "ABC_Widget.h"
4 #include "ABC_Gadget.h"
5 #include "ABC_Connector.h"
6 #include <ut/ut.h>
7
8 using namespace std;
9 using namespace mi;
10
11 #if 0
12 static void Dump(const vector<ABC_Connector_Class>& v)
13 {
14 for (size_t i = 0; i < v.size(); i++)
15 {
16 v[0].Print();
17 }
18 }
19 #endif
20
21 NitsSetup(MapOfInstancesSetup)
22 krisbash 1.1 NitsEndSetup
23
24 NitsCleanup(MapOfInstancesSetup)
25 NitsEndCleanup
26
27 NitsTestWithSetup(Test1, MapOfInstancesSetup)
28 {
29 vector<ABC_Connector_Class> v;
30
31 // Insert a connector into the STL vector:
32 {
33 ABC_Widget_Class w;
34 w.Key_value(MI_T("1000"));
35 w.Color_value(MI_T("Red"));
36
37 ABC_Gadget_Class g;
38 g.Key_value(MI_T("1000"));
39 g.Color_value(MI_T("Blue"));
40
41 ABC_Connector_Class c;
42 w.__setCopyOnWrite(false);
43 krisbash 1.1 assert(w.__getCopyOnWrite() == false);
44 c.Left_value(w);
45 g.__setCopyOnWrite(false);
46 assert(g.__getCopyOnWrite() == false);
47 c.Right_value(g);
48
49 v.push_back(c);
50 }
51
52 // Update v[0]:
53 ABC_Connector_Class c = v[0];
54
55 ABC_Widget_Class w = c.Left_value();
56 w.Color_value(MI_T("Pink"));
57
58 ABC_Gadget_Class g = c.Right_value();
59 g.Color_value(MI_T("Cyan"));
60
61 // Dump the vector:
62 UT_ASSERT(v[0].Left_value().Color_value() == MI_T("Pink"));
63 UT_ASSERT(v[0].Right_value().Color_value() == MI_T("Cyan"));
64 krisbash 1.1
65 // Test __forceCopyOnWrite()
66 {
67 ABC_Widget_Class w1;
68 w1.Key_value(MI_T("1000"));
69 w1.Color_value(MI_T("Red"));
70 w1.__setCopyOnWrite(false);
71
72
73 ABC_Widget_Class w2 = w1;
74 w2.__forceCopyOnWrite();
75 w2.Color_value(MI_T("Pink"));
76 #if 0
77 w1.Print();
78 w2.Print();
79 #endif
80
81 UT_ASSERT(w1.Color_value() == MI_T("Red"));
82 UT_ASSERT(w2.Color_value() == MI_T("Pink"));
83 }
84 }
85 krisbash 1.1 NitsEndTest
|