-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathimage_test.cpp
153 lines (131 loc) · 3.39 KB
/
image_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: MIT
// Copyright (C) 2024 Artem Senichev <[email protected]>
extern "C" {
#include "buildcfg.h"
#include "image.h"
}
#include <gtest/gtest.h>
#include <unistd.h>
class Image : public ::testing::Test {
protected:
void TearDown() override
{
if (image) {
image_free(image, IMGFREE_ALL);
}
}
void Load(const char* file)
{
image = image_create(file);
ASSERT_TRUE(image);
ASSERT_EQ(image_load(image), imgload_success);
ASSERT_TRUE(image->name);
ASSERT_TRUE(image->parent_dir);
EXPECT_NE(image->frames[0].pm.width, static_cast<size_t>(0));
EXPECT_NE(image->frames[0].pm.height, static_cast<size_t>(0));
EXPECT_NE(image->frames[0].pm.data[0], static_cast<argb_t>(0));
}
struct image* image = nullptr;
};
TEST_F(Image, Create)
{
image = image_create("file123");
ASSERT_TRUE(image);
ASSERT_STREQ(image->source, "file123");
}
TEST_F(Image, Update)
{
Load(TEST_DATA_DIR "/image.bmp");
image->index = 123;
struct image* new_img = image_create(TEST_DATA_DIR "/image.bmp");
ASSERT_TRUE(new_img);
new_img->index = 321;
image_update(new_img, image);
EXPECT_FALSE(image->frames);
EXPECT_TRUE(new_img->frames);
EXPECT_EQ(new_img->index, static_cast<size_t>(321));
image_free(new_img, IMGFREE_ALL);
}
TEST_F(Image, Free)
{
Load(TEST_DATA_DIR "/image.bmp");
EXPECT_FALSE(image_has_thumb(image));
image_thumb_create(image, 1, true, aa_nearest);
EXPECT_TRUE(image_has_thumb(image));
image_free(image, IMGFREE_THUMB);
EXPECT_FALSE(image_has_thumb(image));
EXPECT_TRUE(image_has_frames(image));
image_free(image, IMGFREE_FRAMES);
EXPECT_FALSE(image_has_frames(image));
EXPECT_FALSE(image->format);
}
TEST_F(Image, Transform)
{
Load(TEST_DATA_DIR "/image.bmp");
image_flip_vertical(image);
image_flip_horizontal(image);
image_rotate(image, 90);
image_rotate(image, 180);
image_rotate(image, 270);
}
TEST_F(Image, Thumbnail)
{
image = image_create("file");
ASSERT_FALSE(image_thumb_create(image, 10, true, aa_nearest));
image_free(image, IMGFREE_ALL);
Load(TEST_DATA_DIR "/image.bmp");
ASSERT_TRUE(image_thumb_create(image, 10, true, aa_nearest));
EXPECT_TRUE(image->thumbnail.data);
EXPECT_EQ(image->thumbnail.width, static_cast<size_t>(10));
EXPECT_EQ(image->thumbnail.height, static_cast<size_t>(10));
}
TEST_F(Image, LoadFromExec)
{
image = image_create(LDRSRC_EXEC "cat " TEST_DATA_DIR "/image.bmp");
ASSERT_TRUE(image);
ASSERT_EQ(image_load(image), imgload_success);
}
#define TEST_LOADER(n) \
TEST_F(Image, Load_##n) \
{ \
Load(TEST_DATA_DIR "/image." #n); \
}
TEST_LOADER(bmp);
TEST_LOADER(dcm);
TEST_LOADER(ff);
TEST_LOADER(pnm);
TEST_LOADER(qoi);
TEST_LOADER(tga);
#ifdef HAVE_LIBEXR
// TEST_LOADER(exr);
#endif
#ifdef HAVE_LIBGIF
TEST_LOADER(gif);
#endif
#ifdef HAVE_LIBHEIF
TEST_LOADER(heif);
#endif
#ifdef HAVE_LIBAVIF
TEST_LOADER(avif);
#endif
#ifdef HAVE_LIBJPEG
TEST_LOADER(jpg);
#endif
#ifdef HAVE_LIBJXL
TEST_LOADER(jxl);
#endif
#ifdef HAVE_LIBPNG
TEST_LOADER(png);
#endif
#ifdef HAVE_LIBRSVG
TEST_LOADER(svg);
#endif
#ifdef HAVE_LIBTIFF
TEST_LOADER(tiff);
#endif
#ifdef HAVE_LIBSIXEL
TEST_LOADER(six);
#endif
#ifdef HAVE_LIBWEBP
TEST_LOADER(webp);
#endif