2
// Copyright (C) 1997 - 2007, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
* \brief Unit tests for RIB input buffer.
22
* \author Chris Foster [chris42f (at) gmail (dot) com]
25
#include "ribinputbuffer.h"
27
#ifndef AQSIS_SYSTEM_WIN32
28
#define BOOST_TEST_DYN_LINK
29
#endif //AQSIS_SYSTEM_WIN32
33
#include <boost/test/auto_unit_test.hpp>
35
using namespace Aqsis;
37
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_sourcepos_test)
39
std::istringstream in("some rib\ncharacters\r\nhere");
40
CqRibInputBuffer inBuf(in);
42
for(int i = 0; i < 7; ++i)
44
BOOST_CHECK_EQUAL(inBuf.get(), 'b');
45
SqSourcePos pos = inBuf.pos();
46
BOOST_CHECK_EQUAL(pos.line, 1);
47
BOOST_CHECK_EQUAL(pos.col, 8);
50
BOOST_CHECK_EQUAL(inBuf.get(), 'c');
52
BOOST_CHECK_EQUAL(pos.line, 2);
53
BOOST_CHECK_EQUAL(pos.col, 1);
55
for(int i = 0; i < 9; ++i)
57
BOOST_CHECK_EQUAL(inBuf.get(), '\r');
58
BOOST_CHECK_EQUAL(inBuf.get(), '\n');
60
BOOST_CHECK_EQUAL(pos.line, 3);
61
BOOST_CHECK_EQUAL(pos.col, 0);
64
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_gzip_test)
66
// Test automatic detection and ungzip'ping of an input stream.
68
// The zippedChars below were generated with the command:
70
// echo -e -n 'some rib\ncharacters\nhere\n' | gzip | hexdump -C | sed -e 's/^[^ ]* *//' -e 's/|.*$//' -e 's/\</0x/g'
71
const unsigned char zippedChars[] = {
72
0x1f, 0x8b, 0x08, 0x00, 0x32, 0xd4, 0xc3, 0x48, 0x00, 0x03, 0x2b, 0xce, 0xcf, 0x4d, 0x55, 0x28,
73
0xca, 0x4c, 0xe2, 0x4a, 0xce, 0x48, 0x2c, 0x4a, 0x4c, 0x2e, 0x49, 0x2d, 0x2a, 0xe6, 0xca, 0x48,
74
0x2d, 0x4a, 0xe5, 0x02, 0x00, 0x0f, 0xc5, 0xdd, 0x8b, 0x19, 0x00, 0x00, 0x00
76
std::string zipStr(zippedChars, zippedChars + sizeof(zippedChars));
77
std::istringstream in(zipStr);
78
CqRibInputBuffer inBuf(in);
80
std::istream::int_type c = 0;
81
std::string extractedStr;
82
while((c = inBuf.get()) != EOF)
85
BOOST_CHECK_EQUAL(extractedStr, "some rib\ncharacters\nhere\n");
88
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_bufwrap_test)
90
// Test that buffer wrapping works correctly.
92
// 5*64 chars, which is enough to cause the buffer of 256 chars to wrap around.
93
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
94
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
95
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
96
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
97
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
99
std::istringstream in(inStr);
100
CqRibInputBuffer inBuf(in);
102
std::istream::int_type c = 0;
103
std::string extractedStr;
104
while((c = inBuf.get()) != EOF)
107
BOOST_CHECK_EQUAL(extractedStr, inStr);