ReactOS 0.4.16-dev-125-g798ea90
CAtlList.cpp File Reference
#include "atltest.h"
#include <atlbase.h>
#include <atlcoll.h>
#include <atlstr.h>
Include dependency graph for CAtlList.cpp:

Go to the source code of this file.

Macros

#define ok_list(lst, expected)
 

Functions

static void test_BasicCases ()
 
static CStringW to_str (const CAtlList< int > &lst)
 
static void test_SwapElements ()
 
static void test_AppendListToTail ()
 
static void test_AppendListToHead ()
 
 START_TEST (CAtlList)
 

Macro Definition Documentation

◆ ok_list

#define ok_list (   lst,
  expected 
)
Value:
do \
{ \
CStringW _value = to_str(lst); \
ok(_value == (expected), "Wrong value for '%s', expected: " #expected " got: \"%S\"\n", #lst, \
_value.GetString()); \
} while (0)
static CStringW to_str(const CAtlList< int > &lst)
Definition: CAtlList.cpp:60
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
BOOL expected
Definition: store.c:2063

Definition at line 72 of file CAtlList.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( CAtlList  )

Definition at line 160 of file CAtlList.cpp.

161{
166}
static void test_BasicCases()
Definition: CAtlList.cpp:20
static void test_SwapElements()
Definition: CAtlList.cpp:82
static void test_AppendListToHead()
Definition: CAtlList.cpp:139
static void test_AppendListToTail()
Definition: CAtlList.cpp:117

◆ test_AppendListToHead()

static void test_AppendListToHead ( )
static

Definition at line 139 of file CAtlList.cpp.

140{
142 list_head.AddHead(0);
143 list_head.AddHead(0);
144 list_head.AddHead(2);
145 ok_list(list_head, "2,0,0,");
146
148 list.AddHead(8);
149 list.AddHead(9);
150 list.AddHead(7);
151 ok_list(list, "7,9,8,");
152
153 list.AddHeadList(&list_head);
154 ok_list(list, "2,0,0,7,9,8,");
155
156 list_head.AddHeadList(&list);
157 ok_list(list_head, "2,0,0,7,9,8,2,0,0,");
158}
#define ok_list(lst, expected)
Definition: CAtlList.cpp:72
Definition: list.h:37
Definition: list.h:15

Referenced by START_TEST().

◆ test_AppendListToTail()

static void test_AppendListToTail ( )
static

Definition at line 117 of file CAtlList.cpp.

118{
120 list.AddTail(1);
121 list.AddTail(2);
122 list.AddTail(0);
123 ok_list(list, "1,2,0,");
124
126 list_tail.AddTail(8);
127 list_tail.AddTail(1);
128 list_tail.AddTail(0);
129 ok_list(list_tail, "8,1,0,");
130
131 list.AddTailList(&list_tail);
132 ok_list(list, "1,2,0,8,1,0,");
133
134 list_tail.AddTailList(&list);
135 ok_list(list_tail, "8,1,0,1,2,0,8,1,0,");
136}
__WINE_SERVER_LIST_INLINE struct list * list_tail(const struct list *list)
Definition: list.h:137

Referenced by START_TEST().

◆ test_BasicCases()

static void test_BasicCases ( )
static

Definition at line 20 of file CAtlList.cpp.

21{
22 CAtlList<int> list1;
23
24 ok_size_t(list1.GetCount(), 0);
25 list1.AddTail(56);
26 ok_size_t(list1.GetCount(), 1);
27 POSITION head = list1.AddHead(12);
28 ok_size_t(list1.GetCount(), 2);
29 POSITION tail = list1.AddTail(90);
30 ok_size_t(list1.GetCount(), 3);
31
32 list1.InsertBefore(head, -123);
33 list1.InsertAfter(head, 34); // no longer head, but the POSITION should still be valid..
34
35 list1.InsertBefore(tail, 78);
36 list1.InsertAfter(tail, -44);
37
38 int expected[] = {-123, 12, 34, 56, 78, 90, -44};
39 int expected_size = sizeof(expected) / sizeof(expected[0]);
40 int index = 0;
41 POSITION it = list1.GetHeadPosition();
42 while (it != NULL)
43 {
44 ok(index < expected_size, "Too many items, expected %d, got %d!\n", expected_size, (index + 1));
45 int value = list1.GetNext(it);
46 if (index < expected_size)
47 {
48 ok(value == expected[index], "Wrong value, got %d, expected %d\n", value, expected[index]);
49 }
50 else
51 {
52 ok(0, "Extra value: %d\n", value);
53 }
54 index++;
55 }
56 ok(it == NULL, "it does still point to something!\n");
57}
struct outqueuenode * tail
Definition: adnsresfilter.c:66
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define ok(value,...)
Definition: atltest.h:57
#define ok_size_t(expression, result)
Definition: atltest.h:115
POSITION InsertAfter(_In_ POSITION pos, INARGTYPE element)
Definition: atlcoll.h:726
POSITION AddHead(INARGTYPE element)
Definition: atlcoll.h:612
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:629
POSITION GetHeadPosition() const
Definition: atlcoll.h:554
POSITION InsertBefore(_In_ POSITION pos, INARGTYPE element)
Definition: atlcoll.h:704
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:566
size_t GetCount() const
Definition: atlcoll.h:542
#define NULL
Definition: types.h:112
GLuint index
Definition: glext.h:6031
Definition: pdh_main.c:94

Referenced by START_TEST().

◆ test_SwapElements()

static void test_SwapElements ( )
static

Definition at line 82 of file CAtlList.cpp.

83{
85 list.AddTail(1);
86 list.AddTail(2);
87 list.AddTail(3);
88
89 ok_list(list, "1,2,3,");
90
91 POSITION p1 = list.FindIndex(0);
92 POSITION p2 = list.FindIndex(2);
93
94 list.SwapElements(p1, p1);
95 ok_list(list, "1,2,3,");
96
97 list.SwapElements(p1, p2);
98 ok_list(list, "3,2,1,");
99
100 p1 = list.FindIndex(0);
101 p2 = list.FindIndex(1);
102 list.SwapElements(p1, p2);
103 ok_list(list, "2,3,1,");
104
105 p1 = list.FindIndex(1);
106 p2 = list.FindIndex(2);
107 list.SwapElements(p1, p2);
108 ok_list(list, "2,1,3,");
109
110 p1 = list.FindIndex(0);
111 p2 = list.FindIndex(2);
112 list.SwapElements(p2, p1);
113 ok_list(list, "3,1,2,");
114}

Referenced by START_TEST().

◆ to_str()

static CStringW to_str ( const CAtlList< int > &  lst)
static

Definition at line 60 of file CAtlList.cpp.

61{
62 CStringW tmp;
63 POSITION it = lst.GetHeadPosition();
64 while (it != NULL)
65 {
66 int value = lst.GetNext(it);
67 tmp.AppendFormat(L"%d,", value);
68 }
69 return tmp;
70}
void __cdecl AppendFormat(UINT nFormatID,...)
Definition: cstringt.h:800
#define L(x)
Definition: ntvdm.h:50