aboutsummaryrefslogtreecommitdiff
path: root/test/common/stream.h
blob: a605d34a2cbf79f87af8ebb842e3e298cdb3e013 (plain)
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
#include <cxxtest/TestSuite.h>

#include "common/stream.h"

class ReadLineStreamTestSuite : public CxxTest::TestSuite {
	public:
	void test_readline(void) {
		byte contents[] = { 'a', 'b', '\n', '\n', 'c', '\n' };
		Common::MemoryReadStream ms(contents, sizeof(contents));
		
		char buffer[100];
		
		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "ab\n"));

		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "\n"));

		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "c\n"));

		TS_ASSERT(!ms.eos());

		TS_ASSERT(0 == ms.readLine_NEW(buffer, sizeof(buffer)));

		TS_ASSERT(ms.eos());
	}

	void test_readline2(void) {
		byte contents[] = { 'a', 'b', '\n', '\n', 'c' };
		Common::MemoryReadStream ms(contents, sizeof(contents));
		
		char buffer[100];
		
		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "ab\n"));

		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "\n"));

		TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
		TS_ASSERT(0 == strcmp(buffer, "c"));

		TS_ASSERT(ms.eos());
	}
};