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
|
#include "klee/Internal/ADT/TreeStream.h"
#include <vector>
#include <cstring>
#include "gtest/gtest.h"
using namespace klee;
/* Basic test, checking that after writing "abc" and then "defg", we
get a {'a', 'b', 'c', 'c', 'd', 'e', 'f', 'g' } back. */
TEST(TreeStreamTest, Basic) {
TreeStreamWriter tsw("tsw1.out");
ASSERT_TRUE(tsw.good());
TreeOStream tos = tsw.open();
tos.write("abc", 3);
tos.write("defg", 4);
tos.flush();
std::vector<unsigned char> out;
tsw.readStream(tos.getID(), out);
ASSERT_EQ(7u, out.size());
for (unsigned char c = 'a'; c <= 'g'; c++)
ASSERT_EQ(c, out[c - 'a']);
}
/* This tests the case when we perform a write with a size larger than
the buffer size, which is a constant set to 4*4096. This test fails
without #704 */
TEST(TreeStreamTest, WriteLargerThanBufferSize) {
TreeStreamWriter tsw("tsw2.out");
ASSERT_TRUE(tsw.good());
TreeOStream tos = tsw.open();
#define NBYTES 5*4096UL
char buf[NBYTES];
memset(buf, 'A', sizeof(buf));
tos.write(buf, NBYTES);
tos.flush();
std::vector<unsigned char> out;
tsw.readStream(tos.getID(), out);
ASSERT_EQ(NBYTES, out.size());
for (unsigned i=0; i<out.size(); i++)
ASSERT_EQ('A', out[i]);
}
|