1/*
2** Copyright 2004, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the MIT 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
16const pattern _B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
17const pattern _B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}};
18const pattern _B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}};
19
20// colors
21const rgb_color	_B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00};
22const rgb_color	_B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00};
23const uint8 _B_TRANSPARENT_8_BIT = 0xff;
24
25const uint8 _B_TRANSPARENT_MAGIC_CMAP8 = 0xff;
26const uint16 _B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce;
27const uint16 _B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39;
28const uint32 _B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477;
29const uint32 _B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700;
30
31
32// misc.
33const struct screen_id _B_MAIN_SCREEN_ID = {0};
34
35template<class T> void compare(T &a, T &b);
36
37
38template<>
39void
40compare<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
47template<>
48void
49compare<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
58template<class T>
59void
60compare(T &a, T &b)
61{
62	CHK(a == b);
63}
64
65
66class ConstantsTest : public BTestCase {
67	public:
68		ConstantsTest(std::string name = "");
69
70		static Test *suite(void);
71		void test(void);
72};
73
74
75ConstantsTest::ConstantsTest(std::string name)
76	: BTestCase(name)
77{
78}
79
80
81Test *
82ConstantsTest::suite(void)
83{
84	return new CppUnit::TestCaller<ConstantsTest>("GraphicsDefs::Constants", &ConstantsTest::test);
85}
86
87
88void
89ConstantsTest::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
115Test *
116GraphicsDefsTestSuite()
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