1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS api tests
3c2c66affSColin Finck * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4c2c66affSColin Finck * PURPOSE: Test for CSimpleMap
5c2c66affSColin Finck * PROGRAMMER: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6c2c66affSColin Finck */
7c2c66affSColin Finck
8c714b7fdSKatayama Hirofumi MZ #ifdef HAVE_APITEST
9c2c66affSColin Finck #include <apitest.h>
10c2c66affSColin Finck #else
11a800fa7bSKatayama Hirofumi MZ #include "atltest.h"
12c2c66affSColin Finck #endif
13c2c66affSColin Finck
14c2c66affSColin Finck #include <atlbase.h>
15c2c66affSColin Finck #include <atlsimpcoll.h>
16c2c66affSColin Finck
17c2c66affSColin Finck struct CMonster
18c2c66affSColin Finck {
19c2c66affSColin Finck static int s_nCount;
20c2c66affSColin Finck static int s_nCopyCount;
21c2c66affSColin Finck
CMonsterCMonster22c2c66affSColin Finck CMonster()
23c2c66affSColin Finck {
24c2c66affSColin Finck CMonster::s_nCount++;
25c2c66affSColin Finck }
CMonsterCMonster26c2c66affSColin Finck CMonster(const CMonster& c)
27c2c66affSColin Finck {
28c2c66affSColin Finck CMonster::s_nCount++;
29c2c66affSColin Finck }
~CMonsterCMonster30c2c66affSColin Finck ~CMonster()
31c2c66affSColin Finck {
32c2c66affSColin Finck CMonster::s_nCount--;
33c2c66affSColin Finck }
operator =CMonster34c2c66affSColin Finck CMonster& operator=(const CMonster& other)
35c2c66affSColin Finck {
36c2c66affSColin Finck CMonster::s_nCopyCount++;
37c2c66affSColin Finck return *this;
38c2c66affSColin Finck }
39c2c66affSColin Finck };
40c2c66affSColin Finck
41c2c66affSColin Finck int CMonster::s_nCount = 0;
42c2c66affSColin Finck int CMonster::s_nCopyCount = 0;
43c2c66affSColin Finck
START_TEST(CSimpleMap)44c2c66affSColin Finck START_TEST(CSimpleMap)
45c2c66affSColin Finck {
46c2c66affSColin Finck CSimpleMap<int, int> map1;
47c2c66affSColin Finck
48*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 0);
49c2c66affSColin Finck
50c2c66affSColin Finck map1.Add(1, 2);
51*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 1);
52c2c66affSColin Finck map1.Add(2, 3);
53*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 2);
54c2c66affSColin Finck
55*14c267a3SKatayama Hirofumi MZ ok_int(map1.Lookup(1), 2);
56*14c267a3SKatayama Hirofumi MZ ok_int(map1.Lookup(2), 3);
57*14c267a3SKatayama Hirofumi MZ ok_int(map1.Lookup(-1), 0);
58c2c66affSColin Finck
59*14c267a3SKatayama Hirofumi MZ ok_int(map1.ReverseLookup(2), 1);
60*14c267a3SKatayama Hirofumi MZ ok_int(map1.ReverseLookup(3), 2);
61c2c66affSColin Finck
62*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetKeyAt(0), 1);
63*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetKeyAt(1), 2);
64c2c66affSColin Finck
65*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetValueAt(0), 2);
66*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetValueAt(1), 3);
67c2c66affSColin Finck
68c2c66affSColin Finck map1.SetAt(2, 4);
69c2c66affSColin Finck
70*14c267a3SKatayama Hirofumi MZ ok_int(map1.Lookup(1), 2);
71*14c267a3SKatayama Hirofumi MZ ok_int(map1.Lookup(2), 4);
72c2c66affSColin Finck
73*14c267a3SKatayama Hirofumi MZ ok_int(map1.ReverseLookup(2), 1);
74*14c267a3SKatayama Hirofumi MZ ok_int(map1.ReverseLookup(4), 2);
75c2c66affSColin Finck
76c2c66affSColin Finck map1.Remove(1);
77*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 1);
78c2c66affSColin Finck map1.Remove(2);
79*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 0);
80c2c66affSColin Finck
81c2c66affSColin Finck map1.Add(1, 4);
82*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 1);
83c2c66affSColin Finck map1.Add(2, 8);
84*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 2);
85c2c66affSColin Finck map1.Add(3, 12);
86*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 3);
87c2c66affSColin Finck
88c2c66affSColin Finck map1.RemoveAll();
89*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 0);
90c2c66affSColin Finck
91*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 0);
92*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
93c2c66affSColin Finck
94c2c66affSColin Finck CSimpleMap<CMonster, CMonster> map2;
95*14c267a3SKatayama Hirofumi MZ ok_int(map2.GetSize(), 0);
96c2c66affSColin Finck
97*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 0);
98*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
99c2c66affSColin Finck
100c2c66affSColin Finck {
101c2c66affSColin Finck CMonster m1;
102*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 1);
103*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
104c2c66affSColin Finck
105c2c66affSColin Finck CMonster m2;
106*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 2);
107*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
108c2c66affSColin Finck
109c2c66affSColin Finck map2.Add(m1, m2);
110*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 4);
111*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
112c2c66affSColin Finck }
113c2c66affSColin Finck
114*14c267a3SKatayama Hirofumi MZ ok_int(map2.GetSize(), 1);
115*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 2);
116*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
117c2c66affSColin Finck
118c2c66affSColin Finck {
119c2c66affSColin Finck CMonster m1;
120*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 3);
121*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
122c2c66affSColin Finck
123c2c66affSColin Finck CMonster m2;
124*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 4);
125*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
126c2c66affSColin Finck
127c2c66affSColin Finck map2.Add(m1, m2);
128*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 6);
129*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
130c2c66affSColin Finck }
131c2c66affSColin Finck
132*14c267a3SKatayama Hirofumi MZ ok_int(map2.GetSize(), 2);
133*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 4);
134*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
135c2c66affSColin Finck
136c2c66affSColin Finck map2.RemoveAt(0);
137*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 2);
138*14c267a3SKatayama Hirofumi MZ ok_int(map2.GetSize(), 1);
139*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
140c2c66affSColin Finck
141c2c66affSColin Finck map2.RemoveAt(0);
142*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 0);
143*14c267a3SKatayama Hirofumi MZ ok_int(map2.GetSize(), 0);
144*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCopyCount, 0);
145c2c66affSColin Finck
146c2c66affSColin Finck CSimpleMap<int, CMonster> map3;
147*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 0);
148c2c66affSColin Finck
149c2c66affSColin Finck CMonster m3;
150*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 1);
151c2c66affSColin Finck
152c2c66affSColin Finck map3.Add(1, m3);
153*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 1);
154*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 2);
155c2c66affSColin Finck
156c2c66affSColin Finck map3.Add(2, m3);
157*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 2);
158*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 3);
159c2c66affSColin Finck
160c2c66affSColin Finck map3.Add(3, m3);
161*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 3);
162*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 4);
163c2c66affSColin Finck
164c2c66affSColin Finck map3.Remove(2);
165*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 2);
166*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 3);
167c2c66affSColin Finck
168c2c66affSColin Finck map3.RemoveAll();
169*14c267a3SKatayama Hirofumi MZ ok_int(map3.GetSize(), 0);
170*14c267a3SKatayama Hirofumi MZ ok_int(CMonster::s_nCount, 1);
171c2c66affSColin Finck
172c2c66affSColin Finck map1.Add(1, 2);
173*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 1);
174c2c66affSColin Finck map1.Add(2, 3);
175*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 2);
176c2c66affSColin Finck
177c2c66affSColin Finck ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
178*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 1);
179c2c66affSColin Finck ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
180*14c267a3SKatayama Hirofumi MZ ok_int(map1.GetSize(), 0);
181c2c66affSColin Finck }
182