awtk/tests/font_manager_test.cc

72 lines
2.7 KiB
C++
Raw Normal View History

2018-06-27 13:46:42 +08:00

2018-02-21 19:36:38 +08:00
#include "base/canvas.h"
#include "base/font_manager.h"
2018-02-21 19:36:38 +08:00
#include "font_dummy.h"
#include "lcd_log.h"
#include "gtest/gtest.h"
#include <stdlib.h>
2018-02-21 19:36:38 +08:00
TEST(FontManager, basic) {
2021-02-26 16:27:12 +08:00
font_t* tmp;
2018-02-21 19:36:38 +08:00
font_manager_t font_manager;
2021-02-26 16:27:12 +08:00
const char* default_font = system_info()->default_font;
2018-02-21 19:36:38 +08:00
font_dummy_init();
2018-10-19 18:10:58 +08:00
font_manager_init(&font_manager, NULL);
2018-12-28 17:43:54 +08:00
font_manager_add_font(&font_manager, font_dummy_0("demo0", 10));
font_manager_add_font(&font_manager, font_dummy_1("demo1", 11));
font_manager_add_font(&font_manager, font_dummy_2("demo2", 12));
2021-02-26 16:27:12 +08:00
font_manager_add_font(&font_manager, font_dummy_default(default_font, 10));
2018-02-21 19:36:38 +08:00
2018-12-28 17:43:54 +08:00
ASSERT_EQ(font_manager_get_font(&font_manager, "demo0", 10), font_dummy_0("demo0", 10));
ASSERT_EQ(font_manager_get_font(&font_manager, "demo1", 11), font_dummy_1("demo1", 11));
ASSERT_EQ(font_manager_get_font(&font_manager, "demo2", 12), font_dummy_2("demo2", 12));
2018-02-21 19:36:38 +08:00
2021-02-26 16:27:12 +08:00
tmp = font_dummy_default(default_font, 10);
ASSERT_EQ(font_manager_get_font(&font_manager, NULL, 10), tmp);
tmp = font_dummy_default(default_font, 11);
ASSERT_EQ(font_manager_get_font(&font_manager, NULL, 11), tmp);
tmp = font_dummy_default(default_font, 12);
ASSERT_EQ(font_manager_get_font(&font_manager, NULL, 12), tmp);
2018-02-21 19:36:38 +08:00
2021-02-26 16:27:12 +08:00
ASSERT_EQ(font_manager_get_font(&font_manager, NULL, 20) == NULL, true);
ASSERT_EQ(font_manager_get_font(&font_manager, "demo0", 20) == NULL, true);
ASSERT_EQ(font_manager_get_font(&font_manager, default_font, 12) != NULL, true);
ASSERT_EQ(font_manager_get_font(&font_manager, "demo3", 12) != NULL, true);
ASSERT_EQ(font_manager_get_font(&font_manager, "demo3", 20) == NULL, true);
2018-03-11 14:21:19 +08:00
font_manager_deinit(&font_manager);
2018-02-21 19:36:38 +08:00
}
2018-10-19 18:10:58 +08:00
2020-05-29 22:20:24 +08:00
#if defined(WITH_FT_FONT) || defined(WITH_STB_FONT)
2018-12-26 18:10:38 +08:00
#include "font_loader/font_loader_truetype.h"
2018-10-19 18:10:58 +08:00
TEST(FontManager, loader) {
font_manager_t font_manager;
2018-12-26 18:10:38 +08:00
font_manager_init(&font_manager, font_loader_truetype());
2020-12-11 16:50:09 +08:00
font_manager_set_assets_manager(&font_manager, assets_manager());
2018-12-28 17:43:54 +08:00
ASSERT_EQ(font_manager_get_font(&font_manager, "ap", 20) != NULL, true);
2018-10-19 18:10:58 +08:00
font_manager_deinit(&font_manager);
}
2019-04-01 18:06:31 +08:00
TEST(FontManager, unload) {
font_manager_t font_manager;
2021-06-15 18:04:53 +08:00
emitter_t* emitter = EMITTER(assets_manager());
if (emitter_size(emitter) > 0) {
emitter_off_by_tag(emitter, 0);
}
2019-04-01 18:06:31 +08:00
font_manager_init(&font_manager, font_loader_truetype());
2020-12-11 16:50:09 +08:00
font_manager_set_assets_manager(&font_manager, assets_manager());
2019-04-01 18:06:31 +08:00
ASSERT_EQ(font_manager_get_font(&font_manager, "ap", 20) != NULL, true);
ASSERT_EQ(font_manager_unload_font(&font_manager, "ap", 0), RET_OK);
ASSERT_EQ(font_manager_unload_font(&font_manager, "ap", 0), RET_NOT_FOUND);
ASSERT_EQ(font_manager_lookup(&font_manager, "ap", 20) == NULL, true);
font_manager_deinit(&font_manager);
}
2020-05-29 22:20:24 +08:00
#endif