18 #include "bitmapimage.h"
20 TEST_CASE(
"BitmapImage constructors")
22 SECTION(
"Init an Bitmap Image")
24 auto b = std::make_shared<BitmapImage>();
25 REQUIRE(b->image()->isNull());
27 REQUIRE(b->width() == 0);
28 REQUIRE(b->height() == 0);
29 REQUIRE(b->top() == 0);
30 REQUIRE(b->left() == 0);
33 SECTION(
"Init with color and boundary")
35 auto b = std::make_shared<BitmapImage>(
QRect(10, 20, 30, 40),
Qt::red);
37 REQUIRE(b->left() == 10);
38 REQUIRE(b->top() == 20);
39 REQUIRE(b->width() == 30);
40 REQUIRE(b->height() == 40);
42 QRgb rgb = b->image()->pixel(0, 0);
43 REQUIRE(rgb == qRgb(255, 0, 0));
46 SECTION(
"Clone a BitmapImage")
48 auto b = std::make_shared<BitmapImage>(
QRect(20, 20, 100, 100),
Qt::red);
51 REQUIRE(b->pos() == b2->pos());
52 REQUIRE(b->length() == b2->length());
54 REQUIRE(b->left() == b2->left());
55 REQUIRE(b->right() == b2->right());
56 REQUIRE(b->width() == b2->width());
57 REQUIRE(b->height() == b2->height());
60 QImage* img2 = b2->image();
61 REQUIRE(img1 != img2);
62 REQUIRE((*img1) == (*img2));
65 SECTION(
"#947 Initial Color")
71 auto b = std::make_shared<BitmapImage>();
72 for (
int x = 0; x < b->width(); ++x)
74 for (
int y = 0; y < b->height(); ++y)
76 QRgb color = b->pixel(x, y);
77 REQUIRE(qAlpha(color) == 0);
83 TEST_CASE(
"BitmapImage functions")
85 SECTION(
"moveTopLeft()")
87 auto b = std::make_shared<BitmapImage>(
QRect(0, 0, 50, 50),
Qt::red);
88 b->moveTopLeft(
QPoint(20, 10));
90 REQUIRE(b->topLeft() ==
QPoint(20, 10));
91 REQUIRE(b->width() == 50);
92 REQUIRE(b->height() == 50);