From 639a2c725d7b3317fdbad27bc6a7eb5f28e423a8 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Thu, 15 Sep 2016 19:41:03 +0000 Subject: [PATCH] [ATL][ATL_APITEST] Implemente CSimpleArray + CSimpleMap. Based on a patch from Katayama Hirofumi MZ. CORE-11946 Most of the code is from Katayama Hirofumi MZ, the placement new / delete is written by me, based on a hint from Giannis. svn path=/trunk/; revision=72688 --- reactos/sdk/lib/atl/atlsimpcoll.h | 453 ++++++++++++++++++ rostests/apitests/atl/CMakeLists.txt | 2 + rostests/apitests/atl/CSimpleArray.cpp | 186 +++++++ rostests/apitests/atl/CSimpleMap.cpp | 206 ++++++++ rostests/apitests/atl/devenv/ATLTest.sln | 48 ++ rostests/apitests/atl/devenv/CImage.sln | 28 -- rostests/apitests/atl/devenv/CImage.vcxproj | 6 +- .../apitests/atl/devenv/CSimpleArray.vcxproj | 180 +++++++ .../apitests/atl/devenv/CSimpleMap.vcxproj | 180 +++++++ rostests/apitests/atl/testlist.c | 4 + 10 files changed, 1262 insertions(+), 31 deletions(-) create mode 100644 reactos/sdk/lib/atl/atlsimpcoll.h create mode 100644 rostests/apitests/atl/CSimpleArray.cpp create mode 100644 rostests/apitests/atl/CSimpleMap.cpp create mode 100644 rostests/apitests/atl/devenv/ATLTest.sln delete mode 100644 rostests/apitests/atl/devenv/CImage.sln create mode 100644 rostests/apitests/atl/devenv/CSimpleArray.vcxproj create mode 100644 rostests/apitests/atl/devenv/CSimpleMap.vcxproj diff --git a/reactos/sdk/lib/atl/atlsimpcoll.h b/reactos/sdk/lib/atl/atlsimpcoll.h new file mode 100644 index 00000000000..9564e53b991 --- /dev/null +++ b/reactos/sdk/lib/atl/atlsimpcoll.h @@ -0,0 +1,453 @@ +// PROJECT: ReactOS ATL Simple Collection +// LICENSE: Public Domain +// PURPOSE: Provides compatibility to Microsoft ATL +// PROGRAMMERS: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) + +#ifndef __ATLSIMPCOLL_H__ +#define __ATLSIMPCOLL_H__ + +#pragma once + +#include "atlcore.h" // for ATL Core + +namespace ATL +{ +template +class CSimpleArrayEqualHelper +{ +public: + static bool IsEqual(const T& t1, const T& t2) + { + return t1 == t2; + } +}; + +// This class exists for the element types of no comparison. +template +class CSimpleArrayEqualHelperFalse +{ +public: + static bool IsEqual(const T&, const T&) + { + ATLASSERT(FALSE); + return false; + } +}; + +template > +class CSimpleArray +{ +public: + typedef T _ArrayElementType; + + CSimpleArray() : m_pData(NULL), m_nCount(0), m_nCapacity(0) + { + } + + CSimpleArray(const CSimpleArray& src) : + m_pData(NULL), m_nCount(0), m_nCapacity(0) + { + *this = src; + } + + ~CSimpleArray() + { + RemoveAll(); + } + + BOOL Add(const T& t) + { + // is the capacity enough? + if (m_nCapacity < m_nCount + 1) + { + // allocate extra capacity for optimization + const int nNewCapacity = (m_nCount + 1) + c_nGrow; + T *pNewData = (T *)realloc(m_pData, nNewCapacity * sizeof(T)); + if (pNewData == NULL) + return FALSE; // failure + + m_pData = pNewData; + m_nCapacity = nNewCapacity; + } + + // call constructor + ConstructItemInPlace(m_nCount, t); + + // increment + ++m_nCount; + + return TRUE; + } + + int Find(const T& t) const + { + for (int nIndex = 0; nIndex < m_nCount; ++nIndex) + { + if (TEqual::IsEqual(m_pData[nIndex], t)) + { + return nIndex; // success + } + } + return -1; // failure + } + + T* GetData() + { + return m_pData; + } + + const T* GetData() const + { + return m_pData; + } + + int GetSize() const + { + return m_nCount; + } + + BOOL Remove(const T& t) + { + return RemoveAt(Find(t)); + } + + void RemoveAll() + { + if (m_pData) + { + // call destructor + const int nCount = m_nCount; + for (int nIndex = 0; nIndex < nCount; ++nIndex) + { + DestructItem(nIndex); + } + + free(m_pData); + m_pData = NULL; + } + m_nCount = 0; + m_nCapacity = 0; + } + + BOOL RemoveAt(int nIndex) + { + // boundary check + if (nIndex < 0 || m_nCount <= nIndex) + return FALSE; // failure + + // call destructor + DestructItem(nIndex); + + // move range [nIndex + 1, m_nCount) to nIndex + const int nRightCount = m_nCount - (nIndex + 1); + const int nRightSize = nRightCount * sizeof(T); + memmove(&m_pData[nIndex], &m_pData[nIndex + 1], nRightSize); + + // decrement + --m_nCount; + + return TRUE; + } + + BOOL SetAtIndex(int nIndex, const T& t) + { + // boundary check + if (nIndex < 0 || m_nCount <= nIndex) + return FALSE; // failure + + // store it + m_pData[nIndex] = t; + return TRUE; + } + + T& operator[](int nIndex) + { + ATLASSERT(0 <= nIndex && nIndex < m_nCount); + return m_pData[nIndex]; + } + + const T& operator[](int nIndex) const + { + ATLASSERT(0 <= nIndex && nIndex < m_nCount); + return m_pData[nIndex]; + } + + CSimpleArray& operator=(const CSimpleArray& src) + { + // don't copy if two objects are same + if (this == &src) + return *this; + + if (src.GetSize() != GetSize()) + { + RemoveAll(); + + m_nCapacity = src.GetSize(); + + T *pNewData = (T *)realloc(m_pData, m_nCapacity * sizeof(T)); + ATLASSERT(pNewData); + if (pNewData == NULL) + return *this; // failure + + // store new data and capacity + m_pData = pNewData; + m_nCount = m_nCapacity; + } + else + { + for (int nIndex = 0; nIndex < m_nCount; ++nIndex) + { + DestructItem(nIndex); + } + } + + ATLASSERT(GetSize() == src.GetSize()); + for (int nIndex = 0; nIndex < src.GetSize(); ++nIndex) + { + ConstructItemInPlace(nIndex, src[nIndex]); + } + + return *this; + } + +protected: + T * m_pData; // malloc'ed + int m_nCount; // # of items of type T + int m_nCapacity; // for optimization + static const int c_nGrow = 8; // for optimization + + // NOTE: Range m_pData[0] .. m_pData[m_nCapacity - 1] are accessible. + // NOTE: Range [0, m_nCount) are constructed. + // NOTE: Range [m_nCount, m_nCapacity) are not constructed. + // NOTE: 0 <= m_nCount && m_nCount <= m_nCapacity. + + // call constructor at nIndex + void ConstructItemInPlace(int nIndex, const T& src) + { + new(&m_pData[nIndex]) ConstructImpl(src); + } + + // call destructor at nIndex + void DestructItem(int nIndex) + { + m_pData[nIndex].~T(); + } + +private: + + struct ConstructImpl + { + ConstructImpl(const T& obj) + :m_ConstructHelper(obj) + { + } + + static void *operator new(size_t, void *ptr) + { + return ptr; + } + + static void operator delete(void *p, void* ) + { + } + + T m_ConstructHelper; + }; + +}; + +template +class CSimpleMapEqualHelper +{ +public: + static bool IsEqualKey(const TKey& k1, const TKey& k2) + { + return k1 == k2; + } + + static bool IsEqualValue(const TVal& v1, const TVal& v2) + { + return v1 == v2; + } +}; + +// This class exists for the keys and the values of no comparison. +template +class CSimpleMapEqualHelperFalse +{ +public: + static bool IsEqualKey(const TKey& k1, const TKey& k2) + { + ATLASSERT(FALSE); + return false; + } + + static bool IsEqualValue(const TVal& v1, const TVal& v2) + { + ATLASSERT(FALSE); + return false; + } +}; + +template > +class CSimpleMap +{ +public: + typedef TKey _ArrayKeyType; + typedef TVal _ArrayElementType; + + CSimpleMap() + { + } + + ~CSimpleMap() + { + } + + BOOL Add(const TKey& key, const TVal& val) + { + Pair pair(key, val); + return m_Pairs.Add(pair); + } + + int FindKey(const TKey& key) const + { + const int nCount = GetSize(); + for (int nIndex = 0; nIndex < nCount; ++nIndex) + { + if (TEqual::IsEqualKey(m_Pairs[nIndex].key, key)) + { + return nIndex; // success + } + } + return -1; // failure + } + + int FindVal(const TVal& val) const + { + const int nCount = GetSize(); + for (int nIndex = 0; nIndex < nCount; ++nIndex) + { + if (TEqual::IsEqualValue(m_Pairs[nIndex].val, val)) + { + return nIndex; // success + } + } + return -1; // failure + } + + TKey& GetKeyAt(int nIndex) + { + ATLASSERT(0 <= nIndex && nIndex < GetSize()); + return m_Pairs[nIndex].key; + } + + const TKey& GetKeyAt(int nIndex) const + { + ATLASSERT(0 <= nIndex && nIndex < GetSize()); + return m_Pairs[nIndex].key; + } + + int GetSize() const + { + return m_Pairs.GetSize(); + } + + TVal& GetValueAt(int nIndex) + { + ATLASSERT(0 <= nIndex && nIndex < GetSize()); + return m_Pairs[nIndex].val; + } + + const TVal& GetValueAt(int nIndex) const + { + ATLASSERT(0 <= nIndex && nIndex < GetSize()); + return m_Pairs[nIndex].val; + } + + TVal Lookup(const TKey& key) const + { + int nIndex = FindKey(key); + if (nIndex < 0) + return TVal(); + return m_Pairs[nIndex].val; + } + + BOOL Remove(const TKey& key) + { + int nIndex = FindKey(key); + return RemoveAt(nIndex); + } + + void RemoveAll() + { + m_Pairs.RemoveAll(); + } + + BOOL RemoveAt(int nIndex) + { + return m_Pairs.RemoveAt(nIndex); + } + + TKey ReverseLookup(const TVal& val) const + { + int nIndex = FindVal(val); + if (nIndex < 0) + return TKey(); + return m_Pairs[nIndex].key; + } + + BOOL SetAt(const TKey& key, const TVal& val) + { + int nIndex = FindKey(key); + if (nIndex < 0) + return Add(key, val); + + m_Pairs[nIndex].val = val; + return TRUE; + } + + BOOL SetAtIndex(int nIndex, const TKey& key, const TVal& val) + { + // boundary check + if (nIndex < 0 || GetSize() <= nIndex) + return FALSE; + + m_Pairs[nIndex].key = key; + m_Pairs[nIndex].val = val; + return TRUE; + } + +protected: + struct Pair + { + TKey key; + TVal val; + + Pair() + { + } + + Pair(const TKey& k, const TVal& v) : key(k), val(v) + { + } + + Pair(const Pair& pair) : key(pair.key), val(pair.val) + { + } + + Pair& operator=(const Pair& pair) + { + key = pair.key; + val = pair.val; + return *this; + } + }; + + CSimpleArray > m_Pairs; +}; + +} + +#endif diff --git a/rostests/apitests/atl/CMakeLists.txt b/rostests/apitests/atl/CMakeLists.txt index ada8acd98c2..802911ce11d 100644 --- a/rostests/apitests/atl/CMakeLists.txt +++ b/rostests/apitests/atl/CMakeLists.txt @@ -10,6 +10,8 @@ add_executable(atl_apitest CComHeapPtr.cpp CImage.cpp CRegKey.cpp + CSimpleArray.cpp + CSimpleMap.cpp CString.cpp testlist.c atl_apitest.rc) diff --git a/rostests/apitests/atl/CSimpleArray.cpp b/rostests/apitests/atl/CSimpleArray.cpp new file mode 100644 index 00000000000..a287a5c156a --- /dev/null +++ b/rostests/apitests/atl/CSimpleArray.cpp @@ -0,0 +1,186 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Test for CSimpleArray + * PROGRAMMER: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) + */ + +#ifdef __REACTOS__ + #include +#else + #include + #include + #include + int g_tests_executed = 0; + int g_tests_failed = 0; + void ok_func(const char *file, int line, bool value, const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + if (!value) + { + printf("%s (%d): ", file, line); + vprintf(fmt, va); + g_tests_failed++; + } + g_tests_executed++; + va_end(va); + } + #undef ok + #define ok(value, ...) ok_func(__FILE__, __LINE__, value, __VA_ARGS__) + #define START_TEST(x) int main(void) +#endif + +#include +#include + +struct CCreature +{ + static int s_nCount; + static int s_nCopyCount; + CCreature() + { + CCreature::s_nCount++; + } + CCreature(const CCreature& c) + { + CCreature::s_nCount++; + } + ~CCreature() + { + CCreature::s_nCount--; + } + CCreature& operator=(const CCreature& other) + { + CCreature::s_nCopyCount++; + return *this; + } +}; + +int CCreature::s_nCount = 0; +int CCreature::s_nCopyCount = 0; + + +START_TEST(CSimpleArray) +{ + CSimpleArray array1; + + ok(array1.GetSize() == 0, "Expected array1's size is zero, was %d\n", array1.GetSize()); + + array1.Add(123); + + ok(array1.GetSize() == 1, "Expected array1's size is 1, was %d\n", array1.GetSize()); + ok(array1.GetData()[0] == 123, "Expected array1.GetData()[0] is 123, was %d\n", array1.GetData()[0]); + ok(array1[0] == 123, "Expected array1[0] is 123, was %d\n", array1[0]); + + array1.Add(456); + + ok(array1.GetSize() == 2, "Expected array1's size is 2, was %d\n", array1.GetSize()); + ok(array1.GetData()[0] == 123, "Expected array1.GetData()[0] is 123, was %d\n", array1.GetData()[0]); + ok(array1[0] == 123, "Expected array1[0] is 123, was %d\n", array1[0]); + ok(array1.GetData()[1] == 456, "Expected array1.GetData()[1] is 456, was %d\n", array1.GetData()[1]); + ok(array1[1] == 456, "Expected array1[1] is 456, was %d\n", array1[1]); + + array1.RemoveAll(); + ok(array1.GetSize() == 0, "Expected array1's size is 0, was %d\n", array1.GetSize()); + + array1.Add(1); + array1.Add(1); + array1.Add(1); + array1.Add(2); + array1.Add(2); + array1.Add(3); + ok(array1.GetSize() == 6, "Expected array1's size is 6, was %d\n", array1.GetSize()); + + array1.Remove(2); + ok(array1.GetSize() == 5, "Expected array1's size is 5, was %d\n", array1.GetSize()); + + array1.Remove(1); + ok(array1.GetSize() == 4, "Expected array1's size is 4, was %d\n", array1.GetSize()); + + ok(array1[0] == 1, "Expected array1[0] is 1, was %d\n", array1[0]); + ok(array1[1] == 1, "Expected array1[1] is 1, was %d\n", array1[1]); + ok(array1[2] == 2, "Expected array1[2] is 2, was %d\n", array1[2]); + ok(array1[3] == 3, "Expected array1[3] is 3, was %d\n", array1[3]); + + ok(CCreature::s_nCount == 0, "Expected CCreature::s_nCount is zero, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + CSimpleArray array2; + { + CCreature creature1, creature2; + + ok(CCreature::s_nCount == 2, "Expected CCreature::s_nCount is 2, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + array2.Add(creature1); + ok(CCreature::s_nCount == 3, "Expected CCreature::s_nCount is 3, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + array2.Add(creature2); + ok(CCreature::s_nCount == 4, "Expected CCreature::s_nCount is 4, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + } + ok(CCreature::s_nCount == 2, "Expected CCreature::s_nCount is 2, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + { + CSimpleArray array3(array2), array4, array5; + ok(CCreature::s_nCount == 4, "Expected CCreature::s_nCount is 4, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array4 = array2; + ok(CCreature::s_nCount == 6, "Expected CCreature::s_nCount is 6, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + CCreature creature1; + ok(CCreature::s_nCount == 7, "Expected CCreature::s_nCount is 7, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array4.Add(creature1); + ok(CCreature::s_nCount == 8, "Expected CCreature::s_nCount is 8, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array3 = array4; + ok(CCreature::s_nCount == 9, "Expected CCreature::s_nCount is 9, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array5 = array2; + ok(CCreature::s_nCount == 11, "Expected CCreature::s_nCount is 11, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array5 = array2; + ok(CCreature::s_nCount == 11, "Expected CCreature::s_nCount is 11, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + } + ok(CCreature::s_nCount == 2, "Expected CCreature::s_nCount is 2, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array2.RemoveAll(); + ok(CCreature::s_nCount == 0, "Expected CCreature::s_nCount is zero, was: %d\n", CCreature::s_nCount); + ok(CCreature::s_nCopyCount == 0, "Expected CCreature::s_nCopyCount is zero, was: %d\n", CCreature::s_nCopyCount); + + array1.RemoveAll(); + ok(array1.GetSize() == 0, "Expected array1.GetSize() is zero, was: %d\n", array1.GetSize()); + for (int i = 0; i < 100; ++i) + { + array1.Add(i); + } + ok(array1.GetSize() == 100, "Expected array1.GetSize() is 100, was: %d\n", array1.GetSize()); + + array1.RemoveAll(); + ok(array1.GetSize() == 0, "Expected array1.GetSize() is zero, was: %d\n", array1.GetSize()); + array1.Add(123); + array1.Add(321); + ok(!!array1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n"); + ok(array1.GetSize() == 1, "Expected array1.GetSize() is 1, was: %d\n", array1.GetSize()); + if (array1.GetSize() == 1) + { + ok(array1[0] == 321, "Expected array1[0] is 321, was %d\n", array1[0]); + } + ok(!!array1.RemoveAt(0), "Expected RemoveAt(0) to succeed\n"); + ok(array1.GetSize() == 0, "Expected array1.GetSize() is 0, was: %d\n", array1.GetSize()); + +#ifndef __REACTOS__ + printf("CSimpleArray: %i tests executed (0 marked as todo, %i failures), 0 skipped.\n", g_tests_executed, g_tests_failed); + return g_tests_failed; +#endif +} diff --git a/rostests/apitests/atl/CSimpleMap.cpp b/rostests/apitests/atl/CSimpleMap.cpp new file mode 100644 index 00000000000..eac6a2d54f2 --- /dev/null +++ b/rostests/apitests/atl/CSimpleMap.cpp @@ -0,0 +1,206 @@ +/* + * 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 __REACTOS__ + #include +#else + #include + #include + #include + int g_tests_executed = 0; + int g_tests_failed = 0; + void ok_func(const char *file, int line, bool value, const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + if (!value) + { + printf("%s (%d): ", file, line); + vprintf(fmt, va); + g_tests_failed++; + } + g_tests_executed++; + va_end(va); + } + #undef ok + #define ok(value, ...) ok_func(__FILE__, __LINE__, value, __VA_ARGS__) + #define START_TEST(x) int main(void) +#endif + +#include +#include + +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 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 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 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()); + +#ifndef __REACTOS__ + printf("CSimpleMap: %i tests executed (0 marked as todo, %i failures), 0 skipped.\n", g_tests_executed, g_tests_failed); + return g_tests_failed; +#endif +} diff --git a/rostests/apitests/atl/devenv/ATLTest.sln b/rostests/apitests/atl/devenv/ATLTest.sln new file mode 100644 index 00000000000..76dd5427111 --- /dev/null +++ b/rostests/apitests/atl/devenv/ATLTest.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CImage", "CImage.vcxproj", "{AE520E17-2DAE-40FF-B082-F32A7A935FB2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSimpleArray", "CSimpleArray.vcxproj", "{9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSimpleMap", "CSimpleMap.vcxproj", "{EC560DE6-6DB3-437D-85CA-582491FE6F95}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x64.ActiveCfg = Debug|x64 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x64.Build.0 = Debug|x64 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x86.ActiveCfg = Debug|Win32 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x86.Build.0 = Debug|Win32 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x64.ActiveCfg = Release|x64 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x64.Build.0 = Release|x64 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x86.ActiveCfg = Release|Win32 + {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x86.Build.0 = Release|Win32 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Debug|x64.ActiveCfg = Debug|x64 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Debug|x64.Build.0 = Debug|x64 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Debug|x86.ActiveCfg = Debug|Win32 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Debug|x86.Build.0 = Debug|Win32 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Release|x64.ActiveCfg = Release|x64 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Release|x64.Build.0 = Release|x64 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Release|x86.ActiveCfg = Release|Win32 + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55}.Release|x86.Build.0 = Release|Win32 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Debug|x64.ActiveCfg = Debug|x64 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Debug|x64.Build.0 = Debug|x64 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Debug|x86.ActiveCfg = Debug|Win32 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Debug|x86.Build.0 = Debug|Win32 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x64.ActiveCfg = Release|x64 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x64.Build.0 = Release|x64 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x86.ActiveCfg = Release|Win32 + {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/rostests/apitests/atl/devenv/CImage.sln b/rostests/apitests/atl/devenv/CImage.sln deleted file mode 100644 index 099c2c3851a..00000000000 --- a/rostests/apitests/atl/devenv/CImage.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CImage", "CImage.vcxproj", "{AE520E17-2DAE-40FF-B082-F32A7A935FB2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x64.ActiveCfg = Debug|x64 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x64.Build.0 = Debug|x64 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x86.ActiveCfg = Debug|Win32 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Debug|x86.Build.0 = Debug|Win32 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x64.ActiveCfg = Release|x64 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x64.Build.0 = Release|x64 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x86.ActiveCfg = Release|Win32 - {AE520E17-2DAE-40FF-B082-F32A7A935FB2}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/rostests/apitests/atl/devenv/CImage.vcxproj b/rostests/apitests/atl/devenv/CImage.vcxproj index 571f2e3c94c..e958b071d37 100644 --- a/rostests/apitests/atl/devenv/CImage.vcxproj +++ b/rostests/apitests/atl/devenv/CImage.vcxproj @@ -27,7 +27,7 @@ Application true - v140 + v120_xp Unicode @@ -39,13 +39,13 @@ Application true - v140 Unicode + v120_xp Application false - v140 + v120_xp Unicode diff --git a/rostests/apitests/atl/devenv/CSimpleArray.vcxproj b/rostests/apitests/atl/devenv/CSimpleArray.vcxproj new file mode 100644 index 00000000000..189f4e2a60a --- /dev/null +++ b/rostests/apitests/atl/devenv/CSimpleArray.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {9F029341-87C2-4BFD-B1FC-D5F5B8D28D55} + 8.1 + AtlProj + + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + true + + + true + false + + + true + false + + + + NotUsing + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + MultiThreaded + MultiThreaded + MultiThreadedDebug + MultiThreadedDebug + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + \ No newline at end of file diff --git a/rostests/apitests/atl/devenv/CSimpleMap.vcxproj b/rostests/apitests/atl/devenv/CSimpleMap.vcxproj new file mode 100644 index 00000000000..2ff7f04a3e3 --- /dev/null +++ b/rostests/apitests/atl/devenv/CSimpleMap.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {EC560DE6-6DB3-437D-85CA-582491FE6F95} + 8.1 + AtlProj + + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + true + + + true + false + + + true + false + + + + NotUsing + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + MultiThreaded + MultiThreaded + MultiThreadedDebug + MultiThreadedDebug + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + \ No newline at end of file diff --git a/rostests/apitests/atl/testlist.c b/rostests/apitests/atl/testlist.c index 535f8bced89..bfeb9d0ba1a 100644 --- a/rostests/apitests/atl/testlist.c +++ b/rostests/apitests/atl/testlist.c @@ -6,6 +6,8 @@ extern void func_CComBSTR(void); extern void func_CComHeapPtr(void); extern void func_CImage(void); extern void func_CRegKey(void); +extern void func_CSimpleArray(void); +extern void func_CSimpleMap(void); extern void func_CString(void); const struct test winetest_testlist[] = @@ -15,6 +17,8 @@ const struct test winetest_testlist[] = { "CComHeapPtr", func_CComHeapPtr }, { "CImage", func_CImage }, { "CRegKey", func_CRegKey }, + { "CSimpleArray", func_CSimpleArray }, + { "CSimpleMap", func_CSimpleMap }, { "CString", func_CString }, { 0, 0 } }; -- 2.17.1