Home | History | Annotate | Download | only in unit
      1 //===-- tsan_vector_test.cc -----------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of ThreadSanitizer (TSan), a race detector.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 #include "tsan_vector.h"
     14 #include "tsan_rtl.h"
     15 #include "gtest/gtest.h"
     16 
     17 namespace __tsan {
     18 
     19 TEST(Vector, Basic) {
     20   Vector<int> v(MBlockScopedBuf);
     21   EXPECT_EQ(v.Size(), (uptr)0);
     22   v.PushBack(42);
     23   EXPECT_EQ(v.Size(), (uptr)1);
     24   EXPECT_EQ(v[0], 42);
     25   v.PushBack(43);
     26   EXPECT_EQ(v.Size(), (uptr)2);
     27   EXPECT_EQ(v[0], 42);
     28   EXPECT_EQ(v[1], 43);
     29 }
     30 
     31 TEST(Vector, Stride) {
     32   Vector<int> v(MBlockScopedBuf);
     33   for (int i = 0; i < 1000; i++) {
     34     v.PushBack(i);
     35     EXPECT_EQ(v.Size(), (uptr)(i + 1));
     36     EXPECT_EQ(v[i], i);
     37   }
     38   for (int i = 0; i < 1000; i++) {
     39     EXPECT_EQ(v[i], i);
     40   }
     41 }
     42 
     43 }  // namespace __tsan
     44