Moved graphics classes into own namespace, added unit testing with gtest
This commit is contained in:
47
tests/bitmap_test/bitmap_test.cpp
Normal file
47
tests/bitmap_test/bitmap_test.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "graphics/Bitmap.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
auto width = bm.getWidth();
|
||||
auto height = bm.getHeight();
|
||||
ASSERT_EQ(width, 16);
|
||||
ASSERT_EQ(height, 8);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_getBitmapLineOutsideOfImage_yieldsNullopt) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
// line 8 is out of bounds, count begins with 0
|
||||
auto outOfBoundsLine = bm.getLine(8);
|
||||
ASSERT_EQ(std::nullopt, outOfBoundsLine);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_getBitmapLineInsideOfImage_yieldsValidLineSize) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
auto line = bm.getLine(7);
|
||||
if (!line) {
|
||||
FAIL() << "Returned line is invalid";
|
||||
}
|
||||
auto lineSize = line->size();
|
||||
ASSERT_EQ(16, lineSize);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_getBitmapRowOutsideOfImage_yieldsNullopt) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
// row 16 is out of bounds, count begins with 0
|
||||
auto outOfBoundsRow = bm.getRow(16);
|
||||
ASSERT_EQ(std::nullopt, outOfBoundsRow);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_getBitmapRowInsideOfImage_yieldsValidRowSize) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
auto row = bm.getRow(15);
|
||||
if (!row) {
|
||||
FAIL() << "Returned Row is invalid";
|
||||
}
|
||||
auto rowSize = row->size();
|
||||
ASSERT_EQ(8, rowSize);
|
||||
}
|
9
tests/image_test/image_test.cpp
Normal file
9
tests/image_test/image_test.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "graphics/Image.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
TEST(basic_test, Image_smokeTest_succeeds) {
|
||||
auto im = ptprnt::graphics::Image();
|
||||
}
|
14
tests/meson.build
Normal file
14
tests/meson.build
Normal file
@@ -0,0 +1,14 @@
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']]
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
test(test.get(0),
|
||||
executable(test.get(1),
|
||||
sources: test.get(2),
|
||||
include_directories: incdir,
|
||||
link_with:[ptprnt_lib],
|
||||
dependencies: [gtest_dep, pangocairo_dep]
|
||||
)
|
||||
)
|
||||
endforeach
|
Reference in New Issue
Block a user