aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/llbuffer_tut.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:02 -0500
committerJacek Antonelli2008-08-15 23:45:02 -0500
commitd644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch)
tree7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/llbuffer_tut.cpp
parentSecond Life viewer sources 1.17.3.0 (diff)
downloadmeta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz
Second Life viewer sources 1.18.0.6
Diffstat (limited to '')
-rw-r--r--linden/indra/test/llbuffer_tut.cpp270
1 files changed, 270 insertions, 0 deletions
diff --git a/linden/indra/test/llbuffer_tut.cpp b/linden/indra/test/llbuffer_tut.cpp
new file mode 100644
index 0000000..bf58abb
--- /dev/null
+++ b/linden/indra/test/llbuffer_tut.cpp
@@ -0,0 +1,270 @@
1/**
2 * @file llbuffer_tut.cpp
3 * @author Adroit
4 * @date 2007-03
5 * @brief llbuffer test cases.
6 *
7 * Copyright (c) 2007-2007, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 */
30
31#include <tut/tut.h>
32#include "lltut.h"
33#include "llbuffer.h"
34#include "llmemtype.h"
35
36namespace tut
37{
38 struct buffer
39 {
40 };
41
42 typedef test_group<buffer> buffer_t;
43 typedef buffer_t::object buffer_object_t;
44 tut::buffer_t tut_buffer("buffer");
45
46 template<> template<>
47 void buffer_object_t::test<1>()
48 {
49 LLChannelDescriptors channelDescriptors;
50 ensure("in() and out() functions Failed", (0 == channelDescriptors.in() && 1 == channelDescriptors.out()));
51
52 S32 val = 50;
53 LLChannelDescriptors channelDescriptors1(val);
54 ensure("LLChannelDescriptors in() and out() functions Failed", (50 == channelDescriptors1.in() && 51 == channelDescriptors1.out()));
55 }
56
57 template<> template<>
58 void buffer_object_t::test<2>()
59 {
60 LLSegment segment;
61 ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size()));
62 segment.setChannel(50);
63 ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50);
64 ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50)));
65 }
66
67 template<> template<>
68 void buffer_object_t::test<3>()
69 {
70 S32 channel = 30;
71 const char str[] = "SecondLife";
72 S32 len = sizeof(str);
73 LLSegment segment(channel, (U8*)str, len);
74 ensure("LLSegment get functions failed", (30 == segment.getChannel() && len == segment.size() && (U8*)str == segment.data()));
75 ensure_memory_matches("LLSegment::data() failed", segment.data(), segment.size(), (U8*)str, len);
76 ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(channel)));
77 }
78
79 template<> template<>
80 void buffer_object_t::test<4>()
81 {
82 S32 channel = 50;
83 S32 bigSize = 16384*2;
84 char str[] = "SecondLife";
85 S32 smallSize = sizeof(str);
86
87 LLSegment segment;
88 LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384
89
90 S32 requestSize;
91
92 requestSize = 16384-1;
93 ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
94 // second request for remainign 1 byte
95
96 requestSize = 1;
97 ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
98
99 // it should fail now.
100 requestSize = 1;
101 ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment)));
102
103 LLHeapBuffer buf1(bigSize);
104
105 // requst for more than default size but less than total sizeit should fail now.
106 requestSize = 16384 + 1;
107 ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
108
109 LLHeapBuffer buf2((U8*) str, smallSize);
110 requestSize = smallSize;
111 ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0);
112 requestSize = smallSize+1;
113 ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment)));
114 }
115
116 //makeChannelConsumer()
117 template<> template<>
118 void buffer_object_t::test<5>()
119 {
120 LLChannelDescriptors inchannelDescriptors(20);
121 LLChannelDescriptors outchannelDescriptors = LLBufferArray::makeChannelConsumer(inchannelDescriptors);
122 ensure("LLBufferArray::makeChannelConsumer() function Failed", (21 == outchannelDescriptors.in()));
123 }
124
125 template<> template<>
126 void buffer_object_t::test<6>()
127 {
128 LLBufferArray bufferArray;
129 const char array[] = "SecondLife";
130 S32 len = strlen(array);
131 LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
132 bufferArray.append(channelDescriptors.in(), (U8*)array, len);
133 S32 count = bufferArray.countAfter(channelDescriptors.in(), NULL);
134 ensure_equals("Appended size is:", count, len);
135 }
136
137 //append() and prepend()
138 template<> template<>
139 void buffer_object_t::test<7>()
140 {
141 LLBufferArray bufferArray;
142 const char array[] = "SecondLife";
143 S32 len = strlen(array);
144 const char array1[] = "LindenLabs";
145 S32 len1 = strlen(array1);
146
147 std::string str(array1);
148 str.append(array);
149
150 LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
151 bufferArray.append(channelDescriptors.in(), (U8*)array, len);
152 bufferArray.prepend(channelDescriptors.in(), (U8*)array1, len1);
153 char buf[100];
154 S32 len2 = 20;
155 bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
156 ensure_equals("readAfter length failed", len2, 20);
157
158 buf[len2] = '\0';
159 ensure_equals("readAfter/prepend/append failed", buf, str);
160 }
161
162 //append()
163 template<> template<>
164 void buffer_object_t::test<8>()
165 {
166 LLBufferArray bufferArray;
167 const char array[] = "SecondLife";
168 S32 len = strlen(array);
169 const char array1[] = "LindenLabs";
170 S32 len1 = strlen(array1);
171
172 std::string str(array);
173 str.append(array1);
174
175 LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
176 bufferArray.append(channelDescriptors.in(), (U8*)array, len);
177 bufferArray.append(channelDescriptors.in(), (U8*)array1, len1);
178 char buf[100];
179 S32 len2 = 20;
180 bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
181 ensure_equals("readAfter length failed", len2, 20);
182
183 buf[len2] = '\0';
184 ensure_equals("readAfter/append/append failed", buf, str);
185 }
186
187 template<> template<>
188 void buffer_object_t::test<9>()
189 {
190 LLBufferArray bufferArray;
191 const char array[] = "SecondLife";
192 S32 len = strlen(array) + 1;
193 std::string str(array);
194 LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
195 bufferArray.append(channelDescriptors.in(), (U8*)array, len);
196 LLBufferArray bufferArray1;
197 ensure("Contents are not copied and the source buffer is not empty", (1 == bufferArray1.takeContents(bufferArray)));
198
199 char buf[100];
200 S32 len2 = len;
201 bufferArray1.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
202 ensure_equals("takeContents failed to copy", buf, str);
203 }
204
205 //seek()
206 template<> template<>
207 void buffer_object_t::test<10>()
208 {
209 const char array[] = "SecondLife is a Virtual World";
210 S32 len = strlen(array);
211 LLBufferArray bufferArray;
212 bufferArray.append(0, (U8*)array, len);
213
214 char buf[255];
215 S32 len1 = 16;
216 U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
217 buf[len1] = '\0';
218 last = bufferArray.seek(0, last, -2);
219
220 len1 = 15;
221 last = bufferArray.readAfter(0, last, (U8*)buf, len1);
222 buf[len1] = '\0';
223 std::string str(buf);
224 ensure_equals("Seek does'nt worked", str, std::string("a Virtual World"));
225 }
226
227 template<> template<>
228 void buffer_object_t::test<11>()
229 {
230 const char array[] = "SecondLife is a Virtual World";
231 S32 len = strlen(array);
232 LLBufferArray bufferArray;
233 bufferArray.append(0, (U8*)array, len);
234
235 char buf[255];
236 S32 len1 = 10;
237 U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
238 bufferArray.splitAfter(last);
239 LLBufferArray::segment_iterator_t iterator = bufferArray.beginSegment();
240 ++iterator;
241 std::string str(((char*)(*iterator).data()), (*iterator).size());
242 ensure_equals("Strings are not equal;splitAfter() operation failed", str, std::string(" is a Virtual World"));
243 }
244
245 //makeSegment()->eraseSegment()
246 template<> template<>
247 void buffer_object_t::test<12>()
248 {
249 LLBufferArray bufferArray;
250 LLChannelDescriptors channelDescriptors;
251 LLBufferArray::segment_iterator_t it;
252 S32 length = 1000;
253 it = bufferArray.makeSegment(channelDescriptors.out(), length);
254 ensure("makeSegment() function failed", (it != bufferArray.endSegment()));
255 ensure("eraseSegment() function failed", bufferArray.eraseSegment(it));
256 ensure("eraseSegment() begin/end should now be same", bufferArray.beginSegment() == bufferArray.endSegment());
257 }
258
259 // constructSegmentAfter()
260 template<> template<>
261 void buffer_object_t::test<13>()
262 {
263 LLBufferArray bufferArray;
264 LLBufferArray::segment_iterator_t it;
265 LLSegment segment;
266 LLBufferArray::segment_iterator_t end = bufferArray.endSegment();
267 it = bufferArray.constructSegmentAfter(NULL, segment);
268 ensure("constructSegmentAfter() function failed", (it == end));
269 }
270}