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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/**
* \file stream_tests.cpp
* \brief Output stream automated tests.
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
*/
#include "premake.h"
#include "testing/testing.h"
extern "C" {
#include "base/stream.h"
}
struct FxStream
{
Stream strm;
char buffer[1024];
FxStream()
{
strm = stream_create_null();
stream_set_buffer(strm, buffer);
}
~FxStream()
{
stream_destroy(strm);
}
};
struct FxStreamStrings : FxStream
{
Strings strs;
FxStreamStrings()
{
strs = strings_create();
}
~FxStreamStrings()
{
strings_destroy(strs);
}
};
SUITE(base)
{
TEST_FIXTURE(FxStream, Write_WritesValue_OnSimpleValue)
{
stream_write(strm, "Hi there!");
CHECK_EQUAL("Hi there!", buffer);
}
TEST_FIXTURE(FxStream, Write_WritesValue_OnFormattedValue)
{
stream_write(strm, "Hi there, %s!", "Mr. Bill");
CHECK_EQUAL("Hi there, Mr. Bill!", buffer);
}
TEST_FIXTURE(FxStream, WriteLine_AppendsNewLine_OnSimpleValue)
{
stream_writeline(strm, "Hi there!");
CHECK_EQUAL("Hi there!\n", buffer);
}
TEST_FIXTURE(FxStream, WriteLine_AppendsNewLine_OnFormattedValue)
{
stream_writeline(strm, "Hi there, %s!", "Mr. Bill");
CHECK_EQUAL("Hi there, Mr. Bill!\n", buffer);
}
TEST_FIXTURE(FxStream, WriteLine_AppendsNewLine_OnModifiedNewline)
{
stream_set_newline(strm, "\r\n");
stream_writeline(strm, "Hi there!");
CHECK_EQUAL("Hi there!\r\n", buffer);
}
/**********************************************************************
* stream_write_strings() tests
**********************************************************************/
TEST_FIXTURE(FxStreamStrings, WriteStrings_WritesStartEnd_OnEmptyList)
{
stream_write_strings(strm, strs, "^", "<", ">", ",", "$");
CHECK_EQUAL("^$", buffer);
}
TEST_FIXTURE(FxStreamStrings, WriteStrings_WriteSingleItem_OnSingleItem)
{
strings_add(strs, "AAA");
stream_write_strings(strm, strs, "^", "<", ">", ",", "$");
CHECK_EQUAL("^<AAA>$", buffer);
}
TEST_FIXTURE(FxStreamStrings, WriteStrings_WriteMultipleItems_OnMultipleItems)
{
strings_add(strs, "AAA");
strings_add(strs, "BBB");
strings_add(strs, "CCC");
stream_write_strings(strm, strs, "^", "<", ">", ",", "$");
CHECK_EQUAL("^<AAA>,<BBB>,<CCC>$", buffer);
}
}
|