"Fossies" - the Fresh Open Source Software Archive

Member "aqsis-1.8.2/libs/riutil/ribinputbuffer_test.cpp" (24 Aug 2012, 4396 Bytes) of package /linux/privat/aqsis-1.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Aqsis
    2 // Copyright (C) 2001, Paul C. Gregory and the other authors and contributors
    3 // All rights reserved.
    4 //
    5 // Redistribution and use in source and binary forms, with or without
    6 // modification, are permitted provided that the following conditions are met:
    7 //
    8 // * Redistributions of source code must retain the above copyright notice,
    9 //   this list of conditions and the following disclaimer.
   10 // * Redistributions in binary form must reproduce the above copyright notice,
   11 //   this list of conditions and the following disclaimer in the documentation
   12 //   and/or other materials provided with the distribution.
   13 // * Neither the name of the software's owners nor the names of its
   14 //   contributors may be used to endorse or promote products derived from this
   15 //   software without specific prior written permission.
   16 //
   17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   27 // POSSIBILITY OF SUCH DAMAGE.
   28 //
   29 // (This is the New BSD license)
   30 
   31 /** \file
   32  * \brief Unit tests for RIB input buffer.
   33  * \author Chris Foster  [chris42f (at) gmail (dot) com]
   34  */
   35 
   36 #include "ribinputbuffer.h"
   37 
   38 #define BOOST_TEST_DYN_LINK
   39 
   40 #include <stdio.h>
   41 #include <sstream>
   42 
   43 #include <boost/test/auto_unit_test.hpp>
   44 
   45 using namespace Aqsis;
   46 
   47 BOOST_AUTO_TEST_SUITE(rib_input_buffer_tests)
   48 
   49 BOOST_AUTO_TEST_CASE(RibInputBuffer_sourcepos_test)
   50 {
   51     std::istringstream in("some rib\ncharacters\r\nhere");
   52     RibInputBuffer inBuf(in);
   53 
   54     for(int i = 0; i < 7; ++i)
   55         inBuf.get();
   56     BOOST_CHECK_EQUAL(inBuf.get(), 'b');
   57     SourcePos pos = inBuf.pos();
   58     BOOST_CHECK_EQUAL(pos.line, 1);
   59     BOOST_CHECK_EQUAL(pos.col, 8);
   60 
   61     inBuf.get();
   62     BOOST_CHECK_EQUAL(inBuf.get(), 'c');
   63     pos = inBuf.pos();
   64     BOOST_CHECK_EQUAL(pos.line, 2);
   65     BOOST_CHECK_EQUAL(pos.col, 1);
   66 
   67     for(int i = 0; i < 9; ++i)
   68         inBuf.get();
   69     BOOST_CHECK_EQUAL(inBuf.get(), '\r');
   70     BOOST_CHECK_EQUAL(inBuf.get(), '\n');
   71     pos = inBuf.pos();
   72     BOOST_CHECK_EQUAL(pos.line, 3);
   73     BOOST_CHECK_EQUAL(pos.col, 0);
   74 }
   75 
   76 BOOST_AUTO_TEST_CASE(RibInputBuffer_gzip_test)
   77 {
   78     // Test automatic detection and ungzip'ping of an input stream.
   79     //
   80     // The zippedChars below were generated with the command:
   81     //
   82     // echo -e -n 'some rib\ncharacters\nhere\n' | gzip | hexdump -C | sed -e 's/^[^ ]* *//' -e 's/|.*$//' -e 's/\</0x/g'
   83     const unsigned char zippedChars[] = {
   84         0x1f, 0x8b, 0x08, 0x00, 0x32, 0xd4, 0xc3, 0x48, 0x00, 0x03, 0x2b, 0xce, 0xcf, 0x4d, 0x55, 0x28, 
   85         0xca, 0x4c, 0xe2, 0x4a, 0xce, 0x48, 0x2c, 0x4a, 0x4c, 0x2e, 0x49, 0x2d, 0x2a, 0xe6, 0xca, 0x48, 
   86         0x2d, 0x4a, 0xe5, 0x02, 0x00, 0x0f, 0xc5, 0xdd, 0x8b, 0x19, 0x00, 0x00, 0x00
   87     };
   88     std::string zipStr(zippedChars, zippedChars + sizeof(zippedChars));
   89     std::istringstream in(zipStr);
   90     RibInputBuffer inBuf(in);
   91 
   92     std::istream::int_type c = 0;
   93     std::string extractedStr;
   94     while((c = inBuf.get()) != RibInputBuffer::eof)
   95         extractedStr += c;
   96 
   97     BOOST_CHECK_EQUAL(extractedStr, "some rib\ncharacters\nhere\n");
   98 }
   99 
  100 BOOST_AUTO_TEST_CASE(RibInputBuffer_bufwrap_test)
  101 {
  102     // Test that buffer wrapping works correctly.
  103     std::string inStr(
  104         // 5*64 chars, which is enough to cause the buffer of 256 chars to wrap around.
  105         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
  106         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
  107         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
  108         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
  109         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl"
  110     );
  111     std::istringstream in(inStr);
  112     RibInputBuffer inBuf(in);
  113 
  114     std::istream::int_type c = 0;
  115     std::string extractedStr;
  116     while((c = inBuf.get()) != RibInputBuffer::eof)
  117         extractedStr += c;
  118 
  119     BOOST_CHECK_EQUAL(extractedStr, inStr);
  120 }
  121 
  122 BOOST_AUTO_TEST_SUITE_END()