Path: blob/main_old/src/common/FixedVector_unittest.cpp
1693 views
//1// Copyright 2018 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// FixedVector_unittest:6// Tests of the FixedVector class7//89#include <gtest/gtest.h>1011#include "common/FixedVector.h"1213namespace angle14{15// Make sure the various constructors compile and do basic checks16TEST(FixedVector, Constructors)17{18FixedVector<int, 5> defaultContructor;19EXPECT_EQ(0u, defaultContructor.size());2021FixedVector<int, 5> count(3);22EXPECT_EQ(3u, count.size());2324FixedVector<int, 5> countAndValue(3, 2);25EXPECT_EQ(3u, countAndValue.size());26EXPECT_EQ(2, countAndValue[1]);2728FixedVector<int, 5> copy(countAndValue);29EXPECT_EQ(copy, countAndValue);3031FixedVector<int, 5> copyRValue(std::move(count));32EXPECT_EQ(3u, copyRValue.size());3334FixedVector<int, 5> initializerList{1, 2, 3, 4, 5};35EXPECT_EQ(5u, initializerList.size());36EXPECT_EQ(3, initializerList[2]);3738FixedVector<int, 5> assignCopy(copyRValue);39EXPECT_EQ(3u, assignCopy.size());4041FixedVector<int, 5> assignRValue(std::move(assignCopy));42EXPECT_EQ(3u, assignRValue.size());4344FixedVector<int, 5> assignmentInitializerList = {1, 2, 3, 4, 5};45EXPECT_EQ(5u, assignmentInitializerList.size());46EXPECT_EQ(3, assignmentInitializerList[2]);47}4849// Test indexing operations (at, operator[])50TEST(FixedVector, Indexing)51{52FixedVector<int, 5> vec = {0, 1, 2, 3, 4};53EXPECT_EQ(0, vec.at(0));54EXPECT_EQ(vec[0], vec.at(0));55}5657// Test the push_back functions58TEST(FixedVector, PushBack)59{60FixedVector<int, 5> vec;61vec.push_back(1);62EXPECT_EQ(1, vec[0]);63vec.push_back(1);64vec.push_back(1);65vec.push_back(1);66vec.push_back(1);67EXPECT_EQ(vec.size(), vec.max_size());68}6970// Test the pop_back function71TEST(FixedVector, PopBack)72{73FixedVector<int, 5> vec;74vec.push_back(1);75EXPECT_EQ(1, (int)vec.size());76vec.pop_back();77EXPECT_EQ(0, (int)vec.size());78}7980// Test the back function81TEST(FixedVector, Back)82{83FixedVector<int, 5> vec;84vec.push_back(1);85vec.push_back(2);86EXPECT_EQ(2, vec.back());87}8889// Test the sizing operations90TEST(FixedVector, Size)91{92FixedVector<int, 5> vec;93EXPECT_TRUE(vec.empty());94EXPECT_EQ(0u, vec.size());95EXPECT_EQ(5u, vec.max_size());9697vec.push_back(1);98EXPECT_FALSE(vec.empty());99EXPECT_EQ(1u, vec.size());100}101102// Test clearing the vector103TEST(FixedVector, Clear)104{105FixedVector<int, 5> vec = {0, 1, 2, 3, 4};106vec.clear();107EXPECT_TRUE(vec.empty());108}109110// Test resizing the vector111TEST(FixedVector, Resize)112{113FixedVector<int, 5> vec;114vec.resize(5u, 1);115EXPECT_EQ(5u, vec.size());116EXPECT_EQ(1, vec[4]);117118vec.resize(2u);119EXPECT_EQ(2u, vec.size());120}121122// Test iterating over the vector123TEST(FixedVector, Iteration)124{125FixedVector<int, 5> vec = {0, 1, 2, 3};126127int vistedCount = 0;128for (int value : vec)129{130EXPECT_EQ(vistedCount, value);131vistedCount++;132}133EXPECT_EQ(4, vistedCount);134}135136// Test the "full" method.137TEST(FixedVector, Full)138{139FixedVector<int, 2> vec;140141EXPECT_FALSE(vec.full());142vec.push_back(0);143EXPECT_FALSE(vec.full());144vec.push_back(1);145EXPECT_TRUE(vec.full());146}147} // namespace angle148149150