forked from artemsen/swayimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader_test.cpp
92 lines (84 loc) · 2 KB
/
loader_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
// SPDX-License-Identifier: MIT
// Copyright (C) 2024 Artem Senichev <[email protected]>
extern "C" {
#include "application.h"
#include "buildcfg.h"
#include "loader.h"
#include "ui.h"
#include "viewer.h"
}
#include <gtest/gtest.h>
// stubs for linker (application and ui are not included to tests)
extern "C" {
void app_watch(int, fd_callback, void*) { }
void app_reload() { }
void app_redraw() { }
void app_on_resize() { }
void app_on_keyboard(xkb_keysym_t, uint8_t) { }
void app_on_drag(int, int) { }
void app_exit(int) { }
void app_on_load(struct image*, size_t) { }
bool app_is_viewer()
{
return true;
}
}
class Loader : public ::testing::Test {
protected:
void TearDown() override { image_free(image); }
void Load(const char* file)
{
EXPECT_EQ(loader_from_source(file, &image), ldr_success);
ASSERT_NE(image, nullptr);
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(Loader, External)
{
const enum loader_status status = loader_from_source(
LDRSRC_EXEC "cat " TEST_DATA_DIR "/image.bmp", &image);
EXPECT_EQ(status, ldr_success);
ASSERT_NE(image, nullptr);
}
#define TEST_LOADER(n) \
TEST_F(Loader, n) \
{ \
Load(TEST_DATA_DIR "/image." #n); \
}
TEST_LOADER(bmp);
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_LIBWEBP
TEST_LOADER(webp);
#endif