1 //===-- vector_test.cpp -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "tests/scudo_unit_test.h"
10
11 #include "vector.h"
12
TEST(ScudoVectorTest,Basic)13 TEST(ScudoVectorTest, Basic) {
14 scudo::Vector<int> V;
15 EXPECT_EQ(V.size(), 0U);
16 V.push_back(42);
17 EXPECT_EQ(V.size(), 1U);
18 EXPECT_EQ(V[0], 42);
19 V.push_back(43);
20 EXPECT_EQ(V.size(), 2U);
21 EXPECT_EQ(V[0], 42);
22 EXPECT_EQ(V[1], 43);
23 }
24
TEST(ScudoVectorTest,Stride)25 TEST(ScudoVectorTest, Stride) {
26 scudo::Vector<int> V;
27 for (int i = 0; i < 1000; i++) {
28 V.push_back(i);
29 EXPECT_EQ(V.size(), i + 1U);
30 EXPECT_EQ(V[i], i);
31 }
32 for (int i = 0; i < 1000; i++)
33 EXPECT_EQ(V[i], i);
34 }
35
TEST(ScudoVectorTest,ResizeReduction)36 TEST(ScudoVectorTest, ResizeReduction) {
37 scudo::Vector<int> V;
38 V.push_back(0);
39 V.push_back(0);
40 EXPECT_EQ(V.size(), 2U);
41 V.resize(1);
42 EXPECT_EQ(V.size(), 1U);
43 }
44