Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbitset_test.cpp
Go to the documentation of this file.
00001 #include <bitset> 00002 #include <algorithm> 00003 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) 00004 # include <sstream> 00005 #endif 00006 00007 #include "cppunit/cppunit_proxy.h" 00008 00009 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00010 using namespace std; 00011 #endif 00012 00013 // 00014 // TestCase class 00015 // 00016 class BitsetTest : public CPPUNIT_NS::TestCase 00017 { 00018 CPPUNIT_TEST_SUITE(BitsetTest); 00019 CPPUNIT_TEST(bitset1); 00020 #if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS) 00021 CPPUNIT_IGNORE; 00022 #endif 00023 CPPUNIT_TEST(iostream); 00024 CPPUNIT_TEST_SUITE_END(); 00025 00026 protected: 00027 void bitset1(); 00028 void iostream(); 00029 }; 00030 00031 CPPUNIT_TEST_SUITE_REGISTRATION(BitsetTest); 00032 00033 // 00034 // tests implementation 00035 // 00036 void BitsetTest::bitset1() 00037 { 00038 bitset<13U> b1(0xFFFF); 00039 bitset<13U> b2(0x1111); 00040 CPPUNIT_ASSERT(b1.size() == 13); 00041 CPPUNIT_ASSERT(b1 == 0x1FFF); 00042 CPPUNIT_ASSERT(b2.size() == 13); 00043 CPPUNIT_ASSERT(b2 == 0x1111); 00044 00045 #if !defined (STLPORT) || !defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) 00046 b1 = b1 ^ (b2 << 2); 00047 CPPUNIT_ASSERT(b1 == 0x1BBB); 00048 00049 CPPUNIT_ASSERT(b1.count() == 10); 00050 CPPUNIT_ASSERT(b2.count() == 4); 00051 00052 # if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) 00053 size_t __pos = b2._Find_first(); 00054 CPPUNIT_ASSERT( __pos == 0 ); 00055 __pos = b2._Find_next(__pos); 00056 CPPUNIT_ASSERT( __pos == 4 ); 00057 __pos = b2._Find_next(__pos); 00058 CPPUNIT_ASSERT( __pos == 8 ); 00059 __pos = b2._Find_next(__pos); 00060 CPPUNIT_ASSERT( __pos == 12 ); 00061 __pos = b2._Find_next(__pos); 00062 CPPUNIT_ASSERT( __pos == 13 ); 00063 # endif 00064 #endif 00065 00066 #if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) 00067 string representation = b2.to_string<char, char_traits<char>, allocator<char> >(); 00068 CPPUNIT_ASSERT( representation == "1000100010001" ); 00069 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) 00070 wstring wrepresentation = b2.to_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >(); 00071 CPPUNIT_ASSERT( wrepresentation == L"1000100010001" ); 00072 # endif 00073 #else 00074 CPPUNIT_ASSERT( b2.to_string() == "1000100010001" ); 00075 #endif 00076 } 00077 00078 void BitsetTest::iostream() 00079 { 00080 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) 00081 { 00082 stringstream sstr; 00083 bitset<13U> b(0x1111); 00084 sstr << b; 00085 CPPUNIT_ASSERT( sstr.str() == "1000100010001" ); 00086 00087 bitset<13U> b1; 00088 sstr >> b1; 00089 CPPUNIT_ASSERT( b1.test(0) ); 00090 CPPUNIT_ASSERT( b1.test(4) ); 00091 CPPUNIT_ASSERT( b1.test(8) ); 00092 CPPUNIT_ASSERT( b1.test(12) ); 00093 } 00094 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) 00095 { 00096 wstringstream sstr; 00097 bitset<13U> b(0x1111); 00098 sstr << b; 00099 CPPUNIT_ASSERT( sstr.str() == L"1000100010001" ); 00100 00101 bitset<13U> b1; 00102 sstr >> b1; 00103 CPPUNIT_ASSERT( b1.test(0) ); 00104 CPPUNIT_ASSERT( b1.test(4) ); 00105 CPPUNIT_ASSERT( b1.test(8) ); 00106 CPPUNIT_ASSERT( b1.test(12) ); 00107 } 00108 # endif 00109 #endif 00110 } Generated on Sun May 27 2012 04:35:19 for ReactOS by
1.7.6.1
|