mirror of
https://github.com/reactos/reactos.git
synced 2024-08-08 04:08:29 +00:00
![Katayama Hirofumi MZ](/assets/img/avatar_default.png)
- Add "atltest.h" header file for common use in atl_apitest. - Delete the duplicated and simplify.
182 lines
7.9 KiB
C++
182 lines
7.9 KiB
C++
/*
|
|
* PROJECT: ReactOS api tests
|
|
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
|
|
* PURPOSE: Test for CSimpleMap
|
|
* PROGRAMMER: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
|
*/
|
|
|
|
#ifdef HAVE_APITEST
|
|
#include <apitest.h>
|
|
#else
|
|
#include "atltest.h"
|
|
#endif
|
|
|
|
#include <atlbase.h>
|
|
#include <atlsimpcoll.h>
|
|
|
|
struct CMonster
|
|
{
|
|
static int s_nCount;
|
|
static int s_nCopyCount;
|
|
|
|
CMonster()
|
|
{
|
|
CMonster::s_nCount++;
|
|
}
|
|
CMonster(const CMonster& c)
|
|
{
|
|
CMonster::s_nCount++;
|
|
}
|
|
~CMonster()
|
|
{
|
|
CMonster::s_nCount--;
|
|
}
|
|
CMonster& operator=(const CMonster& other)
|
|
{
|
|
CMonster::s_nCopyCount++;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
int CMonster::s_nCount = 0;
|
|
int CMonster::s_nCopyCount = 0;
|
|
|
|
START_TEST(CSimpleMap)
|
|
{
|
|
CSimpleMap<int, int> map1;
|
|
|
|
ok(map1.GetSize() == 0, "Expected map1's size is zero, was %d\n", map1.GetSize());
|
|
|
|
map1.Add(1, 2);
|
|
ok(map1.GetSize() == 1, "Expected map1's size is 1, was %d\n", map1.GetSize());
|
|
map1.Add(2, 3);
|
|
ok(map1.GetSize() == 2, "Expected map1's size is 2, was %d\n", map1.GetSize());
|
|
|
|
ok(map1.Lookup(1) == 2, "Expected map1.Lookup(1) is 2, was %d\n", map1.Lookup(1));
|
|
ok(map1.Lookup(2) == 3, "Expected map1.Lookup(2) is 3, was %d\n", map1.Lookup(2));
|
|
ok(map1.Lookup(-1) == 0, "Expected map1.Lookup(-1) is 0, was %d\n", map1.Lookup(-1));
|
|
|
|
ok(map1.ReverseLookup(2) == 1, "Expected map1.ReverseLookup(2) is 1, was %d\n", map1.ReverseLookup(2));
|
|
ok(map1.ReverseLookup(3) == 2, "Expected map1.ReverseLookup(3) is 2, was %d\n", map1.ReverseLookup(3));
|
|
|
|
ok(map1.GetKeyAt(0) == 1, "Expected map1.GetKeyAt(0) is 1, was %d\n", map1.GetKeyAt(0));
|
|
ok(map1.GetKeyAt(1) == 2, "Expected map1.GetKeyAt(1) is 2, was %d\n", map1.GetKeyAt(1));
|
|
|
|
ok(map1.GetValueAt(0) == 2, "Expected map1.GetValueAt(0) is 2, was %d\n", map1.GetValueAt(0));
|
|
ok(map1.GetValueAt(1) == 3, "Expected map1.GetValueAt(1) is 3, was %d\n", map1.GetValueAt(1));
|
|
|
|
map1.SetAt(2, 4);
|
|
|
|
ok(map1.Lookup(1) == 2, "Expected map1.Lookup(1) is 2, was %d\n", map1.Lookup(1));
|
|
ok(map1.Lookup(2) == 4, "Expected map1.Lookup(2) is 4, was %d\n", map1.Lookup(2));
|
|
|
|
ok(map1.ReverseLookup(2) == 1, "Expected map1.ReverseLookup(2) is 1, was %d\n", map1.ReverseLookup(2));
|
|
ok(map1.ReverseLookup(4) == 2, "Expected map1.ReverseLookup(4) is 2, was %d\n", map1.ReverseLookup(4));
|
|
|
|
map1.Remove(1);
|
|
ok(map1.GetSize() == 1, "Expected map1's size is 1, was %d\n", map1.GetSize());
|
|
map1.Remove(2);
|
|
ok(map1.GetSize() == 0, "Expected map1's size is 0, was %d\n", map1.GetSize());
|
|
|
|
map1.Add(1, 4);
|
|
ok(map1.GetSize() == 1, "Expected map1's size is 1, was %d\n", map1.GetSize());
|
|
map1.Add(2, 8);
|
|
ok(map1.GetSize() == 2, "Expected map1's size is 2, was %d\n", map1.GetSize());
|
|
map1.Add(3, 12);
|
|
ok(map1.GetSize() == 3, "Expected map1's size is 3, was %d\n", map1.GetSize());
|
|
|
|
map1.RemoveAll();
|
|
ok(map1.GetSize() == 0, "Expected map1's size is 0, was %d\n", map1.GetSize());
|
|
|
|
ok(CMonster::s_nCount == 0, "Expected CMonster::s_nCount is 0, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
CSimpleMap<CMonster, CMonster> map2;
|
|
ok(map2.GetSize() == 0, "Expected map2's size is zero, was %d\n", map2.GetSize());
|
|
|
|
ok(CMonster::s_nCount == 0, "Expected CMonster::s_nCount is 0, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
{
|
|
CMonster m1;
|
|
ok(CMonster::s_nCount == 1, "Expected CMonster::s_nCount is 1, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
CMonster m2;
|
|
ok(CMonster::s_nCount == 2, "Expected CMonster::s_nCount is 2, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
map2.Add(m1, m2);
|
|
ok(CMonster::s_nCount == 4, "Expected CMonster::s_nCount is 4, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
}
|
|
|
|
ok(map2.GetSize() == 1, "Expected map2's size is 1, was %d\n", map2.GetSize());
|
|
ok(CMonster::s_nCount == 2, "Expected CMonster::s_nCount is 2, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
{
|
|
CMonster m1;
|
|
ok(CMonster::s_nCount == 3, "Expected CMonster::s_nCount is 3, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
CMonster m2;
|
|
ok(CMonster::s_nCount == 4, "Expected CMonster::s_nCount is 4, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
map2.Add(m1, m2);
|
|
ok(CMonster::s_nCount == 6, "Expected CMonster::s_nCount is 6, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
}
|
|
|
|
ok(map2.GetSize() == 2, "Expected map2's size is 2, was %d\n", map2.GetSize());
|
|
ok(CMonster::s_nCount == 4, "Expected CMonster::s_nCount is 4, was %d\n", CMonster::s_nCount);
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
map2.RemoveAt(0);
|
|
ok(CMonster::s_nCount == 2, "Expected CMonster::s_nCount is 2, was %d\n", CMonster::s_nCount);
|
|
ok(map2.GetSize() == 1, "Expected map2's size is 1, was %d\n", map2.GetSize());
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
map2.RemoveAt(0);
|
|
ok(CMonster::s_nCount == 0, "Expected CMonster::s_nCount is 0, was %d\n", CMonster::s_nCount);
|
|
ok(map2.GetSize() == 0, "Expected map2's size is 0, was %d\n", map2.GetSize());
|
|
ok(CMonster::s_nCopyCount == 0, "Expected CMonster::s_nCopyCount is 0, was %d\n", CMonster::s_nCopyCount);
|
|
|
|
CSimpleMap<int, CMonster> map3;
|
|
ok(map3.GetSize() == 0, "Expected map3's size is 0, was %d\n", map3.GetSize());
|
|
|
|
CMonster m3;
|
|
ok(CMonster::s_nCount == 1, "Expected CMonster::s_nCount is 1, was %d\n", CMonster::s_nCount);
|
|
|
|
map3.Add(1, m3);
|
|
ok(map3.GetSize() == 1, "Expected map3's size is 1, was %d\n", map3.GetSize());
|
|
ok(CMonster::s_nCount == 2, "Expected CMonster::s_nCount is 2, was %d\n", CMonster::s_nCount);
|
|
|
|
map3.Add(2, m3);
|
|
ok(map3.GetSize() == 2, "Expected map3's size is 2, was %d\n", map3.GetSize());
|
|
ok(CMonster::s_nCount == 3, "Expected CMonster::s_nCount is 3, was %d\n", CMonster::s_nCount);
|
|
|
|
map3.Add(3, m3);
|
|
ok(map3.GetSize() == 3, "Expected map3's size is 3, was %d\n", map3.GetSize());
|
|
ok(CMonster::s_nCount == 4, "Expected CMonster::s_nCount is 4, was %d\n", CMonster::s_nCount);
|
|
|
|
map3.Remove(2);
|
|
ok(map3.GetSize() == 2, "Expected map3's size is 2, was %d\n", map3.GetSize());
|
|
ok(CMonster::s_nCount == 3, "Expected CMonster::s_nCount is 3, was %d\n", CMonster::s_nCount);
|
|
|
|
map3.RemoveAll();
|
|
ok(map3.GetSize() == 0, "Expected map3's size is 0, was %d\n", map3.GetSize());
|
|
ok(CMonster::s_nCount == 1, "Expected CMonster::s_nCount is 1, was %d\n", CMonster::s_nCount);
|
|
|
|
map1.Add(1, 2);
|
|
ok(map1.GetSize() == 1, "Expected map1's size is 1, was %d\n", map1.GetSize());
|
|
map1.Add(2, 3);
|
|
ok(map1.GetSize() == 2, "Expected map1's size is 2, was %d\n", map1.GetSize());
|
|
|
|
ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
|
|
ok(map1.GetSize() == 1, "Expected map1's size is 1, was %d\n", map1.GetSize());
|
|
ok(!!map1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n");
|
|
ok(map1.GetSize() == 0, "Expected map1's size is 0, was %d\n", map1.GetSize());
|
|
}
|