~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to libs/ribparse/ribinputbuffer_test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright (C) 1997 - 2007, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.org
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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
 
19
 
 
20
/** \file
 
21
 * \brief Unit tests for RIB input buffer.
 
22
 * \author Chris Foster  [chris42f (at) gmail (dot) com]
 
23
 */
 
24
 
 
25
#include "ribinputbuffer.h"
 
26
 
 
27
#ifndef AQSIS_SYSTEM_WIN32
 
28
#define BOOST_TEST_DYN_LINK
 
29
#endif //AQSIS_SYSTEM_WIN32
 
30
 
 
31
#include <sstream>
 
32
 
 
33
#include <boost/test/auto_unit_test.hpp>
 
34
 
 
35
using namespace Aqsis;
 
36
 
 
37
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_sourcepos_test)
 
38
{
 
39
        std::istringstream in("some rib\ncharacters\r\nhere");
 
40
        CqRibInputBuffer inBuf(in);
 
41
 
 
42
        for(int i = 0; i < 7; ++i)
 
43
                inBuf.get();
 
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);
 
48
 
 
49
        inBuf.get();
 
50
        BOOST_CHECK_EQUAL(inBuf.get(), 'c');
 
51
        pos = inBuf.pos();
 
52
        BOOST_CHECK_EQUAL(pos.line, 2);
 
53
        BOOST_CHECK_EQUAL(pos.col, 1);
 
54
 
 
55
        for(int i = 0; i < 9; ++i)
 
56
                inBuf.get();
 
57
        BOOST_CHECK_EQUAL(inBuf.get(), '\r');
 
58
        BOOST_CHECK_EQUAL(inBuf.get(), '\n');
 
59
        pos = inBuf.pos();
 
60
        BOOST_CHECK_EQUAL(pos.line, 3);
 
61
        BOOST_CHECK_EQUAL(pos.col, 0);
 
62
}
 
63
 
 
64
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_gzip_test)
 
65
{
 
66
        // Test automatic detection and ungzip'ping of an input stream.
 
67
        //
 
68
        // The zippedChars below were generated with the command:
 
69
        //
 
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
 
75
        };
 
76
        std::string zipStr(zippedChars, zippedChars + sizeof(zippedChars));
 
77
        std::istringstream in(zipStr);
 
78
        CqRibInputBuffer inBuf(in);
 
79
 
 
80
        std::istream::int_type c = 0;
 
81
        std::string extractedStr;
 
82
        while((c = inBuf.get()) != EOF)
 
83
                extractedStr += c;
 
84
 
 
85
        BOOST_CHECK_EQUAL(extractedStr, "some rib\ncharacters\nhere\n");
 
86
}
 
87
 
 
88
BOOST_AUTO_TEST_CASE(CqRibInputBuffer_bufwrap_test)
 
89
{
 
90
        // Test that buffer wrapping works correctly.
 
91
        std::string inStr(
 
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"
 
98
        );
 
99
        std::istringstream in(inStr);
 
100
        CqRibInputBuffer inBuf(in);
 
101
 
 
102
        std::istream::int_type c = 0;
 
103
        std::string extractedStr;
 
104
        while((c = inBuf.get()) != EOF)
 
105
                extractedStr += c;
 
106
 
 
107
        BOOST_CHECK_EQUAL(extractedStr, inStr);
 
108
}