ReactOS  0.4.14-dev-998-g623dd26
CAtlList.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE: Test for CAtlList
5  * COPYRIGHT: Copyright 2016-2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  * Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
7  */
8 
9 #ifdef HAVE_APITEST
10  #include <apitest.h>
11 #else
12  #include "atltest.h"
13 #endif
14 
15 #include <atlbase.h>
16 #include <atlcoll.h>
17 
18 
20 {
21  CAtlList<int> list1;
22 
23  ok_size_t(list1.GetCount(), 0);
24  list1.AddTail(56);
25  ok_size_t(list1.GetCount(), 1);
26  POSITION head = list1.AddHead(12);
27  ok_size_t(list1.GetCount(), 2);
28  POSITION tail = list1.AddTail(90);
29  ok_size_t(list1.GetCount(), 3);
30 
31  list1.InsertBefore(head, -123);
32  list1.InsertAfter(head, 34); // no longer head, but the POSITION should still be valid..
33 
34  list1.InsertBefore(tail, 78);
35  list1.InsertAfter(tail, -44);
36 
37  int expected[] = {-123, 12, 34, 56, 78, 90, -44 };
38  int expected_size = sizeof(expected) / sizeof(expected[0]);
39  int index = 0;
40  POSITION it = list1.GetHeadPosition();
41  while (it != NULL)
42  {
43  ok(index < expected_size, "Too many items, expected %d, got %d!\n", expected_size, (index+1));
44  int value = list1.GetNext(it);
45  if (index < expected_size)
46  {
47  ok(value == expected[index], "Wrong value, got %d, expected %d\n", value, expected[index]);
48  }
49  else
50  {
51  ok(0, "Extra value: %d\n", value);
52  }
53  index++;
54  }
55  ok(it == NULL, "it does still point to something!\n");
56 }
POSITION GetHeadPosition() const
Definition: atlcoll.h:534
struct outqueuenode * tail
Definition: adnsresfilter.c:66
struct outqueuenode * head
Definition: adnsresfilter.c:66
START_TEST(CAtlList)
Definition: CAtlList.cpp:19
POSITION InsertBefore(_In_ POSITION pos, INARGTYPE element)
Definition: atlcoll.h:666
smooth NULL
Definition: ftsmooth.c:416
size_t GetCount() const
Definition: atlcoll.h:522
GLuint index
Definition: glext.h:6031
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:546
#define ok_size_t(expression, result)
Definition: atltest.h:115
POSITION InsertAfter(_In_ POSITION pos, INARGTYPE element)
Definition: atlcoll.h:688
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:609
#define ok(value,...)
Definition: atltest.h:57
POSITION AddHead(INARGTYPE element)
Definition: atlcoll.h:592
BOOL expected
Definition: store.c:2063