-
Notifications
You must be signed in to change notification settings - Fork 1
/
ring_test.cpp
57 lines (51 loc) · 1.09 KB
/
ring_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
cl /W3 /Zi ring_test.cpp && ring_test
cl /W3 /Zi /Ox ring_test.cpp && ring_test
*/
#include <stdio.h>
#include <stdlib.h>
#include "ring.h"
#ifdef assert
#undef assert
#endif
// The second BREAKME version is useful when debugging
//#define BREAKME (void)0
#ifndef BREAKME
# ifdef _MSC_VER
# define BREAKME __debugbreak()
# else
# define BREAKME __builtin_trap()
# endif
#endif
#define assert(exp) (void) ((exp) || (printf("Error: %s:%d:\n %s\n", __FILE__, __LINE__, #exp), BREAKME, exit(1), 0))
int main(int argc, char** argv)
{
{
ring::Buf<int> b;
int buf[100];
for (int chunk = 1; chunk <= 5; chunk++)
{
for (int loops = 0; loops < 20; loops++)
{
assert(b.Size() == 0);
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < chunk; j++)
buf[j] = i;
assert(b.Write(buf, chunk));
assert(b.Size() == chunk * (i + 1));
}
for (int i = 0; i < 30; i++)
{
assert(b.Read(buf, chunk) == chunk);
for (int j = 0; j < chunk; j++)
assert(buf[j] == i);
}
assert(b.Size() == 0);
int v;
assert(!b.Read(v));
}
}
}
return 0;
}