Home | History | Annotate | Download | only in unit
      1 #include <vector>
      2 
      3 #include "cppunit/cppunit_proxy.h"
      4 
      5 #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
      6 using namespace std;
      7 #endif
      8 
      9 //
     10 // TestCase class
     11 //
     12 class BvectorTest : public CPPUNIT_NS::TestCase
     13 {
     14   CPPUNIT_TEST_SUITE(BvectorTest);
     15 #if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
     16   CPPUNIT_IGNORE;
     17 #endif
     18   CPPUNIT_TEST(bvec1);
     19   CPPUNIT_TEST_SUITE_END();
     20 
     21 protected:
     22   void bvec1();
     23 };
     24 
     25 CPPUNIT_TEST_SUITE_REGISTRATION(BvectorTest);
     26 
     27 //
     28 // tests implementation
     29 //
     30 void BvectorTest::bvec1()
     31 {
     32 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
     33   bool ii[3]= {1,0,1};
     34   bit_vector b(3);
     35 
     36   CPPUNIT_ASSERT(b[0]==0);
     37   CPPUNIT_ASSERT(b[1]==0);
     38   CPPUNIT_ASSERT(b[2]==0);
     39 
     40   b[0] = b[2] = 1;
     41 
     42   CPPUNIT_ASSERT(b[0]==1);
     43   CPPUNIT_ASSERT(b[1]==0);
     44   CPPUNIT_ASSERT(b[2]==1);
     45 
     46   b.insert(b.begin(),(bool*)ii, ii+2);
     47 
     48   CPPUNIT_ASSERT(b[0]==1);
     49   CPPUNIT_ASSERT(b[1]==0);
     50   CPPUNIT_ASSERT(b[2]==1);
     51   CPPUNIT_ASSERT(b[3]==0);
     52   CPPUNIT_ASSERT(b[4]==1);
     53 
     54   bit_vector bb = b;
     55   if (bb != b)
     56     exit(1);
     57 
     58   b[0] |= 0;
     59   b[1] |= 0;
     60   b[2] |= 1;
     61   b[3] |= 1;
     62   CPPUNIT_ASSERT(!((b[0] != 1) || (b[1] != 0) || (b[2] != 1) || (b[3] != 1)));
     63 
     64 
     65   bb[0] &= 0;
     66   bb[1] &= 0;
     67   bb[2] &= 1;
     68   bb[3] &= 1;
     69   CPPUNIT_ASSERT(!((bb[0] != 0) || (bb[1] != 0) || (bb[2] != 1) || (bb[3] != 0)));
     70 #endif
     71 }
     72