From a2cae290693de0352b55909c55c7f1189b92b951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 26 Jun 2004 17:04:43 +0000 Subject: [PATCH] Added test for GraphicsDefs.h constants. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8182 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/interface/GraphicsDefsTest.cpp | 147 ++++++++++++++++++ src/tests/kits/interface/GraphicsDefsTest.h | 8 + .../kits/interface/InterfaceKitTestAddon.cpp | 9 +- src/tests/kits/interface/Jamfile | 2 + 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 src/tests/kits/interface/GraphicsDefsTest.cpp create mode 100644 src/tests/kits/interface/GraphicsDefsTest.h diff --git a/src/tests/kits/interface/GraphicsDefsTest.cpp b/src/tests/kits/interface/GraphicsDefsTest.cpp new file mode 100644 index 0000000000..d84c2e2e61 --- /dev/null +++ b/src/tests/kits/interface/GraphicsDefsTest.cpp @@ -0,0 +1,147 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include "common.h" +#include "GraphicsDefsTest.h" +#include "TestCase.h" +#include + +#include + + +// patterns +const pattern _B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +const pattern _B_MIXED_COLORS = {{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}}; +const pattern _B_SOLID_LOW = {{0, 0, 0, 0, 0, 0, 0, 0}}; + +// colors +const rgb_color _B_TRANSPARENT_COLOR = {0x77, 0x74, 0x77, 0x00}; +const rgb_color _B_TRANSPARENT_32_BIT = {0x77, 0x74, 0x77, 0x00}; +const uint8 _B_TRANSPARENT_8_BIT = 0xff; + +const uint8 _B_TRANSPARENT_MAGIC_CMAP8 = 0xff; +const uint16 _B_TRANSPARENT_MAGIC_RGBA15 = 0x39ce; +const uint16 _B_TRANSPARENT_MAGIC_RGBA15_BIG = 0xce39; +const uint32 _B_TRANSPARENT_MAGIC_RGBA32 = 0x00777477; +const uint32 _B_TRANSPARENT_MAGIC_RGBA32_BIG = 0x77747700; + + +// misc. +const struct screen_id _B_MAIN_SCREEN_ID = {0}; + +template void compare(T a, T b); + + +/* +template<> +void +compare(const char *prefix, uint16 value) +{ + printf("%s: uint16: %x\n", prefix, value); +} + + +template<> +void +compare(const char *prefix, uint32 value) +{ + printf("%s: uint32: %lx\n", prefix, value); +} +*/ + +template<> +void +compare(const pattern &a, const pattern &b) +{ + for (int32 i = 0; i < 8; i++) + CHK(a.data[i] == b.data[i]); +} + + +template<> +void +compare(const rgb_color a, const rgb_color b) +{ + CHK(a.red == b.red); + CHK(a.green == b.green); + CHK(a.blue == b.blue); + CHK(a.alpha == b.alpha); +} + + +template +void +compare(T a, T b) +{ + CHK(a == b); +} + + +class ConstantsTest : public BTestCase { + public: + ConstantsTest(std::string name = ""); + + static Test *suite(void); + void test(void); +}; + + +ConstantsTest::ConstantsTest(std::string name) + : BTestCase(name) +{ +} + + +Test * +ConstantsTest::suite(void) +{ + return new CppUnit::TestCaller("GraphicsDefs::Constants", &ConstantsTest::test); +} + + +void +ConstantsTest::test(void) +{ +#define TEST(type, constant) compare(_##constant, constant) + + TEST(pattern, B_SOLID_LOW); + TEST(pattern, B_MIXED_COLORS); + TEST(pattern, B_SOLID_HIGH); + + TEST(rgb_color, B_TRANSPARENT_COLOR); + TEST(rgb_color, B_TRANSPARENT_32_BIT); + TEST(uint8, B_TRANSPARENT_MAGIC_CMAP8); + TEST(uint16, B_TRANSPARENT_MAGIC_RGBA15); + TEST(uint16, B_TRANSPARENT_MAGIC_RGBA15_BIG); + TEST(uint32, B_TRANSPARENT_MAGIC_RGBA32); + TEST(uint32, B_TRANSPARENT_MAGIC_RGBA32_BIG); + TEST(uint8, B_TRANSPARENT_8_BIT); + + TEST(uint32, B_MAIN_SCREEN_ID.id); + +#undef TEST +} + + +// #pragma mark - + + +Test * +GraphicsDefsTestSuite() +{ + TestSuite *testSuite = new TestSuite(); + + testSuite->addTest(new ConstantsTest("Constants")); + + return testSuite; +} + + + + + + + diff --git a/src/tests/kits/interface/GraphicsDefsTest.h b/src/tests/kits/interface/GraphicsDefsTest.h new file mode 100644 index 0000000000..b2d47972aa --- /dev/null +++ b/src/tests/kits/interface/GraphicsDefsTest.h @@ -0,0 +1,8 @@ +#ifndef _graphics_defs_test_h_ +#define _graphics_defs_test_h_ + +class CppUnit::Test; + +CppUnit::Test *GraphicsDefsTestSuite(); + +#endif // _graphics_defs_test_h_ diff --git a/src/tests/kits/interface/InterfaceKitTestAddon.cpp b/src/tests/kits/interface/InterfaceKitTestAddon.cpp index a792d5b278..e71ec884ad 100644 --- a/src/tests/kits/interface/InterfaceKitTestAddon.cpp +++ b/src/tests/kits/interface/InterfaceKitTestAddon.cpp @@ -7,8 +7,12 @@ #include "bpolygon/PolygonTest.h" #include "bregion/RegionTest.h" #include "bwidthbuffer/WidthBufferTest.h" +#include "GraphicsDefsTest.h" -BTestSuite* getTestSuite() { + +BTestSuite * +getTestSuite() +{ BTestSuite *suite = new BTestSuite("Interface"); // ##### Add test suites here ##### @@ -17,6 +21,7 @@ BTestSuite* getTestSuite() { suite->addTest("BPolygon", PolygonTestSuite()); suite->addTest("BRegion", RegionTestSuite()); suite->addTest("_BWidthBuffer_", WidthBufferTestSuite()); - + suite->addTest("GraphicsDefs", GraphicsDefsTestSuite()); + return suite; } diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index 3f33893fc9..40b6411a5a 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -14,6 +14,8 @@ SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ; CommonTestLib libinterfacetest.so : InterfaceKitTestAddon.cpp + GraphicsDefsTest.cpp + # BBitmap BitmapTest.cpp BBitmapTester.cpp