Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "SkBitSet.h"
      9 #include "Test.h"
     10 
     11 DEF_TEST(BitSet, reporter) {
     12     SkBitSet set0(65536);
     13     REPORTER_ASSERT(reporter, set0.isBitSet(0) == false);
     14     REPORTER_ASSERT(reporter, set0.isBitSet(32767) == false);
     15     REPORTER_ASSERT(reporter, set0.isBitSet(65535) == false);
     16 
     17     SkBitSet set1(65536);
     18     REPORTER_ASSERT(reporter, set0 == set1);
     19 
     20     set0.setBit(22, true);
     21     REPORTER_ASSERT(reporter, set0.isBitSet(22) == true);
     22     set0.setBit(24, true);
     23     REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
     24     set0.setBit(35, true);  // on a different DWORD
     25     REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
     26     set0.setBit(22, false);
     27     REPORTER_ASSERT(reporter, set0.isBitSet(22) == false);
     28     REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
     29     REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
     30 
     31     SkTDArray<unsigned int> data;
     32     set0.exportTo(&data);
     33     REPORTER_ASSERT(reporter, data.count() == 2);
     34     REPORTER_ASSERT(reporter, data[0] == 24);
     35     REPORTER_ASSERT(reporter, data[1] == 35);
     36 
     37     set1.setBit(12345, true);
     38     set1.orBits(set0);
     39     REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
     40     REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
     41     REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
     42     REPORTER_ASSERT(reporter, set1.isBitSet(24) == true);
     43     REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
     44     REPORTER_ASSERT(reporter, set1 != set0);
     45 
     46     set1.clearAll();
     47     REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
     48     REPORTER_ASSERT(reporter, set1.isBitSet(12345) == false);
     49     REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
     50     REPORTER_ASSERT(reporter, set1.isBitSet(24) == false);
     51     REPORTER_ASSERT(reporter, set1.isBitSet(35) == false);
     52 
     53     set1.orBits(set0);
     54     REPORTER_ASSERT(reporter, set1 == set0);
     55 
     56     SkBitSet set2(1);
     57     SkBitSet set3(1);
     58     SkBitSet set4(4);
     59     SkBitSet set5(33);
     60 
     61     REPORTER_ASSERT(reporter, set2 == set3);
     62     REPORTER_ASSERT(reporter, set2 != set4);
     63     REPORTER_ASSERT(reporter, set2 != set5);
     64 
     65     set2.setBit(0, true);
     66     REPORTER_ASSERT(reporter, set2 != set5);
     67     set5.setBit(0, true);
     68     REPORTER_ASSERT(reporter, set2 != set5);
     69     REPORTER_ASSERT(reporter, set2 != set3);
     70     set3.setBit(0, true);
     71     REPORTER_ASSERT(reporter, set2 == set3);
     72     set3.clearAll();
     73     set3 = set2;
     74     set2 = set2;
     75     REPORTER_ASSERT(reporter, set2 == set3);
     76 }
     77