awtk/tests/system_info_test.cc

98 lines
3.2 KiB
C++
Raw Normal View History

2019-03-08 18:51:09 +08:00
#include "base/locale_info.h"
#include "base/system_info.h"
2019-03-07 15:25:11 +08:00
#include "gtest/gtest.h"
2019-03-08 18:51:09 +08:00
#include <string>
using std::string;
2019-03-07 15:25:11 +08:00
TEST(SystemInfo, basic) {
2020-08-18 17:56:36 +08:00
system_info_t* info = system_info_create(APP_DESKTOP, "awtk", NULL);
2019-03-07 15:25:11 +08:00
ASSERT_EQ(info->app_type, APP_DESKTOP);
ASSERT_STREQ(info->app_name, "awtk");
ASSERT_EQ(system_info_set_lcd_w(info, 100), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(info->lcd_w, 100u);
2021-12-08 15:20:36 +08:00
ASSERT_EQ(info->lcd_w,
(uint32_t)tk_object_get_prop_int(TK_OBJECT(info), SYSTEM_INFO_PROP_LCD_W, 0));
2019-03-07 15:25:11 +08:00
ASSERT_EQ(system_info_set_lcd_h(info, 200), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(info->lcd_h, 200u);
2021-12-08 15:20:36 +08:00
ASSERT_EQ(info->lcd_h,
(uint32_t)tk_object_get_prop_int(TK_OBJECT(info), SYSTEM_INFO_PROP_LCD_H, 0));
2019-03-07 15:25:11 +08:00
ASSERT_EQ(system_info_set_lcd_type(info, LCD_FRAMEBUFFER), RET_OK);
ASSERT_EQ(info->lcd_type, LCD_FRAMEBUFFER);
ASSERT_EQ((int32_t)(info->lcd_type),
tk_object_get_prop_int(TK_OBJECT(info), SYSTEM_INFO_PROP_LCD_TYPE, 111));
2019-03-07 15:25:11 +08:00
ASSERT_EQ(system_info_set_device_pixel_ratio(info, 2), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(info->device_pixel_ratio, 2.0f);
2019-03-07 15:25:11 +08:00
ASSERT_EQ(info->device_pixel_ratio,
tk_object_get_prop_float(TK_OBJECT(info), SYSTEM_INFO_PROP_DEVICE_PIXEL_RATIO, 0));
2019-03-07 15:25:11 +08:00
ASSERT_EQ(system_info_set_lcd_orientation(info, LCD_ORIENTATION_180), RET_OK);
ASSERT_EQ(info->lcd_orientation, LCD_ORIENTATION_180);
ASSERT_EQ((int32_t)(info->lcd_orientation),
tk_object_get_prop_int(TK_OBJECT(info), SYSTEM_INFO_PROP_LCD_ORIENTATION, 111));
2019-03-07 15:25:11 +08:00
2021-12-08 15:20:36 +08:00
ASSERT_STREQ("portrait",
tk_object_get_prop_str(TK_OBJECT(info), SYSTEM_INFO_PROP_DEVICE_ORIENTATION));
2019-03-07 15:25:11 +08:00
ASSERT_EQ(system_info_set_lcd_w(info, 1000), RET_OK);
2021-12-08 15:20:36 +08:00
ASSERT_STREQ("landscape",
tk_object_get_prop_str(TK_OBJECT(info), SYSTEM_INFO_PROP_DEVICE_ORIENTATION));
2019-03-08 18:51:09 +08:00
locale_info_change(locale_info(), "zh", "CN");
ASSERT_STREQ("zh", tk_object_get_prop_str(TK_OBJECT(info), SYSTEM_INFO_PROP_LANGUAGE));
ASSERT_STREQ("CN", tk_object_get_prop_str(TK_OBJECT(info), SYSTEM_INFO_PROP_COUNTRY));
2019-03-08 18:51:09 +08:00
tk_object_unref(TK_OBJECT(info));
2019-03-08 18:51:09 +08:00
}
static ret_t on_expr(void* ctx, const void* data) {
string& str = *(string*)ctx;
if (str != "") {
str += ";";
}
str += (char*)data;
return RET_FAIL;
}
TEST(SystemInfo, expr) {
string str;
system_info_t* info = system_info_create(APP_DESKTOP, "awtk", "awtk_dir");
locale_info_change(locale_info(), "zh", "CN");
ASSERT_EQ(system_info_set_lcd_w(info, 100), RET_OK);
ASSERT_EQ(system_info_set_lcd_h(info, 200), RET_OK);
str = "";
system_info_eval_exprs(info, "", on_expr, &str);
ASSERT_EQ(str, string(""));
str = "";
system_info_eval_exprs(info, "abc", on_expr, &str);
ASSERT_EQ(str, string("abc"));
str = "";
system_info_eval_exprs(info, "abc,123", on_expr, &str);
ASSERT_EQ(str, string("abc;123"));
str = "";
system_info_eval_exprs(info, "abc_${lcd_w},123_${lcd_h}", on_expr, &str);
ASSERT_EQ(str, string("abc_100;123_200"));
str = "";
system_info_eval_exprs(info, "abc_${lcd_w},123_${lcd_h},bg_${app_name}", on_expr, &str);
ASSERT_EQ(str, string("abc_100;123_200;bg_awtk"));
str = "";
system_info_eval_exprs(info, "bg_${language}_${country},bg_${language},bg_${country}", on_expr,
&str);
ASSERT_EQ(str, string("bg_zh_CN;bg_zh;bg_CN"));
2019-03-07 15:25:11 +08:00
tk_object_unref(TK_OBJECT(info));
2019-03-07 15:25:11 +08:00
}