1 //===-- sanitizer_list_test.cc --------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_list.h"
14 #include "gtest/gtest.h"
16 namespace __sanitizer
{
22 typedef IntrusiveList
<ListItem
> List
;
24 static List static_list
;
26 static void SetList(List
*l
, ListItem
*x
= 0,
27 ListItem
*y
= 0, ListItem
*z
= 0) {
29 if (x
) l
->push_back(x
);
30 if (y
) l
->push_back(y
);
31 if (z
) l
->push_back(z
);
34 static void CheckList(List
*l
, ListItem
*i1
, ListItem
*i2
= 0, ListItem
*i3
= 0,
35 ListItem
*i4
= 0, ListItem
*i5
= 0, ListItem
*i6
= 0) {
37 CHECK_EQ(l
->front(), i1
);
41 CHECK_EQ(l
->front(), i2
);
45 CHECK_EQ(l
->front(), i3
);
49 CHECK_EQ(l
->front(), i4
);
53 CHECK_EQ(l
->front(), i5
);
57 CHECK_EQ(l
->front(), i6
);
63 TEST(SanitizerCommon
, IntrusiveList
) {
65 CHECK_EQ(static_list
.size(), 0);
70 ListItem
*x
= &items
[0];
71 ListItem
*y
= &items
[1];
72 ListItem
*z
= &items
[2];
73 ListItem
*a
= &items
[3];
74 ListItem
*b
= &items
[4];
75 ListItem
*c
= &items
[5];
77 CHECK_EQ(l
.size(), 0);
79 CHECK_EQ(l
.size(), 1);
80 CHECK_EQ(l
.back(), x
);
81 CHECK_EQ(l
.front(), x
);
87 CHECK_EQ(l
.size(), 1);
88 CHECK_EQ(l
.back(), x
);
89 CHECK_EQ(l
.front(), x
);
97 CHECK_EQ(l
.size(), 3);
98 CHECK_EQ(l
.front(), z
);
99 CHECK_EQ(l
.back(), x
);
100 l
.CheckConsistency();
103 CHECK_EQ(l
.size(), 2);
104 CHECK_EQ(l
.front(), y
);
105 CHECK_EQ(l
.back(), x
);
109 l
.CheckConsistency();
114 CHECK_EQ(l
.size(), 3);
115 CHECK_EQ(l
.front(), x
);
116 CHECK_EQ(l
.back(), z
);
117 l
.CheckConsistency();
120 CHECK_EQ(l
.size(), 2);
121 CHECK_EQ(l
.front(), y
);
122 CHECK_EQ(l
.back(), z
);
126 l
.CheckConsistency();
132 l1
.append_front(&l2
);
143 SetList(&l1
, x
, y
, z
);
144 SetList(&l2
, a
, b
, c
);
146 CheckList(&l1
, x
, y
, z
, a
, b
, c
);
151 l1
.append_front(&l2
);
152 CheckList(&l1
, x
, y
);
156 TEST(SanitizerCommon
, IntrusiveListAppendEmpty
) {
164 CHECK_EQ(l
.back(), &i
);
165 CHECK_EQ(l
.front(), &i
);
166 CHECK_EQ(l
.size(), 1);
168 CHECK_EQ(l
.back(), &i
);
169 CHECK_EQ(l
.front(), &i
);
170 CHECK_EQ(l
.size(), 1);
173 } // namespace __sanitizer