awtk/tests/locale_test.cc

40 lines
1.1 KiB
C++
Raw Normal View History

2018-08-24 07:45:37 +08:00
#include "base/locale_info.h"
2018-05-04 14:52:15 +08:00
#include "gtest/gtest.h"
2018-10-30 18:14:12 +08:00
#include "common.h"
2018-05-04 14:52:15 +08:00
#include <string>
using std::string;
static string s_locale;
static ret_t test_on_locale_changed(void* ctx, event_t* e) {
2018-08-24 07:45:37 +08:00
locale_info_t* locale_info = (locale_info_t*)ctx;
2018-05-04 14:52:15 +08:00
(void)e;
2018-08-24 07:45:37 +08:00
s_locale = string(locale_info->language) + "_" + string(locale_info->country);
2018-05-04 14:52:15 +08:00
return RET_OK;
}
TEST(Locale, basic) {
const char* str = "ok";
uint32_t id = 0;
2018-08-24 07:45:37 +08:00
locale_info_t* locale_info = locale_info_create("en", "US");
ASSERT_EQ(string("OK"), string(locale_info_tr(locale_info, str)));
2018-05-04 14:52:15 +08:00
2018-08-24 07:45:37 +08:00
id = locale_info_on(locale_info, EVT_LOCALE_CHANGED, test_on_locale_changed, locale_info);
2018-05-04 14:52:15 +08:00
ASSERT_EQ(id, 1);
2018-08-24 07:45:37 +08:00
ASSERT_EQ(locale_info_change(locale_info, "zh", "CN"), RET_OK);
2018-05-04 14:52:15 +08:00
ASSERT_EQ(s_locale, "zh_CN");
2018-10-30 18:14:12 +08:00
assert_str_eq(L"确定", locale_info_tr(locale_info, str));
2018-05-04 14:52:15 +08:00
2018-08-24 07:45:37 +08:00
ASSERT_EQ(locale_info_off(locale_info, id), RET_OK);
ASSERT_EQ(locale_info_change(locale_info, "en", "US"), RET_OK);
2018-05-04 14:52:15 +08:00
ASSERT_EQ(s_locale, "zh_CN");
2018-08-24 07:45:37 +08:00
ASSERT_EQ(string("OK"), string(locale_info_tr(locale_info, str)));
2018-05-04 14:52:15 +08:00
2018-08-24 07:45:37 +08:00
locale_info_destroy(locale_info);
2018-05-04 14:52:15 +08:00
}