memory2buffertest.h

00001 /***************************************************************************
00002 *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003 *   rvinyard@cs.nmsu.edu                                                  *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Lesser General Public License as        *
00007 *   published by the Free Software Foundation version 2.1.                *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU Lesser General Public      *
00015 *   License along with this library; if not, write to the                 *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018 ***************************************************************************/
00019 #ifndef MEMORY2BUFFERTEST_H
00020 #define MEMORY2BUFFERTEST_H
00021 
00022 #include <bit/bit.h>
00023 #include <cppunit/TestFixture.h>
00024 
00025 using namespace bit;
00026 
00027 class Memory2BufferTest : public  CppUnit::TestFixture {
00028   public:
00029 
00030     CPPUNIT_TEST_SUITE( Memory2BufferTest );
00031     CPPUNIT_TEST( end_partial_octet_ends_on_first_octet_boundary );
00032     CPPUNIT_TEST( end_partial_octet_ends_on_second_octet_boundary );
00033     CPPUNIT_TEST( end_whole_octet_ends_on_first_octet_boundary );
00034     CPPUNIT_TEST( end_whole_octet_ends_on_second_octet_boundary );
00035     CPPUNIT_TEST( end_three_bits_ends_on_first_octet_boundary );
00036     CPPUNIT_TEST( end_three_bits_ends_on_second_octet_boundary );
00037     CPPUNIT_TEST( end_two_mid_octets );
00038     CPPUNIT_TEST( end_two_mid_octet_bits );
00039     CPPUNIT_TEST( end_two_bits_into_mid_octet );
00040     CPPUNIT_TEST( end_spanning_octets );
00041     CPPUNIT_TEST( end_spanning_octets2 );
00042     CPPUNIT_TEST( start_partial_octet_ends_on_first_octet_boundary );
00043     CPPUNIT_TEST( start_partial_octet_ends_on_second_octet_boundary );
00044     CPPUNIT_TEST( start_whole_octet_ends_on_first_octet_boundary );
00045     CPPUNIT_TEST( start_whole_octet_ends_on_second_octet_boundary );
00046     CPPUNIT_TEST( start_three_bits_ends_on_first_octet_boundary );
00047     CPPUNIT_TEST( start_three_bits_ends_on_second_octet_boundary );
00048     CPPUNIT_TEST( start_two_mid_octets );
00049     CPPUNIT_TEST( start_two_mid_octet_bits );
00050     CPPUNIT_TEST( start_two_bits_into_mid_octet );
00051     CPPUNIT_TEST( start_spanning_octets );
00052     CPPUNIT_TEST( start_spanning_octets2 );
00053     CPPUNIT_TEST_SUITE_END();
00054 
00055   public:
00056     void setUp() { }
00057 
00058     void tearDown() { }
00059 
00060     void end_partial_octet_ends_on_first_octet_boundary()    { CPPUNIT_ASSERT( 0x1F345678 == mem2buf( 0x89ABCDEF, 4, 4, 4)); }
00061     void end_partial_octet_ends_on_second_octet_boundary()   { CPPUNIT_ASSERT( 0x123F5678 == mem2buf( 0x89ABCDEF, 12, 4, 4));}
00062     void end_whole_octet_ends_on_first_octet_boundary()      { CPPUNIT_ASSERT( 0xEF345678 == mem2buf( 0x89ABCDEF, 0, 8, 8));}
00063     void end_whole_octet_ends_on_second_octet_boundary()     { CPPUNIT_ASSERT( 0x12EF5678 == mem2buf( 0x89ABCDEF, 8, 8, 8));}
00064     void end_three_bits_ends_on_first_octet_boundary()       { CPPUNIT_ASSERT( 0x17345678 == mem2buf( 0x89ABCDEF, 5, 3, 3));}
00065     void end_three_bits_ends_on_second_octet_boundary()      { CPPUNIT_ASSERT( 0x12375678 == mem2buf( 0x89ABCDEF, 13, 3, 3));}
00066     void end_two_mid_octets()                                { CPPUNIT_ASSERT( 0x1CDEF678 == mem2buf( 0x89ABCDEF, 4, 16, 16));}
00067     void end_two_mid_octet_bits()                            { CPPUNIT_ASSERT( 0x16345678 == mem2buf( 0x89ABCDEF, 5, 2, 2));}
00068     void end_two_bits_into_mid_octet()                       { CPPUNIT_ASSERT( 0x0e345678 == mem2buf( 0x89ABCDEF, 2, 4, 2));}
00069     void end_spanning_octets()                               { CPPUNIT_ASSERT( 0x12BCDEF8 == mem2buf( 0x89ABCDEF, 8, 20, 20));}
00070     void end_spanning_octets2()                              { CPPUNIT_ASSERT( 0x1ABCDEF8 == mem2buf( 0x89ABCDEF, 4, 24, 24));}
00071 
00072     void start_partial_octet_ends_on_first_octet_boundary()  { CPPUNIT_ASSERT( 0x18345678 == mem2buf( 0x89ABCDEF, 4, 4, 4, START)); }
00073     void start_partial_octet_ends_on_second_octet_boundary() { CPPUNIT_ASSERT( 0x12385678 == mem2buf( 0x89ABCDEF, 12, 4, 4, START));}
00074     void start_whole_octet_ends_on_first_octet_boundary()    { CPPUNIT_ASSERT( 0x89345678 == mem2buf( 0x89ABCDEF, 0, 8, 8, START));}
00075     void start_whole_octet_ends_on_second_octet_boundary()   { CPPUNIT_ASSERT( 0x12895678 == mem2buf( 0x89ABCDEF, 8, 8, 8, START));}
00076     void start_three_bits_ends_on_first_octet_boundary()     { CPPUNIT_ASSERT( 0x14345678 == mem2buf( 0x89ABCDEF, 5, 3, 3, START));}
00077     void start_three_bits_ends_on_second_octet_boundary()    { CPPUNIT_ASSERT( 0x12355678 == mem2buf( 0xA9ABCDEF, 13, 3, 3, START));}
00078     void start_two_mid_octets()                              { CPPUNIT_ASSERT( 0x189AB678 == mem2buf( 0x89ABCDEF, 4, 16, 16, START));}
00079     void start_two_mid_octet_bits()                          { CPPUNIT_ASSERT( 0x16345678 == mem2buf( 0xC9ABCDEF, 5, 2, 2, START));}
00080     void start_two_bits_into_mid_octet()                     { CPPUNIT_ASSERT( 0x0A345678 == mem2buf( 0x89ABCDEF, 2, 4, 2, START));}
00081     void start_spanning_octets()                             { CPPUNIT_ASSERT( 0x1289ABC8 == mem2buf( 0x89ABCDEF, 8, 20, 20, START));}
00082     void start_spanning_octets2()                            { CPPUNIT_ASSERT( 0x189ABCD8 == mem2buf( 0x89ABCDEF, 4, 24, 24, START));}
00083 
00084     uint32_t mem2buf(uint32_t value, size_t offset, size_t destsize, size_t extract, Location loc=END) {
00085       Buffer b;
00086       uint32_t buf=0x12345678;
00087       value = host_to_be(value);
00088       buf = host_to_be(buf);
00089       b.set_data(&buf, sizeof(buf));
00090       b.pack(&value, sizeof(value), loc, offset, destsize, extract);
00091       buf = *((uint32_t*)b.data());
00092       buf = be_to_host(buf);
00093 //       std::cout << " 0x" << std::hex << buf << std::dec << "  ";
00094       return buf;
00095     }
00096 };
00097 
00098 #endif

Generated on Thu Jul 6 14:38:08 2006 by  doxygen 1.4.6