Path: blob/master/test/hotspot/gtest/gc/z/test_zArray.cpp
41152 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/z/zArray.inline.hpp"25#include "unittest.hpp"2627TEST(ZArray, sanity) {28ZArray<int> a;2930// Add elements31for (int i = 0; i < 10; i++) {32a.append(i);33}3435ZArray<int> b;3637b.swap(&a);3839// Check size40ASSERT_EQ(a.length(), 0);41ASSERT_EQ(a.max_length(), 0);42ASSERT_EQ(a.is_empty(), true);4344ASSERT_EQ(b.length(), 10);45ASSERT_GE(b.max_length(), 10);46ASSERT_EQ(b.is_empty(), false);4748// Clear elements49a.clear();5051// Check that b is unaffected52ASSERT_EQ(b.length(), 10);53ASSERT_GE(b.max_length(), 10);54ASSERT_EQ(b.is_empty(), false);5556a.append(1);5758// Check that b is unaffected59ASSERT_EQ(b.length(), 10);60ASSERT_GE(b.max_length(), 10);61ASSERT_EQ(b.is_empty(), false);62}6364TEST(ZArray, iterator) {65ZArray<int> a;6667// Add elements68for (int i = 0; i < 10; i++) {69a.append(i);70}7172// Iterate73int count = 0;74ZArrayIterator<int> iter(&a);75for (int value; iter.next(&value);) {76ASSERT_EQ(a.at(count), count);77count++;78}7980// Check count81ASSERT_EQ(count, 10);82}838485