Revert "Roll NDK to r11c and extract it into its own repository."
[android_tools.git] / ndk / tests / device / test-gnustl-full / unit / bitset_test.cpp
blob141f646bc6aa7079916f8eab1d16b89aebef5dc0
1 #include <bitset>
2 #include <algorithm>
3 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
4 # include <sstream>
5 #endif
7 #include "cppunit/cppunit_proxy.h"
9 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
10 using namespace std;
11 #endif
14 // TestCase class
16 class BitsetTest : public CPPUNIT_NS::TestCase
18 CPPUNIT_TEST_SUITE(BitsetTest);
19 CPPUNIT_TEST(bitset1);
20 #if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS)
21 CPPUNIT_IGNORE;
22 #endif
23 CPPUNIT_TEST(iostream);
24 CPPUNIT_TEST_SUITE_END();
26 protected:
27 void bitset1();
28 void iostream();
31 CPPUNIT_TEST_SUITE_REGISTRATION(BitsetTest);
34 // tests implementation
36 void BitsetTest::bitset1()
38 bitset<13U> b1(0xFFFF);
39 bitset<13U> b2(0x1111);
40 CPPUNIT_ASSERT(b1.size() == 13);
41 CPPUNIT_ASSERT(b1 == 0x1FFF);
42 CPPUNIT_ASSERT(b2.size() == 13);
43 CPPUNIT_ASSERT(b2 == 0x1111);
45 #if !defined (STLPORT) || !defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
46 b1 = b1 ^ (b2 << 2);
47 CPPUNIT_ASSERT(b1 == 0x1BBB);
49 CPPUNIT_ASSERT(b1.count() == 10);
50 CPPUNIT_ASSERT(b2.count() == 4);
52 # if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
53 size_t __pos = b2._Find_first();
54 CPPUNIT_ASSERT( __pos == 0 );
55 __pos = b2._Find_next(__pos);
56 CPPUNIT_ASSERT( __pos == 4 );
57 __pos = b2._Find_next(__pos);
58 CPPUNIT_ASSERT( __pos == 8 );
59 __pos = b2._Find_next(__pos);
60 CPPUNIT_ASSERT( __pos == 12 );
61 __pos = b2._Find_next(__pos);
62 CPPUNIT_ASSERT( __pos == 13 );
63 # endif
64 #endif
66 #if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
67 string representation = b2.to_string<char, char_traits<char>, allocator<char> >();
68 CPPUNIT_ASSERT( representation == "1000100010001" );
69 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
70 wstring wrepresentation = b2.to_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >();
71 CPPUNIT_ASSERT( wrepresentation == L"1000100010001" );
72 # endif
73 #else
74 CPPUNIT_ASSERT( b2.to_string() == "1000100010001" );
75 #endif
78 void BitsetTest::iostream()
80 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
82 stringstream sstr;
83 bitset<13U> b(0x1111);
84 sstr << b;
85 CPPUNIT_ASSERT( sstr.str() == "1000100010001" );
87 bitset<13U> b1;
88 sstr >> b1;
89 CPPUNIT_ASSERT( b1.test(0) );
90 CPPUNIT_ASSERT( b1.test(4) );
91 CPPUNIT_ASSERT( b1.test(8) );
92 CPPUNIT_ASSERT( b1.test(12) );
94 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
96 wstringstream sstr;
97 bitset<13U> b(0x1111);
98 sstr << b;
99 CPPUNIT_ASSERT( sstr.str() == L"1000100010001" );
101 bitset<13U> b1;
102 sstr >> b1;
103 CPPUNIT_ASSERT( b1.test(0) );
104 CPPUNIT_ASSERT( b1.test(4) );
105 CPPUNIT_ASSERT( b1.test(8) );
106 CPPUNIT_ASSERT( b1.test(12) );
108 # endif
109 #endif