Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/z/test_zArray.cpp
41152 views
1
/*
2
* Copyright (c) 2017, 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 "gc/z/zArray.inline.hpp"
26
#include "unittest.hpp"
27
28
TEST(ZArray, sanity) {
29
ZArray<int> a;
30
31
// Add elements
32
for (int i = 0; i < 10; i++) {
33
a.append(i);
34
}
35
36
ZArray<int> b;
37
38
b.swap(&a);
39
40
// Check size
41
ASSERT_EQ(a.length(), 0);
42
ASSERT_EQ(a.max_length(), 0);
43
ASSERT_EQ(a.is_empty(), true);
44
45
ASSERT_EQ(b.length(), 10);
46
ASSERT_GE(b.max_length(), 10);
47
ASSERT_EQ(b.is_empty(), false);
48
49
// Clear elements
50
a.clear();
51
52
// Check that b is unaffected
53
ASSERT_EQ(b.length(), 10);
54
ASSERT_GE(b.max_length(), 10);
55
ASSERT_EQ(b.is_empty(), false);
56
57
a.append(1);
58
59
// Check that b is unaffected
60
ASSERT_EQ(b.length(), 10);
61
ASSERT_GE(b.max_length(), 10);
62
ASSERT_EQ(b.is_empty(), false);
63
}
64
65
TEST(ZArray, iterator) {
66
ZArray<int> a;
67
68
// Add elements
69
for (int i = 0; i < 10; i++) {
70
a.append(i);
71
}
72
73
// Iterate
74
int count = 0;
75
ZArrayIterator<int> iter(&a);
76
for (int value; iter.next(&value);) {
77
ASSERT_EQ(a.at(count), count);
78
count++;
79
}
80
81
// Check count
82
ASSERT_EQ(count, 10);
83
}
84
85