Mercurial > fife-parpg
comparison ext/UnitTest++/src/tests/TestMemoryOutStream.cpp @ 37:0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
author | jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 12 Jul 2008 12:00:57 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
36:6f1227f4932b | 37:0d325e9d5953 |
---|---|
1 #include "../UnitTest++.h" | |
2 | |
3 #include "../MemoryOutStream.h" | |
4 #include <cstring> | |
5 | |
6 using namespace UnitTest; | |
7 | |
8 namespace { | |
9 | |
10 TEST (DefaultIsEmptyString) | |
11 { | |
12 MemoryOutStream const stream; | |
13 CHECK (stream.GetText() != 0); | |
14 CHECK_EQUAL ("", stream.GetText()); | |
15 } | |
16 | |
17 TEST (StreamingTextCopiesCharacters) | |
18 { | |
19 MemoryOutStream stream; | |
20 stream << "Lalala"; | |
21 CHECK_EQUAL ("Lalala", stream.GetText()); | |
22 } | |
23 | |
24 TEST (StreamingMultipleTimesConcatenatesResult) | |
25 { | |
26 MemoryOutStream stream; | |
27 stream << "Bork" << "Foo" << "Bar"; | |
28 CHECK_EQUAL ("BorkFooBar", stream.GetText()); | |
29 } | |
30 | |
31 TEST (StreamingIntWritesCorrectCharacters) | |
32 { | |
33 MemoryOutStream stream; | |
34 stream << (int)123; | |
35 CHECK_EQUAL ("123", stream.GetText()); | |
36 } | |
37 | |
38 TEST (StreamingUnsignedIntWritesCorrectCharacters) | |
39 { | |
40 MemoryOutStream stream; | |
41 stream << (unsigned int)123; | |
42 CHECK_EQUAL ("123", stream.GetText()); | |
43 } | |
44 | |
45 TEST (StreamingLongWritesCorrectCharacters) | |
46 { | |
47 MemoryOutStream stream; | |
48 stream << (long)(-123); | |
49 CHECK_EQUAL ("-123", stream.GetText()); | |
50 } | |
51 | |
52 TEST (StreamingUnsignedLongWritesCorrectCharacters) | |
53 { | |
54 MemoryOutStream stream; | |
55 stream << (unsigned long)123; | |
56 CHECK_EQUAL ("123", stream.GetText()); | |
57 } | |
58 | |
59 TEST (StreamingFloatWritesCorrectCharacters) | |
60 { | |
61 MemoryOutStream stream; | |
62 stream << 3.1415f; | |
63 CHECK (std::strstr(stream.GetText(), "3.1415")); | |
64 } | |
65 | |
66 TEST (StreamingDoubleWritesCorrectCharacters) | |
67 { | |
68 MemoryOutStream stream; | |
69 stream << 3.1415; | |
70 CHECK (std::strstr(stream.GetText(), "3.1415")); | |
71 } | |
72 | |
73 TEST (StreamingPointerWritesCorrectCharacters) | |
74 { | |
75 MemoryOutStream stream; | |
76 int* p = (int*)0x1234; | |
77 stream << p; | |
78 CHECK (std::strstr(stream.GetText(), "1234")); | |
79 } | |
80 | |
81 TEST (StreamingSizeTWritesCorrectCharacters) | |
82 { | |
83 MemoryOutStream stream; | |
84 size_t const s = 53124; | |
85 stream << s; | |
86 CHECK_EQUAL ("53124", stream.GetText()); | |
87 } | |
88 | |
89 #ifdef UNITTEST_USE_CUSTOM_STREAMS | |
90 | |
91 TEST (StreamInitialCapacityIsCorrect) | |
92 { | |
93 MemoryOutStream stream(MemoryOutStream::GROW_CHUNK_SIZE); | |
94 CHECK_EQUAL ((int)MemoryOutStream::GROW_CHUNK_SIZE, stream.GetCapacity()); | |
95 } | |
96 | |
97 TEST (StreamInitialCapacityIsMultipleOfGrowChunkSize) | |
98 { | |
99 MemoryOutStream stream(MemoryOutStream::GROW_CHUNK_SIZE + 1); | |
100 CHECK_EQUAL ((int)MemoryOutStream::GROW_CHUNK_SIZE * 2, stream.GetCapacity()); | |
101 } | |
102 | |
103 | |
104 TEST (ExceedingCapacityGrowsBuffer) | |
105 { | |
106 MemoryOutStream stream(MemoryOutStream::GROW_CHUNK_SIZE); | |
107 stream << "012345678901234567890123456789"; | |
108 char const* const oldBuffer = stream.GetText(); | |
109 stream << "0123456789"; | |
110 CHECK (oldBuffer != stream.GetText()); | |
111 } | |
112 | |
113 TEST (ExceedingCapacityGrowsBufferByGrowChunk) | |
114 { | |
115 MemoryOutStream stream(MemoryOutStream::GROW_CHUNK_SIZE); | |
116 stream << "0123456789012345678901234567890123456789"; | |
117 CHECK_EQUAL (MemoryOutStream::GROW_CHUNK_SIZE * 2, stream.GetCapacity()); | |
118 } | |
119 | |
120 TEST (WritingStringLongerThanCapacityFitsInNewBuffer) | |
121 { | |
122 MemoryOutStream stream(8); | |
123 stream << "0123456789ABCDEF"; | |
124 CHECK_EQUAL ("0123456789ABCDEF", stream.GetText()); | |
125 } | |
126 | |
127 TEST (WritingIntLongerThanCapacityFitsInNewBuffer) | |
128 { | |
129 MemoryOutStream stream(8); | |
130 stream << "aaaa" << 123456;; | |
131 CHECK_EQUAL ("aaaa123456", stream.GetText()); | |
132 } | |
133 | |
134 TEST (WritingFloatLongerThanCapacityFitsInNewBuffer) | |
135 { | |
136 MemoryOutStream stream(8); | |
137 stream << "aaaa" << 123456.0f;; | |
138 CHECK_EQUAL ("aaaa123456.000000f", stream.GetText()); | |
139 } | |
140 | |
141 TEST (WritingSizeTLongerThanCapacityFitsInNewBuffer) | |
142 { | |
143 MemoryOutStream stream(8); | |
144 stream << "aaaa" << size_t(32145); | |
145 CHECK_EQUAL ("aaaa32145", stream.GetText()); | |
146 } | |
147 | |
148 #endif | |
149 | |
150 } |