view test/hotspot/gtest/gc/z/test_zArray.cpp @ 50525:767cdb97f103

8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental) Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke Contributed-by: per.liden@oracle.com, stefan.karlsson@oracle.com, erik.osterlund@oracle.com, mikael.gerdin@oracle.com, kim.barrett@oracle.com, nils.eliasson@oracle.com, rickard.backman@oracle.com, rwestrel@redhat.com, coleen.phillimore@oracle.com, robbin.ehn@oracle.com, gerard.ziemski@oracle.com, hugh.wilkinson@intel.com, sandhya.viswanathan@intel.com, bill.npo.wheeler@intel.com, vinay.k.awasthi@intel.com, yasuenag@gmail.com
author pliden
date Tue, 12 Jun 2018 17:40:28 +0200
parents
children b833992fa8fa
line wrap: on
line source
/*
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL.  Use is subject to license terms.
 */

#include "precompiled.hpp"
#include "gc/z/zArray.inline.hpp"
#include "unittest.hpp"

TEST(ZArrayTest, test_add) {
  ZArray<int> a;

  // Add elements
  for (int i = 0; i < 10; i++) {
    a.add(i);
  }

  // Check size
  ASSERT_EQ(a.size(), 10u);

  // Check elements
  for (int i = 0; i < 10; i++) {
    EXPECT_EQ(a.at(i), i);
  }
}

TEST(ZArrayTest, test_clear) {
  ZArray<int> a;

  // Add elements
  for (int i = 0; i < 10; i++) {
    a.add(i);
  }

  // Check size
  ASSERT_EQ(a.size(), 10u);
  ASSERT_EQ(a.is_empty(), false);

  // Clear elements
  a.clear();

  // Check size
  ASSERT_EQ(a.size(), 0u);
  ASSERT_EQ(a.is_empty(), true);

  // Add element
  a.add(11);

  // Check size
  ASSERT_EQ(a.size(), 1u);
  ASSERT_EQ(a.is_empty(), false);

  // Clear elements
  a.clear();

  // Check size
  ASSERT_EQ(a.size(), 0u);
  ASSERT_EQ(a.is_empty(), true);
}

TEST(ZArrayTest, test_iterator) {
  ZArray<int> a;

  // Add elements
  for (int i = 0; i < 10; i++) {
    a.add(i);
  }

  // Iterate
  int count = 0;
  ZArrayIterator<int> iter(&a);
  for (int value; iter.next(&value);) {
    ASSERT_EQ(a.at(count), count);
    count++;
  }

  // Check count
  ASSERT_EQ(count, 10);
}