cleartest.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 CLEARTEST_H
00020 #define CLEARTEST_H
00021 
00022 #include <cppunit/TestFixture.h>
00023 
00024 using namespace bit;
00025 
00026 class ClearTest : public  CppUnit::TestFixture {
00027   public:
00028 
00029     CPPUNIT_TEST_SUITE( ClearTest );
00030     CPPUNIT_TEST( bits_28_and_29 );
00031     CPPUNIT_TEST( middle_octets );
00032     CPPUNIT_TEST( lead_bits );
00033     CPPUNIT_TEST( trailing_bits );
00034     CPPUNIT_TEST( spanning_octets );
00035     CPPUNIT_TEST_SUITE_END();
00036 
00037   public:
00038     void setUp() { }
00039 
00040     void tearDown() { }
00041 
00042     void bits_28_and_29() { CPPUNIT_ASSERT( 0xfffffff3 == clear_bits( 0xffffffff, 28, 2) ); }
00043     void middle_octets() { CPPUNIT_ASSERT( 0xff0000ff == clear_bits( 0xffffffff, 8, 16) ); }
00044     void lead_bits() { CPPUNIT_ASSERT( 0xff0fffff == clear_bits( 0xffffffff, 8, 4) ); }
00045     void trailing_bits() { CPPUNIT_ASSERT( 0xfff0ffff == clear_bits( 0xffffffff, 12, 4) ); }
00046     void spanning_octets() { CPPUNIT_ASSERT( 0xf000000f == clear_bits( 0xffffffff, 4, 24) ); }
00047 
00048     uint32_t clear_bits(uint32_t value, size_t offset, size_t bits) {
00049       Buffer b;
00050       value = host_to_be(value);
00051       b.set_data(&value, sizeof(value));
00052       b.clear_bits(offset, bits);
00053       value = *((uint32_t*)b.data());
00054       value = be_to_host(value);
00055       return value;
00056     }
00057 };
00058 
00059 #endif

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