1 // RUN: %clangxx_unit -O0 %s -o %t 2>&1
2 // RUN: %env_esan_opts="record_snapshots=0" %run %t 2>&1 | FileCheck %s
4 #include "esan/esan_circular_buffer.h"
5 #include "sanitizer_common/sanitizer_placement_new.h"
9 static const int TestBufCapacity = 4;
11 // The buffer should have a capacity of TestBufCapacity.
12 void testBuffer(__esan::CircularBuffer<int> *Buf) {
13 assert(Buf->size() == 0);
17 assert(Buf->back() == 1);
18 assert((*Buf)[0] == 1);
19 assert(Buf->size() == 1);
20 assert(!Buf->empty());
26 assert((*Buf)[0] == 2);
27 assert(Buf->size() == 4);
30 assert((*Buf)[0] == 2);
31 assert(Buf->size() == 3);
35 assert((*Buf)[0] == 2);
36 assert(Buf->size() == 1);
37 assert(!Buf->empty());
45 // Test initialize/free.
46 __esan::CircularBuffer<int> GlobalBuf;
47 GlobalBuf.initialize(TestBufCapacity);
48 testBuffer(&GlobalBuf);
51 // Test constructor/free.
52 __esan::CircularBuffer<int> *LocalBuf;
53 static char placeholder[sizeof(*LocalBuf)];
54 LocalBuf = new(placeholder) __esan::CircularBuffer<int>(TestBufCapacity);
58 fprintf(stderr, "All checks passed.\n");
59 // CHECK: All checks passed.