1 | /* |
2 | * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | */ |
23 | |
24 | #include "precompiled.hpp" |
25 | #include "unittest.hpp" |
26 | #include "utilities/chunkedList.hpp" |
27 | |
28 | class Metadata; |
29 | |
30 | template <typename T> |
31 | class TestChunkedList { |
32 | typedef ChunkedList<T, mtOther> ChunkedListT; |
33 | |
34 | public: |
35 | |
36 | static void testEmpty() { |
37 | ChunkedListT buffer; |
38 | ASSERT_EQ((size_t) 0, buffer.size()); |
39 | } |
40 | |
41 | static void testFull() { |
42 | ChunkedListT buffer; |
43 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) { |
44 | buffer.push((T) i); |
45 | } |
46 | ASSERT_EQ((size_t) ChunkedListT::BufferSize, buffer.size()); |
47 | ASSERT_TRUE(buffer.is_full()); |
48 | } |
49 | |
50 | static void testSize() { |
51 | ChunkedListT buffer; |
52 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) { |
53 | ASSERT_EQ((size_t) i, buffer.size()); |
54 | buffer.push((T) i); |
55 | ASSERT_EQ((size_t) (i + 1), buffer.size()); |
56 | } |
57 | } |
58 | |
59 | static void testClear() { |
60 | ChunkedListT buffer; |
61 | |
62 | buffer.clear(); |
63 | ASSERT_EQ((size_t) 0, buffer.size()); |
64 | |
65 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize / 2; i++) { |
66 | buffer.push((T) i); |
67 | } |
68 | buffer.clear(); |
69 | ASSERT_EQ((size_t) 0, buffer.size()); |
70 | |
71 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) { |
72 | buffer.push((T) i); |
73 | } |
74 | buffer.clear(); |
75 | ASSERT_EQ((size_t) 0, buffer.size()); |
76 | } |
77 | |
78 | static void testAt() { |
79 | ChunkedListT buffer; |
80 | |
81 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) { |
82 | buffer.push((T) i); |
83 | ASSERT_EQ((T) i, buffer.at(i)); |
84 | } |
85 | |
86 | for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) { |
87 | ASSERT_EQ((T) i, buffer.at(i)); |
88 | } |
89 | } |
90 | }; |
91 | |
92 | TEST(ChunkedList, metadata_empty) { |
93 | TestChunkedList<Metadata*>::testEmpty(); |
94 | } |
95 | |
96 | TEST(ChunkedList, metadata_full) { |
97 | TestChunkedList<Metadata*>::testFull(); |
98 | } |
99 | |
100 | TEST(ChunkedList, metadata_size) { |
101 | TestChunkedList<Metadata*>::testSize(); |
102 | } |
103 | |
104 | TEST(ChunkedList, metadata_clear) { |
105 | TestChunkedList<Metadata*>::testSize(); |
106 | } |
107 | |
108 | TEST(ChunkedList, metadata_at) { |
109 | TestChunkedList<Metadata*>::testAt(); |
110 | } |
111 | |
112 | TEST(ChunkedList, size_t_empty) { |
113 | TestChunkedList<size_t>::testEmpty(); |
114 | } |
115 | |
116 | TEST(ChunkedList, size_t_full) { |
117 | TestChunkedList<size_t>::testFull(); |
118 | } |
119 | |
120 | TEST(ChunkedList, size_t_size) { |
121 | TestChunkedList<size_t>::testSize(); |
122 | } |
123 | |
124 | TEST(ChunkedList, size_t_clear) { |
125 | TestChunkedList<size_t>::testSize(); |
126 | } |
127 | |
128 | TEST(ChunkedList, size_t_at) { |
129 | TestChunkedList<size_t>::testAt(); |
130 | } |
131 | |