Skip to content

Commit 0814beb

Browse files
committed
Core (Tests): Add unit test for image loading.
1 parent a09f4fe commit 0814beb

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed
4.27 KB
Loading
63 KB
Binary file not shown.
18.3 KB
Loading
47.3 KB
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Loading

libvisual/tests/video_test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ LV_BUILD_TEST(video_check_test
22
SOURCES video_check_test.cpp
33
)
44

5+
LV_BUILD_TEST(video_load_test
6+
SOURCES video_load_test.cpp
7+
)
8+
59
IF(HAVE_SDL)
610
LV_BUILD_TEST(video_scale_test
711
SOURCES video_scale_test.cpp
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "test.h"
2+
#include <libvisual/libvisual.h>
3+
#include <fstream>
4+
5+
namespace
6+
{
7+
LV::VideoPtr load_raw_image (std::string const& path, int width, int height, VisVideoDepth depth)
8+
{
9+
auto image {LV::Video::create (width, height, depth)};
10+
11+
std::size_t const content_bytes_per_row = image->get_width () * image->get_bpp ();
12+
13+
{
14+
std::ifstream input {path, std::ios::binary};
15+
16+
for (int y = 0; y < image->get_height (); y++) {
17+
auto pixel_row_ptr = static_cast<char*> (image->get_pixel_ptr (0, y));
18+
input.read (pixel_row_ptr, content_bytes_per_row);
19+
}
20+
}
21+
22+
#if VISUAL_LITTLE_ENDIAN == 1
23+
auto byteswapped_image {LV::Video::create (width, height, depth)};
24+
byteswapped_image->flip_pixel_bytes (image);
25+
26+
return byteswapped_image;
27+
#else
28+
return image;
29+
#endif
30+
}
31+
32+
void test_png_load ()
33+
{
34+
{
35+
auto png_image {LV::Video::create_from_file ("../images/additive-colors-rgb24.png")};
36+
LV_TEST_ASSERT (png_image);
37+
38+
auto raw_image {load_raw_image ("../images/additive-colors-rgb24.raw",
39+
png_image->get_width (),
40+
png_image->get_height (),
41+
VISUAL_VIDEO_DEPTH_24BIT)};
42+
43+
LV_TEST_ASSERT (png_image->has_same_content (raw_image));
44+
}
45+
46+
{
47+
auto png_image {LV::Video::create_from_file ("../images/additive-colors-argb32.png")};
48+
LV_TEST_ASSERT (png_image);
49+
50+
auto raw_image {load_raw_image ("../images/additive-colors-argb32.raw",
51+
png_image->get_width (),
52+
png_image->get_height (),
53+
VISUAL_VIDEO_DEPTH_32BIT)};
54+
55+
LV_TEST_ASSERT (png_image->has_same_content (raw_image));
56+
}
57+
}
58+
}
59+
60+
int main (int argc, char* argv[])
61+
{
62+
LV::System::init (argc, argv);
63+
64+
auto video = LV::Video::create (640, 480, VISUAL_VIDEO_DEPTH_16BIT);
65+
66+
test_png_load ();
67+
68+
LV::System::destroy ();
69+
}

0 commit comments

Comments
 (0)