awtk/tests/enums_test.cc

45 lines
1.5 KiB
C++
Raw Normal View History

2019-05-22 17:13:00 +08:00
#include "base/keys.h"
#include "base/enums.h"
2018-03-09 21:54:46 +08:00
#include "gtest/gtest.h"
2018-08-24 07:45:37 +08:00
#include "base/assets_manager.h"
2022-10-20 17:44:37 +08:00
#define ENABLE_CUSTOM_KEYS TRUE
2022-10-17 17:55:18 +08:00
#include "base/custom_keys.inc"
2018-03-09 21:54:46 +08:00
TEST(Enums, basic) {
2018-08-24 07:45:37 +08:00
ASSERT_EQ(asset_type_find("style"), asset_type_find_by_value(ASSET_TYPE_STYLE));
ASSERT_EQ(asset_type_find("xml"), asset_type_find_by_value(ASSET_TYPE_XML));
2018-03-09 21:54:46 +08:00
}
TEST(Enums, keys) {
ASSERT_EQ(keys_type_find("a"), keys_type_find_by_value(TK_KEY_a));
ASSERT_EQ(keys_type_find("A"), keys_type_find_by_value(TK_KEY_A));
ASSERT_EQ(keys_type_find("LEFT"), keys_type_find_by_value(TK_KEY_LEFT));
ASSERT_EQ(keys_type_find("left"), keys_type_find_by_value(TK_KEY_LEFT));
ASSERT_EQ(keys_type_find("RETURN"), keys_type_find_by_value(TK_KEY_RETURN));
ASSERT_EQ(keys_type_find("return"), keys_type_find_by_value(TK_KEY_RETURN));
}
2022-09-29 17:18:20 +08:00
TEST(Enums, custom_keys) {
static const key_type_value_t custom_keys[] = {
2022-10-17 17:55:18 +08:00
{(char*)"CUSTOM1", 0, TK_KEY_RETURN},
2022-09-29 17:18:20 +08:00
};
2022-10-08 16:46:38 +08:00
ASSERT_EQ(keys_type_find("CUSTOM1") == NULL, TRUE);
2022-09-29 17:18:20 +08:00
keys_type_set_custom_keys(custom_keys, ARRAY_SIZE(custom_keys));
ASSERT_EQ(keys_type_find("CUSTOM1"), keys_type_find_by_value(TK_KEY_RETURN));
keys_type_set_custom_keys(NULL, 0);
2022-10-08 16:46:38 +08:00
ASSERT_EQ(keys_type_find("CUSTOM1") == NULL, TRUE);
2022-09-29 17:18:20 +08:00
}
2022-10-17 17:55:18 +08:00
2022-10-18 16:06:03 +08:00
TEST(Enums, custom_keys_init) {
ASSERT_EQ(custom_keys() == NULL && custom_keys_nr() == 0, TRUE);
2022-10-17 17:55:18 +08:00
2022-10-18 16:06:03 +08:00
custom_keys_init(TRUE);
ASSERT_EQ(custom_keys() != NULL || custom_keys_nr() == 0, TRUE);
custom_keys_deinit(TRUE);
ASSERT_EQ(custom_keys() == NULL && custom_keys_nr() == 0, TRUE);
2022-10-17 17:55:18 +08:00
}