Path: blob/master/test/hotspot/gtest/utilities/test_valueObjArray.cpp
41145 views
/*1* Copyright (c) 2020, 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*22*/2324#include "precompiled.hpp"25#include "utilities/valueObjArray.hpp"26#include "unittest.hpp"2728class ValueObjArrayTest : public ::testing::Test {29protected:30class IntGenerator {31int _current;3233public:34IntGenerator() : _current(0) {}35int operator*() const {36return _current;37}38IntGenerator operator++() {39++_current;40return *this;41}42};4344struct Struct {45int _value;46const char* _string;47};4849class StructGenerator {50int _current;5152static const char* str(int i) {53const char* array[] = {54"0",55"1",56"2",57"3"};58return array[i];59}6061public:62StructGenerator() : _current(0) {}63Struct operator*() const {64assert(_current < 4, "precondition");65Struct s = { _current, str(_current)};66return s;67}68StructGenerator operator++() {69++_current;70return *this;71}72};73};7475TEST_F(ValueObjArrayTest, primitive) {76ValueObjArrayTest::IntGenerator g;77ValueObjArray<int, 4> array(g);78ASSERT_EQ(array.count(), 4);79ASSERT_EQ(*array.at(0), 0);80ASSERT_EQ(*array.at(1), 1);81ASSERT_EQ(*array.at(2), 2);82ASSERT_EQ(*array.at(3), 3);83}8485TEST_F(ValueObjArrayTest, struct) {86ValueObjArrayTest::StructGenerator g;87ValueObjArray<Struct, 4> array(g);88ASSERT_EQ(array.count(), 4);89ASSERT_EQ(array.at(0)->_value, 0);90ASSERT_EQ(array.at(1)->_value, 1);91ASSERT_EQ(array.at(2)->_value, 2);92ASSERT_EQ(array.at(3)->_value, 3);93ASSERT_EQ(array.at(0)->_string[0], '0');94ASSERT_EQ(array.at(1)->_string[0], '1');95ASSERT_EQ(array.at(2)->_string[0], '2');96ASSERT_EQ(array.at(3)->_string[0], '3');97}9899100