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(ZArrayTest, test_add) { 29 ZArray<int> a; 30 31 // Add elements 32 for (int i = 0; i < 10; i++) { 33 a.add(i); 34 } 35 36 // Check size 37 ASSERT_EQ(a.size(), 10u); 38 39 // Check elements 40 for (int i = 0; i < 10; i++) { 41 EXPECT_EQ(a.at(i), i); 42 } 43 } 44 45 TEST(ZArrayTest, test_clear) { 46 ZArray<int> a; 47 48 // Add elements 49 for (int i = 0; i < 10; i++) { 50 a.add(i); 51 } 52 53 // Check size 54 ASSERT_EQ(a.size(), 10u); 55 ASSERT_EQ(a.is_empty(), false); 56 57 // Clear elements 58 a.clear(); 59 60 // Check size 61 ASSERT_EQ(a.size(), 0u); 62 ASSERT_EQ(a.is_empty(), true); 63 64 // Add element 65 a.add(11); 66 67 // Check size 68 ASSERT_EQ(a.size(), 1u); 69 ASSERT_EQ(a.is_empty(), false); 70 71 // Clear elements 72 a.clear(); 73 74 // Check size 75 ASSERT_EQ(a.size(), 0u); 76 ASSERT_EQ(a.is_empty(), true); 77 } 78 79 TEST(ZArrayTest, test_iterator) { 80 ZArray<int> a; 81 82 // Add elements 83 for (int i = 0; i < 10; i++) { 84 a.add(i); 85 } 86 87 // Iterate 88 int count = 0; 89 ZArrayIterator<int> iter(&a); 90 for (int value; iter.next(&value);) { 91 ASSERT_EQ(a.at(count), count); 92 count++; 93 } 94 95 // Check count 96 ASSERT_EQ(count, 10); 97 }