1 /* 2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the Haiku License. 4 */ 5 6 7 #include "common.h" 8 #include "GraphicsDefsTest.h" 9 #include "TestCase.h" 10 #include <TestUtils.h> 11 12 #include <GraphicsDefs.h> 13 14 15 // patterns 16 const pattern _B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; 17 const pattern _B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}}; 18 const pattern _B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}}; 19 20 // colors 21 const rgb_color _B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00}; 22 const rgb_color _B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00}; 23 const uint8 _B_TRANSPARENT_8_BIT = 0xff; 24 25 const uint8 _B_TRANSPARENT_MAGIC_CMAP8 = 0xff; 26 const uint16 _B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce; 27 const uint16 _B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39; 28 const uint32 _B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477; 29 const uint32 _B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700; 30 31 32 // misc. 33 const struct screen_id _B_MAIN_SCREEN_ID = {0}; 34 35 template<class T> void compare(T &a, T &b); 36 37 38 template<> 39 void 40 compare<const pattern>(const pattern &a, const pattern &b) 41 { 42 for (int32 i = 0; i < 8; i++) 43 CHK(a.data[i] == b.data[i]); 44 } 45 46 47 template<> 48 void 49 compare<const rgb_color>(const rgb_color &a, const rgb_color &b) 50 { 51 CHK(a.red == b.red); 52 CHK(a.green == b.green); 53 CHK(a.blue == b.blue); 54 CHK(a.alpha == b.alpha); 55 } 56 57 58 template<class T> 59 void 60 compare(T &a, T &b) 61 { 62 CHK(a == b); 63 } 64 65 66 class ConstantsTest : public BTestCase { 67 public: 68 ConstantsTest(std::string name = ""); 69 70 static Test *suite(void); 71 void test(void); 72 }; 73 74 75 ConstantsTest::ConstantsTest(std::string name) 76 : BTestCase(name) 77 { 78 } 79 80 81 Test * 82 ConstantsTest::suite(void) 83 { 84 return new CppUnit::TestCaller<ConstantsTest>("GraphicsDefs::Constants", &ConstantsTest::test); 85 } 86 87 88 void 89 ConstantsTest::test(void) 90 { 91 #define TEST(type, constant) compare(_##constant, constant) 92 93 TEST(pattern, B_SOLID_LOW); 94 TEST(pattern, B_MIXED_COLORS); 95 TEST(pattern, B_SOLID_HIGH); 96 97 TEST(rgb_color, B_TRANSPARENT_COLOR); 98 TEST(rgb_color, B_TRANSPARENT_32_BIT); 99 TEST(uint8, B_TRANSPARENT_MAGIC_CMAP8); 100 TEST(uint16, B_TRANSPARENT_MAGIC_RGBA15); 101 TEST(uint16, B_TRANSPARENT_MAGIC_RGBA15_BIG); 102 TEST(uint32, B_TRANSPARENT_MAGIC_RGBA32); 103 TEST(uint32, B_TRANSPARENT_MAGIC_RGBA32_BIG); 104 TEST(uint8, B_TRANSPARENT_8_BIT); 105 106 TEST(uint32, B_MAIN_SCREEN_ID.id); 107 108 #undef TEST 109 } 110 111 112 // #pragma mark - 113 114 115 Test * 116 GraphicsDefsTestSuite() 117 { 118 TestSuite *testSuite = new TestSuite(); 119 120 testSuite->addTest(new ConstantsTest("Constants")); 121 122 return testSuite; 123 } 124 125 126 127 128 129 130 131