1 | //===-- sanitizer_vector_test.cpp -----------------------------------------===// |
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 | // This file is a part of *Sanitizer runtime. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | #include "sanitizer_common/sanitizer_vector.h" |
13 | #include "gtest/gtest.h" |
14 | |
15 | namespace __sanitizer { |
16 | |
17 | TEST(Vector, Basic) { |
18 | Vector<int> v; |
19 | EXPECT_EQ(v.Size(), 0u); |
20 | v.PushBack(42); |
21 | EXPECT_EQ(v.Size(), 1u); |
22 | EXPECT_EQ(v[0], 42); |
23 | v.PushBack(43); |
24 | EXPECT_EQ(v.Size(), 2u); |
25 | EXPECT_EQ(v[0], 42); |
26 | EXPECT_EQ(v[1], 43); |
27 | } |
28 | |
29 | TEST(Vector, Stride) { |
30 | Vector<int> v; |
31 | for (int i = 0; i < 1000; i++) { |
32 | v.PushBack(i); |
33 | EXPECT_EQ(v.Size(), i + 1u); |
34 | EXPECT_EQ(v[i], i); |
35 | } |
36 | for (int i = 0; i < 1000; i++) { |
37 | EXPECT_EQ(v[i], i); |
38 | } |
39 | } |
40 | |
41 | TEST(Vector, ResizeReduction) { |
42 | Vector<int> v; |
43 | v.PushBack(0); |
44 | v.PushBack(0); |
45 | EXPECT_EQ(v.Size(), 2u); |
46 | v.Resize(1); |
47 | EXPECT_EQ(v.Size(), 1u); |
48 | } |
49 | |
50 | } // namespace __sanitizer |
51 | |