aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/io.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/io.cpp')
-rw-r--r--linden/indra/test/io.cpp129
1 files changed, 128 insertions, 1 deletions
diff --git a/linden/indra/test/io.cpp b/linden/indra/test/io.cpp
index a86711a..412c010 100644
--- a/linden/indra/test/io.cpp
+++ b/linden/indra/test/io.cpp
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (c) 2005-2007, Linden Research, Inc. 7 * Copyright (c) 2005-2007, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0 11 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -50,6 +51,101 @@
50 51
51namespace tut 52namespace tut
52{ 53{
54 struct heap_buffer_data
55 {
56 heap_buffer_data() : mBuffer(NULL) {}
57 ~heap_buffer_data() { if(mBuffer) delete mBuffer; }
58 LLHeapBuffer* mBuffer;
59 };
60 typedef test_group<heap_buffer_data> heap_buffer_test;
61 typedef heap_buffer_test::object heap_buffer_object;
62 tut::heap_buffer_test thb("heap_buffer");
63
64 template<> template<>
65 void heap_buffer_object::test<1>()
66 {
67 const S32 BUF_SIZE = 100;
68 mBuffer = new LLHeapBuffer(BUF_SIZE);
69 ensure_equals("empty buffer capacity", mBuffer->capacity(), BUF_SIZE);
70 const S32 SEGMENT_SIZE = 50;
71 LLSegment segment;
72 mBuffer->createSegment(0, SEGMENT_SIZE, segment);
73 ensure_equals("used buffer capacity", mBuffer->capacity(), BUF_SIZE);
74 }
75
76 template<> template<>
77 void heap_buffer_object::test<2>()
78 {
79 const S32 BUF_SIZE = 10;
80 mBuffer = new LLHeapBuffer(BUF_SIZE);
81 LLSegment segment;
82 mBuffer->createSegment(0, BUF_SIZE, segment);
83 ensure("segment is in buffer", mBuffer->containsSegment(segment));
84 ensure_equals("buffer consumed", mBuffer->bytesLeft(), 0);
85 bool created;
86 created = mBuffer->createSegment(0, 0, segment);
87 ensure("Create zero size segment fails", !created);
88 created = mBuffer->createSegment(0, BUF_SIZE, segment);
89 ensure("Create segment fails", !created);
90 }
91
92 template<> template<>
93 void heap_buffer_object::test<3>()
94 {
95 const S32 BUF_SIZE = 10;
96 mBuffer = new LLHeapBuffer(BUF_SIZE);
97 LLSegment segment;
98 mBuffer->createSegment(0, BUF_SIZE, segment);
99 ensure("segment is in buffer", mBuffer->containsSegment(segment));
100 ensure_equals("buffer consumed", mBuffer->bytesLeft(), 0);
101 bool reclaimed = mBuffer->reclaimSegment(segment);
102 ensure("buffer reclaimed.", reclaimed);
103 ensure_equals("buffer available", mBuffer->bytesLeft(), BUF_SIZE);
104 bool created;
105 created = mBuffer->createSegment(0, 0, segment);
106 ensure("Create zero size segment fails", !created);
107 created = mBuffer->createSegment(0, BUF_SIZE, segment);
108 ensure("Create another segment succeeds", created);
109 }
110
111 template<> template<>
112 void heap_buffer_object::test<4>()
113 {
114 const S32 BUF_SIZE = 10;
115 const S32 SEGMENT_SIZE = 4;
116 mBuffer = new LLHeapBuffer(BUF_SIZE);
117 LLSegment seg1;
118 mBuffer->createSegment(0, SEGMENT_SIZE, seg1);
119 ensure("segment is in buffer", mBuffer->containsSegment(seg1));
120 LLSegment seg2;
121 mBuffer->createSegment(0, SEGMENT_SIZE, seg2);
122 ensure("segment is in buffer", mBuffer->containsSegment(seg2));
123 LLSegment seg3;
124 mBuffer->createSegment(0, SEGMENT_SIZE, seg3);
125 ensure("segment is in buffer", mBuffer->containsSegment(seg3));
126 ensure_equals("segment is truncated", seg3.size(), 2);
127 LLSegment seg4;
128 bool created;
129 created = mBuffer->createSegment(0, SEGMENT_SIZE, seg4);
130 ensure("Create segment fails", !created);
131 bool reclaimed;
132 reclaimed = mBuffer->reclaimSegment(seg1);
133 ensure("buffer reclaim succeed.", reclaimed);
134 ensure_equals("no buffer available", mBuffer->bytesLeft(), 0);
135 reclaimed = mBuffer->reclaimSegment(seg2);
136 ensure("buffer reclaim succeed.", reclaimed);
137 ensure_equals("buffer reclaimed", mBuffer->bytesLeft(), 0);
138 reclaimed = mBuffer->reclaimSegment(seg3);
139 ensure("buffer reclaim succeed.", reclaimed);
140 ensure_equals("buffer reclaimed", mBuffer->bytesLeft(), BUF_SIZE);
141 created = mBuffer->createSegment(0, SEGMENT_SIZE, seg1);
142 ensure("segment is in buffer", mBuffer->containsSegment(seg1));
143 ensure("Create segment succeds", created);
144 }
145}
146
147namespace tut
148{
53 struct buffer_data 149 struct buffer_data
54 { 150 {
55 LLBufferArray mBuffer; 151 LLBufferArray mBuffer;
@@ -228,6 +324,37 @@ namespace tut
228 delete[] temp; 324 delete[] temp;
229 } 325 }
230 326
327 template<> template<>
328 void buffer_object::test<9>()
329 {
330 LLChannelDescriptors ch = mBuffer.nextChannel();
331 mBuffer.append(ch.in(), (U8*)"1", 1);
332 S32 capacity = mBuffer.capacity();
333 ensure("has capacity", capacity > 0);
334 U8* temp = new U8[capacity - 1];
335 mBuffer.append(ch.in(), temp, capacity - 1);
336 capacity = mBuffer.capacity();
337 ensure("has capacity when full", capacity > 0);
338 S32 used = mBuffer.countAfter(ch.in(), NULL);
339 ensure_equals("used equals capacity", used, capacity);
340
341 LLBufferArray::segment_iterator_t iter = mBuffer.beginSegment();
342 while(iter != mBuffer.endSegment())
343 {
344 mBuffer.eraseSegment(iter++);
345 }
346
347 used = mBuffer.countAfter(ch.in(), NULL);
348 ensure_equals("used is zero", used, 0);
349 S32 capacity2 = mBuffer.capacity();
350 ensure_equals("capacity the same after erase", capacity2, capacity);
351 mBuffer.append(ch.in(), temp, capacity - 1);
352 capacity2 = mBuffer.capacity();
353 ensure_equals("capacity the same after append", capacity2, capacity);
354
355 delete[] temp;
356 }
357
231#if 0 358#if 0
232 template<> template<> 359 template<> template<>
233 void buffer_object::test<9>() 360 void buffer_object::test<9>()
@@ -287,7 +414,7 @@ namespace tut
287 void bas_object::test<1>() 414 void bas_object::test<1>()
288 { 415 {
289 const char HELLO_WORLD[] = "hello world"; 416 const char HELLO_WORLD[] = "hello world";
290 const S32 str_len = strlen(HELLO_WORLD); /* Flawfinder: ignore */ 417 const S32 str_len = strlen(HELLO_WORLD); /* Flawfinder: ignore */
291 LLChannelDescriptors ch = mBuffer.nextChannel(); 418 LLChannelDescriptors ch = mBuffer.nextChannel();
292 LLBufferStream str(ch, &mBuffer); 419 LLBufferStream str(ch, &mBuffer);
293 mBuffer.append(ch.in(), (U8*)HELLO_WORLD, str_len); 420 mBuffer.append(ch.in(), (U8*)HELLO_WORLD, str_len);