1 #include <cppunit/Test.h> 2 #include <cppunit/TestCaller.h> 3 #include <cppunit/TestSuite.h> 4 #include <stdio.h> 5 #include <TestUtils.h> 6 7 #include "BitmapTest.h" 8 #include "Bitmap.h" 9 10 BitmapTest::BitmapTest(std::string name) 11 : BTestCase(name) 12 { 13 } 14 15 CppUnit::Test* 16 BitmapTest::Suite() 17 { 18 CppUnit::TestSuite *suite = new CppUnit::TestSuite("Bitmap"); 19 20 suite->addTest(new CppUnit::TestCaller<BitmapTest>("Bitmap::Resize test", 21 &BitmapTest::ResizeTest)); 22 suite->addTest(new CppUnit::TestCaller<BitmapTest>("Bitmap::Shift test", 23 &BitmapTest::ShiftTest)); 24 25 return suite; 26 } 27 28 void 29 BitmapTest::ResizeTest() 30 { 31 BKernel::Bitmap bitmap(10); 32 bitmap.Set(6); 33 34 CPPUNIT_ASSERT(bitmap.Get(6)); 35 CPPUNIT_ASSERT(!bitmap.Get(5)); 36 CPPUNIT_ASSERT(!bitmap.Get(7)); 37 38 bitmap.Resize(20); 39 40 CPPUNIT_ASSERT(bitmap.Get(6)); 41 CPPUNIT_ASSERT(!bitmap.Get(7)); 42 CPPUNIT_ASSERT(!bitmap.Get(19)); 43 44 bitmap.Resize(200); 45 bitmap.Set(199); 46 47 CPPUNIT_ASSERT(bitmap.Get(6)); 48 CPPUNIT_ASSERT(!bitmap.Get(7)); 49 CPPUNIT_ASSERT(!bitmap.Get(19)); 50 CPPUNIT_ASSERT(bitmap.Get(199)); 51 CPPUNIT_ASSERT(!bitmap.Get(198)); 52 } 53 54 void 55 BitmapTest::ShiftTest() 56 { 57 BKernel::Bitmap bitmap(20); 58 bitmap.Set(6); 59 60 CPPUNIT_ASSERT(bitmap.Get(6)); 61 CPPUNIT_ASSERT(!bitmap.Get(5)); 62 CPPUNIT_ASSERT(!bitmap.Get(7)); 63 64 bitmap.Shift(10); 65 66 CPPUNIT_ASSERT(bitmap.Get(16)); 67 CPPUNIT_ASSERT(!bitmap.Get(15)); 68 CPPUNIT_ASSERT(!bitmap.Get(17)); 69 CPPUNIT_ASSERT(!bitmap.Get(6)); 70 71 bitmap.Shift(-9); 72 73 CPPUNIT_ASSERT(bitmap.Get(7)); 74 CPPUNIT_ASSERT(!bitmap.Get(6)); 75 CPPUNIT_ASSERT(!bitmap.Get(8)); 76 CPPUNIT_ASSERT(!bitmap.Get(16)); 77 78 // Now test cross-element shifting. 79 bitmap.Resize(200); 80 81 CPPUNIT_ASSERT(bitmap.Get(7)); 82 CPPUNIT_ASSERT(!bitmap.Get(6)); 83 84 bitmap.Shift(100); 85 86 CPPUNIT_ASSERT(!bitmap.Get(7)); 87 CPPUNIT_ASSERT(bitmap.Get(107)); 88 CPPUNIT_ASSERT(!bitmap.Get(106)); 89 90 bitmap.Shift(-100); 91 92 CPPUNIT_ASSERT(bitmap.Get(7)); 93 CPPUNIT_ASSERT(!bitmap.Get(107)); 94 CPPUNIT_ASSERT(!bitmap.Get(6)); 95 } 96