llbuffer_tut.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
- /**
- * @file llbuffer_tut.cpp
- * @author Adroit
- * @date 2007-03
- * @brief llbuffer test cases.
- *
- * $LicenseInfo:firstyear=2007&license=viewergpl$
- *
- * Copyright (c) 2007-2010, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include <tut/tut.hpp>
- #include "linden_common.h"
- #include "lltut.h"
- #include "llbuffer.h"
- #include "llerror.h"
- #include "llmemtype.h"
- namespace tut
- {
- struct buffer
- {
- };
- typedef test_group<buffer> buffer_t;
- typedef buffer_t::object buffer_object_t;
- tut::buffer_t tut_buffer("buffer");
- template<> template<>
- void buffer_object_t::test<1>()
- {
- LLChannelDescriptors channelDescriptors;
- ensure("in() and out() functions Failed", (0 == channelDescriptors.in() && 1 == channelDescriptors.out()));
-
- S32 val = 50;
- LLChannelDescriptors channelDescriptors1(val);
- ensure("LLChannelDescriptors in() and out() functions Failed", (50 == channelDescriptors1.in() && 51 == channelDescriptors1.out()));
- }
-
- template<> template<>
- void buffer_object_t::test<2>()
- {
- LLSegment segment;
- ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size()));
- segment.setChannel(50);
- ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50);
- ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50)));
- }
- template<> template<>
- void buffer_object_t::test<3>()
- {
- S32 channel = 30;
- const char str[] = "SecondLife";
- S32 len = sizeof(str);
- LLSegment segment(channel, (U8*)str, len);
- ensure("LLSegment get functions failed", (30 == segment.getChannel() && len == segment.size() && (U8*)str == segment.data()));
- ensure_memory_matches("LLSegment::data() failed", segment.data(), segment.size(), (U8*)str, len);
- ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(channel)));
- }
-
- template<> template<>
- void buffer_object_t::test<4>()
- {
- S32 channel = 50;
- S32 bigSize = 16384*2;
- char str[] = "SecondLife";
- S32 smallSize = sizeof(str);
- LLSegment segment;
- LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384
- S32 requestSize;
- requestSize = 16384-1;
- ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
- // second request for remainign 1 byte
- requestSize = 1;
- ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
- // it should fail now.
- requestSize = 1;
- ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment)));
- LLHeapBuffer buf1(bigSize);
- // requst for more than default size but less than total sizeit should fail now.
- requestSize = 16384 + 1;
- ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
- LLHeapBuffer buf2((U8*) str, smallSize);
- requestSize = smallSize;
- ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0);
- requestSize = smallSize+1;
- ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment)));
- }
- //makeChannelConsumer()
- template<> template<>
- void buffer_object_t::test<5>()
- {
- LLChannelDescriptors inchannelDescriptors(20);
- LLChannelDescriptors outchannelDescriptors = LLBufferArray::makeChannelConsumer(inchannelDescriptors);
- ensure("LLBufferArray::makeChannelConsumer() function Failed", (21 == outchannelDescriptors.in()));
- }
- template<> template<>
- void buffer_object_t::test<6>()
- {
- LLBufferArray bufferArray;
- const char array[] = "SecondLife";
- S32 len = strlen(array);
- LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
- bufferArray.append(channelDescriptors.in(), (U8*)array, len);
- S32 count = bufferArray.countAfter(channelDescriptors.in(), NULL);
- ensure_equals("Appended size is:", count, len);
- }
- //append() and prepend()
- template<> template<>
- void buffer_object_t::test<7>()
- {
- LLBufferArray bufferArray;
- const char array[] = "SecondLife";
- S32 len = strlen(array);
- const char array1[] = "LindenLabs";
- S32 len1 = strlen(array1);
-
- std::string str(array1);
- str.append(array);
-
- LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
- bufferArray.append(channelDescriptors.in(), (U8*)array, len);
- bufferArray.prepend(channelDescriptors.in(), (U8*)array1, len1);
- char buf[100];
- S32 len2 = 20;
- bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
- ensure_equals("readAfter length failed", len2, 20);
-
- buf[len2] = ' ';
- ensure_equals("readAfter/prepend/append failed", buf, str);
- }
- //append()
- template<> template<>
- void buffer_object_t::test<8>()
- {
- LLBufferArray bufferArray;
- const char array[] = "SecondLife";
- S32 len = strlen(array);
- const char array1[] = "LindenLabs";
- S32 len1 = strlen(array1);
-
- std::string str(array);
- str.append(array1);
-
- LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
- bufferArray.append(channelDescriptors.in(), (U8*)array, len);
- bufferArray.append(channelDescriptors.in(), (U8*)array1, len1);
- char buf[100];
- S32 len2 = 20;
- bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
- ensure_equals("readAfter length failed", len2, 20);
-
- buf[len2] = ' ';
- ensure_equals("readAfter/append/append failed", buf, str);
- }
- template<> template<>
- void buffer_object_t::test<9>()
- {
- LLBufferArray bufferArray;
- const char array[] = "SecondLife";
- S32 len = strlen(array) + 1;
- std::string str(array);
- LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
- bufferArray.append(channelDescriptors.in(), (U8*)array, len);
- LLBufferArray bufferArray1;
- ensure("Contents are not copied and the source buffer is not empty", (1 == bufferArray1.takeContents(bufferArray)));
-
- char buf[100];
- S32 len2 = len;
- bufferArray1.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
- ensure_equals("takeContents failed to copy", buf, str);
- }
- //seek()
- template<> template<>
- void buffer_object_t::test<10>()
- {
- const char array[] = "SecondLife is a Virtual World";
- S32 len = strlen(array);
- LLBufferArray bufferArray;
- bufferArray.append(0, (U8*)array, len);
-
- char buf[255];
- S32 len1 = 16;
- U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
- buf[len1] = ' ';
- last = bufferArray.seek(0, last, -2);
- len1 = 15;
- last = bufferArray.readAfter(0, last, (U8*)buf, len1);
- buf[len1] = ' ';
- std::string str(buf);
- ensure_equals("Seek does'nt worked", str, std::string("a Virtual World"));
- }
- template<> template<>
- void buffer_object_t::test<11>()
- {
- const char array[] = "SecondLife is a Virtual World";
- S32 len = strlen(array);
- LLBufferArray bufferArray;
- bufferArray.append(0, (U8*)array, len);
-
- char buf[255];
- S32 len1 = 10;
- U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
- bufferArray.splitAfter(last);
- LLBufferArray::segment_iterator_t iterator = bufferArray.beginSegment();
- ++iterator;
- std::string str(((char*)(*iterator).data()), (*iterator).size());
- ensure_equals("Strings are not equal;splitAfter() operation failed", str, std::string(" is a Virtual World"));
- }
- //makeSegment()->eraseSegment()
- template<> template<>
- void buffer_object_t::test<12>()
- {
- LLBufferArray bufferArray;
- LLChannelDescriptors channelDescriptors;
- LLBufferArray::segment_iterator_t it;
- S32 length = 1000;
- it = bufferArray.makeSegment(channelDescriptors.out(), length);
- ensure("makeSegment() function failed", (it != bufferArray.endSegment()));
- ensure("eraseSegment() function failed", bufferArray.eraseSegment(it));
- ensure("eraseSegment() begin/end should now be same", bufferArray.beginSegment() == bufferArray.endSegment());
- }
- // constructSegmentAfter()
- template<> template<>
- void buffer_object_t::test<13>()
- {
- LLBufferArray bufferArray;
- LLBufferArray::segment_iterator_t it;
- LLSegment segment;
- LLBufferArray::segment_iterator_t end = bufferArray.endSegment();
- it = bufferArray.constructSegmentAfter(NULL, segment);
- ensure("constructSegmentAfter() function failed", (it == end));
- }
- }