diff --git a/src/tests/kits/interface/bbitmap/BBitmapCases b/src/tests/kits/interface/bbitmap/BBitmapCases new file mode 100644 index 0000000000..00b122ef1a --- /dev/null +++ b/src/tests/kits/interface/bbitmap/BBitmapCases @@ -0,0 +1,32 @@ +BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews, + bool needsContiguous) +case 1: acceptsViews = false, needsContiguous = false, valid bounds, + different color spaces => + Bits() should be valid, BitsLength(), BytesPerRow() etc. should return + the correct values. +TODO: ... + +void SetBits(const void *data, int32 length, int32 offset, + color_space colorSpace) +case 1: overwrite complete bitmap data, offset = 0, different color spaces, + no row padding => + Bitmap should contain the correct data. +case 2: overwrite complete bitmap data, offset = 0, different color spaces, + row padding => + Bitmap should contain the correct data. +case 3: overwrite bitmap data partially, offset = 0, different color spaces, + no row padding => + Bitmap should contain the correct data. +case 4: overwrite bitmap data partially, offset = 0, different color spaces, + row padding => + Bitmap should contain the correct data. + +status_t ImportBits(const BBitmap *bitmap) +case 1: NULL bitmap => + Should return B_BAD_VALUE. +case 2: bitmap with different Bounds() => + Should return B_BAD_VALUE. +case 3: this and bitmap are properly initialized and have the same bounds, + different color spaces => + Should set the data and return B_OK. + diff --git a/src/tests/kits/interface/bbitmap/BBitmapTester.cpp b/src/tests/kits/interface/bbitmap/BBitmapTester.cpp new file mode 100644 index 0000000000..2f9b73b1f2 --- /dev/null +++ b/src/tests/kits/interface/bbitmap/BBitmapTester.cpp @@ -0,0 +1,214 @@ +//------------------------------------------------------------------------------ +// BBitmapTester.cpp +// +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include + +// System Includes ------------------------------------------------------------- +#include +#include + +#include +#include +#include + +// Project Includes ------------------------------------------------------------ +#include +#include +#include + +// Local Includes -------------------------------------------------------------- +#include "BBitmapTester.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ + +// get_bytes_per_row +static inline +int32 +get_bytes_per_row(color_space colorSpace, int32 width) +{ + int32 bpr = 0; + switch (colorSpace) { + // supported + case B_RGB32: case B_RGBA32: + case B_RGB32_BIG: case B_RGBA32_BIG: + case B_UVL32: case B_UVLA32: + case B_LAB32: case B_LABA32: + case B_HSI32: case B_HSIA32: + case B_HSV32: case B_HSVA32: + case B_HLS32: case B_HLSA32: + case B_CMY32: case B_CMYA32: case B_CMYK32: + bpr = 4 * width; + break; + case B_RGB24: case B_RGB24_BIG: + case B_UVL24: case B_LAB24: case B_HSI24: + case B_HSV24: case B_HLS24: case B_CMY24: + bpr = 3 * width; + break; + case B_RGB16: case B_RGB15: case B_RGBA15: + case B_RGB16_BIG: case B_RGB15_BIG: case B_RGBA15_BIG: + bpr = 2 * width; + break; + case B_CMAP8: case B_GRAY8: + bpr = width; + break; + case B_GRAY1: + bpr = (width + 7) / 8; + break; + case B_YCbCr422: case B_YUV422: + bpr = (width + 3) / 4 * 8; + break; + case B_YCbCr411: case B_YUV411: + bpr = (width + 3) / 4 * 6; + break; + case B_YCbCr444: case B_YUV444: + bpr = (width + 3) / 4 * 12; + break; + case B_YCbCr420: case B_YUV420: + bpr = (width + 3) / 4 * 6; + break; + // unsupported + case B_NO_COLOR_SPACE: + case B_YUV9: case B_YUV12: + break; + } + // align to int32 + bpr = (bpr + 3) & 0x7ffffffc; + return bpr; +} + + +/* + BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews, + bool needsContiguous); + @case 1 acceptsViews = false, needsContiguous = false, valid bounds, + different color spaces + @results Bits() should be valid, BitsLength(), BytesPerRow() etc. + should return the correct values. + */ +void TBBitmapTester::BBitmap1() +{ + BApplication app("application/x-vnd.obos.bitmap-constructor-test"); + struct test_case { + BRect bounds; + color_space space; + } testCases[] = { + { BRect(0, 0, 39, 9), B_RGB32 }, + { BRect(0, 0, 39, 9), B_RGBA32 }, + { BRect(0, 0, 39, 9), B_RGB32_BIG }, + { BRect(0, 0, 39, 9), B_RGBA32_BIG }, + + { BRect(0, 0, 39, 9), B_UVL32 }, + { BRect(0, 0, 39, 9), B_UVLA32 }, + { BRect(0, 0, 39, 9), B_LAB32 }, + { BRect(0, 0, 39, 9), B_LABA32 }, + { BRect(0, 0, 39, 9), B_HSI32 }, + { BRect(0, 0, 39, 9), B_HSIA32 }, + { BRect(0, 0, 39, 9), B_HSV32 }, + { BRect(0, 0, 39, 9), B_HSVA32 }, + { BRect(0, 0, 39, 9), B_HLS32 }, + { BRect(0, 0, 39, 9), B_HLSA32 }, + { BRect(0, 0, 39, 9), B_CMY32 }, + { BRect(0, 0, 39, 9), B_CMYA32 }, + { BRect(0, 0, 39, 9), B_CMYK32 }, + { BRect(0, 0, 39, 9), B_RGB24 }, + { BRect(0, 0, 18, 9), B_RGB24 }, + { BRect(0, 0, 39, 9), B_RGB24_BIG }, + { BRect(0, 0, 18, 9), B_RGB24_BIG }, + { BRect(0, 0, 39, 9), B_UVL24 }, + { BRect(0, 0, 18, 9), B_UVL24 }, + { BRect(0, 0, 39, 9), B_LAB24 }, + { BRect(0, 0, 18, 9), B_LAB24 }, + { BRect(0, 0, 39, 9), B_HSI24 }, + { BRect(0, 0, 18, 9), B_HSI24 }, + { BRect(0, 0, 39, 9), B_HSV24 }, + { BRect(0, 0, 18, 9), B_HSV24 }, + { BRect(0, 0, 39, 9), B_HLS24 }, + { BRect(0, 0, 18, 9), B_HLS24 }, + { BRect(0, 0, 39, 9), B_CMY24 }, + { BRect(0, 0, 18, 9), B_CMY24 }, + { BRect(0, 0, 39, 9), B_RGB16 }, + { BRect(0, 0, 18, 9), B_RGB16 }, + { BRect(0, 0, 39, 9), B_RGB16_BIG }, + { BRect(0, 0, 18, 9), B_RGB16_BIG }, + { BRect(0, 0, 39, 9), B_RGB15 }, + { BRect(0, 0, 18, 9), B_RGB15 }, + { BRect(0, 0, 39, 9), B_RGB15_BIG }, + { BRect(0, 0, 18, 9), B_RGB15_BIG }, + { BRect(0, 0, 39, 9), B_RGBA15 }, + { BRect(0, 0, 18, 9), B_RGBA15 }, + { BRect(0, 0, 39, 9), B_RGBA15_BIG }, + { BRect(0, 0, 18, 9), B_RGBA15_BIG }, + { BRect(0, 0, 39, 9), B_CMAP8 }, + { BRect(0, 0, 18, 9), B_CMAP8 }, + { BRect(0, 0, 39, 9), B_GRAY8 }, + { BRect(0, 0, 18, 9), B_GRAY8 }, + { BRect(0, 0, 39, 9), B_GRAY1 }, + { BRect(0, 0, 31, 9), B_GRAY1 }, + { BRect(0, 0, 18, 9), B_GRAY1 }, + { BRect(0, 0, 39, 9), B_YCbCr422 }, + { BRect(0, 0, 18, 9), B_YCbCr422 }, + { BRect(0, 0, 39, 9), B_YUV422 }, + { BRect(0, 0, 18, 9), B_YUV422 }, +// R5: calculates weird BPR values for B_YCbCr411, B_YUV411 and B_YUV420. +// TODO: Investigate! +#ifndef TEST_R5 + { BRect(0, 0, 39, 9), B_YCbCr411 }, + { BRect(0, 0, 31, 9), B_YCbCr411 }, + { BRect(0, 0, 18, 9), B_YCbCr411 }, + { BRect(0, 0, 39, 9), B_YUV411 }, + { BRect(0, 0, 31, 9), B_YUV411 }, + { BRect(0, 0, 18, 9), B_YUV411 }, +#endif + { BRect(0, 0, 39, 9), B_YCbCr444 }, + { BRect(0, 0, 18, 9), B_YCbCr444 }, + { BRect(0, 0, 39, 9), B_YUV444 }, + { BRect(0, 0, 18, 9), B_YUV444 }, + { BRect(0, 0, 39, 9), B_YCbCr420 }, + { BRect(0, 0, 31, 9), B_YCbCr420 }, + { BRect(0, 0, 18, 9), B_YCbCr420 }, +#ifndef TEST_R5 + { BRect(0, 0, 39, 9), B_YUV420 }, + { BRect(0, 0, 31, 9), B_YUV420 }, + { BRect(0, 0, 18, 9), B_YUV420 }, +#endif + }; + int32 testCaseCount = sizeof(testCases) / sizeof(test_case); + for (int32 i = 0; i < testCaseCount; i++) { + // get test case + const test_case &testCase = testCases[i]; + int32 width = testCase.bounds.IntegerWidth() + 1; + int32 height = testCase.bounds.IntegerHeight() + 1; + int32 bpr = get_bytes_per_row(testCase.space, width); + // create and check bitmap + BBitmap bitmap(testCase.bounds, testCase.space); + CHK(bitmap.InitCheck() == B_OK); + CHK(bitmap.IsValid() == true); + CHK(bitmap.Bits() != NULL); + CHK(bitmap.Bounds() == testCase.bounds); + CHK(bitmap.ColorSpace() == testCase.space); +if (bitmap.BytesPerRow() != bpr) { +printf("space: %x: bpr: %ld (%ld)\n", testCase.space, bitmap.BytesPerRow(), +bpr); +} + CHK(bitmap.BytesPerRow() == bpr); + CHK(bitmap.BitsLength() == bpr * height); + } +} + + +Test* TBBitmapTester::Suite() +{ + TestSuite* SuiteOfTests = new TestSuite; + + ADD_TEST4(BBitmap, SuiteOfTests, TBBitmapTester, BBitmap1); + + return SuiteOfTests; +} + diff --git a/src/tests/kits/interface/bbitmap/BBitmapTester.h b/src/tests/kits/interface/bbitmap/BBitmapTester.h new file mode 100644 index 0000000000..5cca5fd8f0 --- /dev/null +++ b/src/tests/kits/interface/bbitmap/BBitmapTester.h @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// BBitmapTester.h +// +//------------------------------------------------------------------------------ + +#ifndef B_BITMAP_TESTER_H +#define B_BITMAP_TESTER_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "../common.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +class TBBitmapTester : public TestCase +{ + public: + TBBitmapTester() {;} + TBBitmapTester(std::string name) : TestCase(name) {;} + + void BBitmap1(); + + static Test* Suite(); +}; + +#endif // B_BITMAP_TESTER_H + diff --git a/src/tests/kits/interface/bbitmap/BitmapTest.cpp b/src/tests/kits/interface/bbitmap/BitmapTest.cpp new file mode 100644 index 0000000000..50acfddb5b --- /dev/null +++ b/src/tests/kits/interface/bbitmap/BitmapTest.cpp @@ -0,0 +1,13 @@ +#include "BBitmapTester.h" +#include "SetBitsTester.h" + +CppUnit::Test* BitmapTestSuite() +{ + CppUnit::TestSuite *testSuite = new CppUnit::TestSuite(); + + testSuite->addTest(SetBitsTester::Suite()); + testSuite->addTest(TBBitmapTester::Suite()); + + return testSuite; +} + diff --git a/src/tests/kits/interface/bbitmap/BitmapTest.h b/src/tests/kits/interface/bbitmap/BitmapTest.h new file mode 100644 index 0000000000..44fc178193 --- /dev/null +++ b/src/tests/kits/interface/bbitmap/BitmapTest.h @@ -0,0 +1,8 @@ +#ifndef _bitmap_test_h_ +#define _bitmap_test_h_ + +class CppUnit::Test; + +CppUnit::Test* BitmapTestSuite(); + +#endif // _bitmap_test_h_ diff --git a/src/tests/kits/interface/bbitmap/SetBitsTester.cpp b/src/tests/kits/interface/bbitmap/SetBitsTester.cpp new file mode 100644 index 0000000000..c31f87682d --- /dev/null +++ b/src/tests/kits/interface/bbitmap/SetBitsTester.cpp @@ -0,0 +1,706 @@ +//------------------------------------------------------------------------------ +// SetBitsTester.cpp +// +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include + +// System Includes ------------------------------------------------------------- +#include +#include + +#include +#include +#include + +// Project Includes ------------------------------------------------------------ +#include +#include +#include + +// Local Includes -------------------------------------------------------------- +#include "SetBitsTester.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ + +struct set_bits_test_data { + color_space space; + int32 width; + int32 height; + int32 offset; + int32 length; + int32 pixel_count; + uint8 data[256]; +}; + +// B_RGB32, width = 3 +set_bits_test_data rgb32_test_data3_initial = { + B_RGB32, 3, 2, + 8, 24, 6, + { + 0, 0, 0, 255, 8, 8, 8, 255, 128, 128, 128, 255, + 255, 255, 255, 255, 0, 0, 228, 255, 0, 102, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data3a_initial = { + B_RGB32, 3, 2, + 8, 24, 6, + { + 0, 0, 0, 0, 8, 8, 8, 0, 128, 128, 128, 0, + 255, 255, 255, 0, 0, 0, 228, 0, 0, 102, 0, 0, + } +}; + +set_bits_test_data rgb32_test_data3_set = { + B_RGB32, 3, 2, + 0, 18, 6, + { + 255, 255, 152, 51, 102, 102, 51, 255, 203, + 0, 102, 51, 203, 152, 203, 203, 203, 0, + } +}; + +set_bits_test_data rgb32_test_data3p_set = { + B_RGB32, 3, 1, + 0, 9, 3, + { + 51, 255, 203, 0, 102, 51, 203, 152, 203, + } +}; + +set_bits_test_data rgb32_test_data3_final = { + B_RGB32, 3, 2, + 0, 24, 6, + { + 152, 255, 255, 255, 102, 102, 51, 255, 203, 255, 51, 255, + 51, 102, 0, 255, 203, 152, 203, 255, 0, 203, 203, 255, + } +}; + +set_bits_test_data rgb32_test_data3a_final = { + B_RGB32, 3, 2, + 0, 24, 6, + { + 152, 255, 255, 0, 102, 102, 51, 0, 203, 255, 51, 0, + 51, 102, 0, 0, 203, 152, 203, 0, 0, 203, 203, 0, + } +}; + +set_bits_test_data rgb32_test_data3g_final = { + B_RGB32, 3, 2, + 0, 24, 6, + { + 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, + 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, + } +}; + +set_bits_test_data rgb32_test_data3p_final = { + B_RGB32, 3, 2, + 0, 24, 6, + { + 0, 0, 0, 255, 8, 8, 8, 255, 203, 255, 51, 255, + 51, 102, 0, 255, 203, 152, 203, 255, 0, 102, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data3ap_final = { + B_RGB32, 3, 2, + 0, 24, 6, + { + 0, 0, 0, 0, 8, 8, 8, 0, 203, 255, 51, 0, + 51, 102, 0, 0, 203, 152, 203, 0, 0, 102, 0, 0, + } +}; + +// B_RGB32, width = 4 +set_bits_test_data rgb32_test_data4_initial = { + B_RGB32, 4, 2, + 8, 32, 8, + { + 0, 0, 0, 255, 8, 8, 8, 255, 128, 128, 128, 255, + 255, 255, 255, 255, 0, 0, 228, 255, 0, 102, 0, 255, + 255, 0, 0, 255, 152, 102, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data4a_initial = { + B_RGB32, 4, 2, + 8, 32, 8, + { + 0, 0, 0, 0, 8, 8, 8, 0, 128, 128, 128, 0, + 255, 255, 255, 0, 0, 0, 228, 0, 0, 102, 0, 0, + 255, 0, 0, 0, 152, 102, 0, 0, + } +}; + +set_bits_test_data rgb32_test_data4_set = { + B_RGB32, 4, 2, + 0, 24, 8, + { + 255, 255, 152, 51, 102, 102, 51, 255, 203, + 0, 102, 51, 203, 152, 203, 203, 203, 0, + 152, 255, 203, 0, 30, 0, + } +}; + +set_bits_test_data rgb32_test_data4p_set = rgb32_test_data3p_set; + +set_bits_test_data rgb32_test_data4_final = { + B_RGB32, 4, 2, + 0, 32, 8, + { + 152, 255, 255, 255, 102, 102, 51, 255, 203, 255, 51, 255, + 51, 102, 0, 255, 203, 152, 203, 255, 0, 203, 203, 255, + 203, 255, 152, 255, 0, 30, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data4a_final = { + B_RGB32, 4, 2, + 0, 32, 8, + { + 152, 255, 255, 0, 102, 102, 51, 0, 203, 255, 51, 0, + 51, 102, 0, 0, 203, 152, 203, 0, 0, 203, 203, 0, + 203, 255, 152, 0, 0, 30, 0, 0, + } +}; + +set_bits_test_data rgb32_test_data4g_final = { + B_RGB32, 4, 2, + 0, 32, 8, + { + 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, + 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 0, 0, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data4p_final = { + B_RGB32, 4, 2, + 0, 32, 8, + { + 0, 0, 0, 255, 8, 8, 8, 255, 203, 255, 51, 255, + 51, 102, 0, 255, 203, 152, 203, 255, 0, 102, 0, 255, + 255, 0, 0, 255, 152, 102, 0, 255, + } +}; + +set_bits_test_data rgb32_test_data4ap_final = { + B_RGB32, 4, 2, + 0, 32, 8, + { + 0, 0, 0, 0, 8, 8, 8, 0, 203, 255, 51, 0, + 51, 102, 0, 0, 203, 152, 203, 0, 0, 102, 0, 0, + 255, 0, 0, 0, 152, 102, 0, 0, + } +}; + +// B_CMAP8, width = 3 +set_bits_test_data cmap8_test_data3_initial = { + B_CMAP8, 3, 2, + 2, 8, 6, + { + 0, 1, 16, 0, 255, 43, 159, 0, + } +}; + +set_bits_test_data cmap8_test_data3_set = { + B_CMAP8, 3, 2, + 0, 8, 6, + { + 253, 181, 83, 0, 158, 129, 101, 0, + } +}; + +set_bits_test_data cmap8_test_data3a_set = { + B_CMAP8, 3, 2, + 0, 6, 6, + { + 253, 181, 83, 158, 129, 101, + } +}; + +set_bits_test_data cmap8_test_data3p_set = { + B_CMAP8, 3, 1, + 0, 4, 3, + { + 83, 0, 158, 129, + } +}; + +set_bits_test_data cmap8_test_data3ap_set = { + B_CMAP8, 3, 1, + 0, 3, 3, + { + 83, 158, 129, + } +}; + +set_bits_test_data &cmap8_test_data3_final = cmap8_test_data3_set; + +set_bits_test_data cmap8_test_data3g_final = { + B_CMAP8, 3, 2, + 0, 8, 6, + { + 63, 0, 63, 0, 0, 63, 63, 0, + } +}; + +set_bits_test_data cmap8_test_data3p_final = { + B_CMAP8, 3, 2, + 0, 8, 6, + { + 0, 1, 83, 0, 158, 129, 159, 0, + } +}; + +// B_CMAP8, width = 4 +set_bits_test_data cmap8_test_data4_initial = { + B_CMAP8, 4, 2, + 2, 8, 8, + { + 0, 1, 16, 255, 43, 159, 32, 126 + } +}; + +set_bits_test_data cmap8_test_data4_set = { + B_CMAP8, 4, 2, + 0, 8, 8, + { + 253, 181, 83, 158, 129, 101, 71, 61 + } +}; + +set_bits_test_data cmap8_test_data4p_set = { + B_CMAP8, 4, 2, + 0, 3, 3, + { + 83, 158, 129, + } +}; + +set_bits_test_data &cmap8_test_data4_final = cmap8_test_data4_set; + +set_bits_test_data cmap8_test_data4g_final = { + B_CMAP8, 4, 2, + 0, 8, 8, + { + 63, 0, 63, 0, 63, 63, 63, 0 + } +}; + +set_bits_test_data cmap8_test_data4p_final = { + B_CMAP8, 4, 2, + 2, 8, 8, + { + 0, 1, 83, 158, 129, 159, 32, 126 + } +}; + +// B_RGB32_BIG +set_bits_test_data rgb32_big_test_data4_initial = { + B_RGB32_BIG, 4, 2, + 0, 32, 8, + { + 0, 0, 0, 255, 8, 8, 8, 255, 128, 128, 128, 255, + 255, 255, 255, 255, 228, 0, 0, 255, 0, 102, 0, 255, + 0, 0, 255, 255, 0, 102, 152, 255, + } +}; + +set_bits_test_data rgb32_big_test_data4_set = { + B_RGB32_BIG, 4, 2, + 0, 32, 8, + { + 255, 255, 152, 255, 51, 102, 102, 255, 51, 255, 203, 255, + 0, 102, 51, 255, 203, 152, 203, 255, 203, 203, 0, 255, + 152, 255, 203, 255, 0, 30, 0, 255, + } +}; + +set_bits_test_data rgb32_big_test_data4_final = { + B_RGB32_BIG, 4, 2, + 0, 32, 8, + { + 255, 255, 152, 0, 51, 102, 102, 0, 51, 255, 203, 0, + 0, 102, 51, 0, 203, 152, 203, 0, 203, 203, 0, 0, + 152, 255, 203, 0, 0, 30, 0, 0, + } +}; + +// B_GRAY1, width = 3 +set_bits_test_data gray1_test_data3_initial = { + B_GRAY1, 3, 2, + 0, 8, 6, + { + 0x20, 0x00, 0x00, 0x00, // 001 + 0x80, 0x00, 0x00, 0x00, // 100 + } +}; + +set_bits_test_data gray1_test_data3_set = { + B_GRAY1, 3, 2, + 0, 8, 6, + { + 0xa0, 0x00, 0x00, 0x00, // 101 + 0x60, 0x00, 0x00, 0x00, // 011 + } +}; + +set_bits_test_data &gray1_test_data3_final = gray1_test_data3_set; + +// B_GRAY1, width = 4 +set_bits_test_data gray1_test_data4_initial = { + B_GRAY1, 4, 2, + 0, 8, 8, + { + 0x30, 0x00, 0x00, 0x00, // 0011 + 0x00, 0x00, 0x00, 0x00, // 0000 + } +}; + +set_bits_test_data gray1_test_data4_set = { + B_GRAY1, 4, 2, + 0, 8, 8, + { + 0xa0, 0x00, 0x00, 0x00, // 1010 + 0xe0, 0x00, 0x00, 0x00, // 1110 + } +}; + +set_bits_test_data &gray1_test_data4_final = gray1_test_data4_set; + + +// dump_bitmap +static +void +dump_bitmap(const BBitmap *bitmap) +{ + BRect bounds = bitmap->Bounds(); + int32 width = bounds.IntegerWidth() + 1; + int32 height = bounds.IntegerHeight() + 1; + printf("BBitmap: %ldx%ld, %x\n", width, height, bitmap->ColorSpace()); + int32 bpr = bitmap->BytesPerRow(); + const uint8 *bits = (const uint8*)bitmap->Bits(); + for (int32 y = 0; y < height; y++) { + const uint8 *row = bits + y * bpr; + for (int32 i = 0; i < bpr; i++) + printf("%02x ", row[i]); + printf("\n"); + } +} + +// test_set_bits +static +void +test_set_bits(const set_bits_test_data &initialData, + const set_bits_test_data &setData, + const set_bits_test_data &finalData) +{ + BRect bounds(0, 0, initialData.width - 1, initialData.height - 1); + BBitmap bitmap(bounds, initialData.space); + CHK(bitmap.InitCheck() == B_OK); + CHK(bitmap.Bounds() == bounds); + CHK(bitmap.BitsLength() == initialData.length); + memcpy(bitmap.Bits(), initialData.data, initialData.length); +//dump_bitmap(&bitmap); +//printf("bitmap.SetBits(%p, %ld, %ld, %x)\n", setData.data, setData.length, 0L, +//setData.space); + bitmap.SetBits(setData.data, setData.length, 0, setData.space); +//dump_bitmap(&bitmap); + CHK(memcmp(bitmap.Bits(), finalData.data, finalData.length) == 0); +} + +// test_set_bits2 +static +void +test_set_bits2(const set_bits_test_data &initialData, + const set_bits_test_data &setData, + const set_bits_test_data &finalData) +{ + BRect bounds(0, 0, initialData.width - 1, initialData.height - 1); + BBitmap bitmap(bounds, initialData.space); + CHK(bitmap.InitCheck() == B_OK); + CHK(bitmap.Bounds() == bounds); + CHK(bitmap.BitsLength() == initialData.length); + memcpy(bitmap.Bits(), initialData.data, initialData.length); +//dump_bitmap(&bitmap); +//printf("bitmap.SetBits(%p, %ld, %ld, %x)\n", setData.data, setData.length, +//initialData.offset, setData.space); + bitmap.SetBits(setData.data, setData.length, initialData.offset, + setData.space); +//dump_bitmap(&bitmap); + CHK(memcmp(bitmap.Bits(), finalData.data, finalData.length) == 0); +} + +// test for OBOS only API +#ifndef TEST_R5 + +// test_import_bits +static +void +test_import_bits(const set_bits_test_data &initialData, + const set_bits_test_data &setData, + const set_bits_test_data &finalData) +{ + // init bitmap 1 + BRect bounds(0, 0, initialData.width - 1, initialData.height - 1); + BBitmap bitmap(bounds, initialData.space); + CHK(bitmap.InitCheck() == B_OK); + CHK(bitmap.Bounds() == bounds); + CHK(bitmap.BitsLength() == initialData.length); + memcpy(bitmap.Bits(), initialData.data, initialData.length); + // init bitmap 2 + BRect bounds2(0, 0, setData.width - 1, setData.height - 1); + BBitmap bitmap2(bounds2, setData.space); + CHK(bitmap2.InitCheck() == B_OK); + CHK(bitmap2.Bounds() == bounds2); + CHK(bitmap2.BitsLength() == setData.length); + memcpy(bitmap2.Bits(), setData.data, setData.length); + // import bits + CHK(bounds == bounds2); + CHK(initialData.length == finalData.length); +//dump_bitmap(&bitmap); +//printf("bitmap.ImportBits(): (%ld, %ld, %x) -> (%ld, %ld, %x)\n", +//bounds.IntegerWidth() + 1, bounds.IntegerHeight() + 1, initialData.space, +//bounds2.IntegerWidth() + 1, bounds2.IntegerHeight() + 1, setData.space); + CHK(bitmap.ImportBits(&bitmap2) == B_OK); +//dump_bitmap(&bitmap); + CHK(memcmp(bitmap.Bits(), finalData.data, finalData.length) == 0); +} + +#endif // test for OBOS only API + +/* + void SetBits(const void *data, int32 length, int32 offset, + color_space colorSpace) + @case 1 overwrite complete bitmap data, offset = 0, + different color spaces, no row padding + @results Bitmap should contain the correct data. + */ +void SetBitsTester::SetBits1() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); +#ifdef TEST_R5 + test_set_bits(rgb32_test_data3_initial, rgb32_test_data3_set, + rgb32_test_data3a_final); + test_set_bits(rgb32_test_data4_initial, rgb32_test_data4_set, + rgb32_test_data4a_final); + test_set_bits(cmap8_test_data4_initial, cmap8_test_data4_set, + cmap8_test_data4_final); + + test_set_bits(rgb32_test_data4a_initial, cmap8_test_data4_set, + rgb32_test_data4_final); + test_set_bits(cmap8_test_data4_initial, rgb32_test_data4_set, + cmap8_test_data4_final); +#else + test_set_bits(rgb32_test_data3_initial, rgb32_test_data3_set, + rgb32_test_data3_final); + test_set_bits(rgb32_test_data4_initial, rgb32_test_data4_set, + rgb32_test_data4_final); + test_set_bits(cmap8_test_data4_initial, cmap8_test_data4_set, + cmap8_test_data4_final); + + test_set_bits(rgb32_test_data4_initial, cmap8_test_data4_set, + rgb32_test_data4_final); + test_set_bits(cmap8_test_data4_initial, rgb32_test_data4_set, + cmap8_test_data4_final); +#endif +} + +/* + void SetBits(const void *data, int32 length, int32 offset, + color_space colorSpace) + @case 2 overwrite complete bitmap data, offset = 0, + different color spaces, row padding + @results Bitmap should contain the correct data. + */ +void SetBitsTester::SetBits2() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); + test_set_bits(cmap8_test_data3_initial, cmap8_test_data3_set, + cmap8_test_data3_final); + test_set_bits(gray1_test_data3_initial, gray1_test_data3_set, + gray1_test_data3_final); + test_set_bits(gray1_test_data4_initial, gray1_test_data4_set, + gray1_test_data4_final); + +// ignores source row padding + test_set_bits(rgb32_test_data3a_initial, cmap8_test_data3a_set, + rgb32_test_data3_final); +#ifndef TEST_R5 +// R5: broken: no effect + test_set_bits(rgb32_test_data3a_initial, gray1_test_data3_set, + rgb32_test_data3g_final); + test_set_bits(rgb32_test_data4a_initial, gray1_test_data4_set, + rgb32_test_data4g_final); +// R5: broken: ignores target bitmap row padding + test_set_bits(cmap8_test_data3_initial, rgb32_test_data3_set, + cmap8_test_data3_final); +// R5: broken: simply copies the data + test_set_bits(cmap8_test_data3_initial, gray1_test_data3_set, + cmap8_test_data3g_final); + test_set_bits(cmap8_test_data4_initial, gray1_test_data4_set, + cmap8_test_data4g_final); +#endif +} + +/* + void SetBits(const void *data, int32 length, int32 offset, + color_space colorSpace) + @case 3 overwrite bitmap data partially, offset = 0, + different color spaces, no row padding + @results Bitmap should contain the correct data. + */ +void SetBitsTester::SetBits3() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); +#ifdef TEST_R5 + test_set_bits2(rgb32_test_data3a_initial, rgb32_test_data3p_set, + rgb32_test_data3ap_final); + test_set_bits2(rgb32_test_data4a_initial, rgb32_test_data4p_set, + rgb32_test_data4ap_final); + test_set_bits2(cmap8_test_data4_initial, cmap8_test_data4p_set, + cmap8_test_data4p_final); +#else + test_set_bits2(rgb32_test_data3_initial, rgb32_test_data3p_set, + rgb32_test_data3p_final); + test_set_bits2(rgb32_test_data4_initial, rgb32_test_data4p_set, + rgb32_test_data4p_final); + test_set_bits2(cmap8_test_data4_initial, cmap8_test_data4p_set, + cmap8_test_data4p_final); +#endif + + test_set_bits2(rgb32_test_data4_initial, cmap8_test_data4p_set, + rgb32_test_data4p_final); + test_set_bits2(cmap8_test_data4_initial, rgb32_test_data4p_set, + cmap8_test_data4p_final); +} + +/* + void SetBits(const void *data, int32 length, int32 offset, + color_space colorSpace) + @case 4 overwrite bitmap data partially, offset = 0, + different color spaces, row padding + @results Bitmap should contain the correct data. + */ +void SetBitsTester::SetBits4() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); + test_set_bits2(cmap8_test_data3_initial, cmap8_test_data3p_set, + cmap8_test_data3p_final); + + test_set_bits2(rgb32_test_data3_initial, cmap8_test_data3ap_set, + rgb32_test_data3p_final); +// R5: broken: ignores target bitmap row padding +#ifndef TEST_R5 + test_set_bits2(cmap8_test_data3_initial, rgb32_test_data3p_set, + cmap8_test_data3p_final); +#endif +} + +// OBOS only API +#ifndef TEST_R5 + +/* + status_t ImportBits(const BBitmap *bitmap) + @case 1 NULL bitmap + @results Should return B_BAD_VALUE. + */ +void SetBitsTester::ImportBitsA1() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); + BBitmap bitmap(BRect(0, 0, 9, 9), B_RGB32); + CHK(bitmap.ImportBits(NULL) == B_BAD_VALUE); +} + +/* + status_t ImportBits(const BBitmap *bitmap) + @case 2 bitmap with different Bounds() + @results Should return B_BAD_VALUE. + */ +void SetBitsTester::ImportBitsA2() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); + BBitmap bitmap(BRect(0, 0, 9, 9), B_RGB32); + BBitmap bitmap2(BRect(0, 0, 9, 10), B_RGB32); + CHK(bitmap.ImportBits(&bitmap2) == B_BAD_VALUE); +} + +/* + status_t ImportBits(const BBitmap *bitmap) + @case 3 this and bitmap are properly initialized and have the + same bounds, different color spaces + @results Should set the data and return B_OK. + */ +void SetBitsTester::ImportBitsA3() +{ + BApplication app("application/x-vnd.obos.bitmap-setbits-test"); + // B_RGB32 + test_import_bits(rgb32_test_data3_initial, rgb32_test_data3_final, + rgb32_test_data3_final); + test_import_bits(rgb32_test_data3_initial, cmap8_test_data3_final, + rgb32_test_data3_final); + test_import_bits(rgb32_test_data3_initial, gray1_test_data3_final, + rgb32_test_data3g_final); + test_import_bits(rgb32_test_data4_initial, rgb32_test_data4_final, + rgb32_test_data4_final); + test_import_bits(rgb32_test_data4_initial, cmap8_test_data4_final, + rgb32_test_data4_final); + test_import_bits(rgb32_test_data4_initial, gray1_test_data4_final, + rgb32_test_data4g_final); + // B_CMAP8 + test_import_bits(cmap8_test_data3_initial, rgb32_test_data3_final, + cmap8_test_data3_final); + test_import_bits(cmap8_test_data3_initial, cmap8_test_data3_final, + cmap8_test_data3_final); + test_import_bits(cmap8_test_data3_initial, gray1_test_data3_final, + cmap8_test_data3g_final); + test_import_bits(cmap8_test_data4_initial, rgb32_test_data4_final, + cmap8_test_data4_final); + test_import_bits(cmap8_test_data4_initial, cmap8_test_data4_final, + cmap8_test_data4_final); + test_import_bits(cmap8_test_data4_initial, gray1_test_data4_final, + cmap8_test_data4g_final); + // B_GRAY1 + test_import_bits(gray1_test_data3_initial, rgb32_test_data3_final, + gray1_test_data3_final); + test_import_bits(gray1_test_data3_initial, cmap8_test_data3_final, + gray1_test_data3_final); + test_import_bits(gray1_test_data3_initial, gray1_test_data3_final, + gray1_test_data3_final); + test_import_bits(gray1_test_data4_initial, rgb32_test_data4_final, + gray1_test_data4_final); + test_import_bits(gray1_test_data4_initial, cmap8_test_data4_final, + gray1_test_data4_final); + test_import_bits(gray1_test_data4_initial, gray1_test_data4_final, + gray1_test_data4_final); +} +#endif // ifndef TEST_R5 + +Test* SetBitsTester::Suite() +{ + TestSuite* SuiteOfTests = new TestSuite; + + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, SetBits1); + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, SetBits2); + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, SetBits3); + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, SetBits4); + +// OBOS only API +#ifndef TEST_R5 + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, ImportBitsA1); + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, ImportBitsA2); + ADD_TEST4(BBitmap, SuiteOfTests, SetBitsTester, ImportBitsA3); +#endif + + return SuiteOfTests; +} + diff --git a/src/tests/kits/interface/bbitmap/SetBitsTester.h b/src/tests/kits/interface/bbitmap/SetBitsTester.h new file mode 100644 index 0000000000..fd8e829487 --- /dev/null +++ b/src/tests/kits/interface/bbitmap/SetBitsTester.h @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// SetBitsTester.h +// +//------------------------------------------------------------------------------ + +#ifndef SET_BITS_TESTER_H +#define SET_BITS_TESTER_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "../common.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +class SetBitsTester : public TestCase +{ + public: + SetBitsTester() {;} + SetBitsTester(std::string name) : TestCase(name) {;} + + void SetBits1(); + void SetBits2(); + void SetBits3(); + void SetBits4(); + +// new API +#ifndef TEST_R5 + void ImportBitsA1(); + void ImportBitsA2(); + void ImportBitsA3(); +#endif + + static Test* Suite(); +}; + +#endif // SET_BITS_TESTER_H +