ReactOS 0.4.15-dev-7907-g95bf896
CSimpleMap.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for CSimpleMap
5 * PROGRAMMER: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#ifdef HAVE_APITEST
9 #include <apitest.h>
10#else
11 #include "atltest.h"
12#endif
13
14#include <atlbase.h>
15#include <atlsimpcoll.h>
16
18{
19 static int s_nCount;
20 static int s_nCopyCount;
21
23 {
25 }
27 {
29 }
31 {
33 }
35 {
37 return *this;
38 }
39};
40
41int CMonster::s_nCount = 0;
43
44START_TEST(CSimpleMap)
45{
46 CSimpleMap<int, int> map1;
47
48 ok_int(map1.GetSize(), 0);
49
50 map1.Add(1, 2);
51 ok_int(map1.GetSize(), 1);
52 map1.Add(2, 3);
53 ok_int(map1.GetSize(), 2);
54
55 ok_int(map1.Lookup(1), 2);
56 ok_int(map1.Lookup(2), 3);
57 ok_int(map1.Lookup(-1), 0);
58
59 ok_int(map1.ReverseLookup(2), 1);
60 ok_int(map1.ReverseLookup(3), 2);
61
62 ok_int(map1.GetKeyAt(0), 1);
63 ok_int(map1.GetKeyAt(1), 2);
64
65 ok_int(map1.GetValueAt(0), 2);
66 ok_int(map1.GetValueAt(1), 3);
67
68 map1.SetAt(2, 4);
69
70 ok_int(map1.Lookup(1), 2);
71 ok_int(map1.Lookup(2), 4);
72
73 ok_int(map1.ReverseLookup(2), 1);
74 ok_int(map1.ReverseLookup(4), 2);
75
76 map1.Remove(1);
77 ok_int(map1.GetSize(), 1);
78 map1.Remove(2);
79 ok_int(map1.GetSize(), 0);
80
81 map1.Add(1, 4);
82 ok_int(map1.GetSize(), 1);
83 map1.Add(2, 8);
84 ok_int(map1.GetSize(), 2);
85 map1.Add(3, 12);
86 ok_int(map1.GetSize(), 3);
87
88 map1.RemoveAll();
89 ok_int(map1.GetSize(), 0);
90
93
94 CSimpleMap<CMonster, CMonster> map2;
95 ok_int(map2.GetSize(), 0);
96
99
100 {
101 CMonster m1;
104
105 CMonster m2;
108
109 map2.Add(m1, m2);
112 }
113
114 ok_int(map2.GetSize(), 1);
117
118 {
119 CMonster m1;
122
123 CMonster m2;
126
127 map2.Add(m1, m2);
130 }
131
132 ok_int(map2.GetSize(), 2);
135
136 map2.RemoveAt(0);
138 ok_int(map2.GetSize(), 1);
140
141 map2.RemoveAt(0);
143 ok_int(map2.GetSize(), 0);
145
146 CSimpleMap<int, CMonster> map3;
147 ok_int(map3.GetSize(), 0);
148
149 CMonster m3;
151
152 map3.Add(1, m3);
153 ok_int(map3.GetSize(), 1);
155
156 map3.Add(2, m3);
157 ok_int(map3.GetSize(), 2);
159
160 map3.Add(3, m3);
161 ok_int(map3.GetSize(), 3);
163
164 map3.Remove(2);
165 ok_int(map3.GetSize(), 2);
167
168 map3.RemoveAll();
169 ok_int(map3.GetSize(), 0);
171
172 map1.Add(1, 2);
173 ok_int(map1.GetSize(), 1);
174 map1.Add(2, 3);
175 ok_int(map1.GetSize(), 2);
176
177 ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
178 ok_int(map1.GetSize(), 1);
179 ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
180 ok_int(map1.GetSize(), 0);
181}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
const GLubyte * c
Definition: glext.h:8905
int other
Definition: msacm.c:1376
static int s_nCopyCount
Definition: CSimpleMap.cpp:20
CMonster & operator=(const CMonster &other)
Definition: CSimpleMap.cpp:34
CMonster(const CMonster &c)
Definition: CSimpleMap.cpp:26
static int s_nCount
Definition: CSimpleMap.cpp:19