+#include <unistd.h>
#include <system_info.h>
#include "haltest.h"
#include "hal-display.h"
-using namespace std;
+static int image_effect_raw_to_enum(int effect);
/* Define Classes */
class DISPLAY : public testing::Test
{
protected:
+ static void SetUpHalTestSuite() {
+ int ret_val, val;
+ enum display_state state;
+ enum display_image_effect effect;
+ enum display_panel_mode pmode;
+
+ ret_val = system_info_get_platform_bool(FEATURE_DISPLAY, &DISPLAY::supported);
+ ASSERT_EQ(SYSTEM_INFO_ERROR_NONE, ret_val) << "system_info_get_platform_bool failed";
+
+ // setup original states for recovery after each testcase
+ ret_val = hal_device_display_get_brightness(&val);
+ orig_brightness = (ret_val == 0 ? val : -1);
+
+ ret_val = hal_device_display_get_state(&state);
+ orig_state = (ret_val == 0 ? state : -1);
+
+ ret_val = hal_device_display_get_image_effect(&effect);
+ orig_image_effect = (ret_val == 0 ? image_effect_raw_to_enum(effect) : -1);
+
+ ret_val = hal_device_display_get_panel_mode(&pmode);
+ orig_panel_mode = (ret_val == 0 ? pmode : -1);
+
+ ret_val = hal_device_display_get_frame_rate(&val);
+ orig_frame_rate = (ret_val == 0 ? val : -1);
+ }
+
void SetUp() override
{
- int ret;
- ret = system_info_get_platform_bool(FEATURE_DISPLAY, &display_supported);
- EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
}
void TearDown() override
}
- bool display_supported;
+ static void TearDownHalTestSuite() {
+ // restore original state if it hadn't been restored during testsuite.
+ if (DISPLAY::orig_brightness != -1)
+ hal_device_display_set_brightness(DISPLAY::orig_brightness);
+ if (DISPLAY::orig_state != -1)
+ hal_device_display_set_state((enum display_state)DISPLAY::orig_state);
+ if (DISPLAY::orig_image_effect != -1)
+ hal_device_display_set_image_effect((enum display_image_effect)DISPLAY::orig_image_effect);
+ if (DISPLAY::orig_panel_mode != -1)
+ hal_device_display_set_panel_mode((enum display_panel_mode)DISPLAY::orig_panel_mode);
+ if (DISPLAY::orig_frame_rate != -1)
+ hal_device_display_set_frame_rate(DISPLAY::orig_frame_rate);
+ }
+
+ static bool supported;
+
+ static int orig_brightness;
+ static int orig_state;
+ static int orig_image_effect;
+ static int orig_panel_mode;
+ static int orig_frame_rate;
};
+bool DISPLAY::supported = false;
+int DISPLAY::orig_brightness = -1;
+int DISPLAY::orig_state = -1;
+int DISPLAY::orig_image_effect = -1;
+int DISPLAY::orig_panel_mode = -1;
+int DISPLAY::orig_frame_rate = -1;
+
+/* For now, only tw3 and exynos9110 have get/set_image_effect function.
+ * But get_image_effect returns a raw value of the image effect node
+ * without converting it to enum. Therefore manually convert it. */
+static int image_effect_raw_to_enum(int effect)
+{
+ if (effect == 0)
+ return DISPLAY_IMAGE_EFFECT_STANDARD;
+ if (effect == 6)
+ return DISPLAY_IMAGE_EFFECT_NEGATIVE;
+ if (effect == 9)
+ return DISPLAY_IMAGE_EFFECT_GREY;
+ if (effect == 11)
+ return DISPLAY_IMAGE_EFFECT_GREY_NEGATIVE;
+
+ EXPECT_TRUE(false) << "Invalid image effect=" << effect;
+
+ return DISPLAY_IMAGE_EFFECT_MAX;
+}
/*
* Testcase for Display
*/
TEST_F(DISPLAY, GetBackendP)
{
- int ret;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_backend();
- EXPECT_EQ(ret, 0) << "Fail to get display device (" << ret << ")";
+ ret_val = hal_device_display_get_backend();
+ EXPECT_EQ(ret_val, 0) << "Failed to get display device (" << ret_val << ")";
}
TEST_F(DISPLAY, GetMaxBrightnessP)
{
- int ret;
+ int ret_val;
int max;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_max_brightness(&max);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_max_brightness(&max);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get max brightness (" << ret << ")";
+ EXPECT_EQ(ret_val, 0) << "Failed to get max brightness (" << ret_val << ")";
}
TEST_F(DISPLAY, GetBrightnessP)
{
- int ret;
+ int ret_val;
int brt;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_brightness(&brt);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_brightness(&brt);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get brightness (" << ret << ")";
+ ASSERT_EQ(ret_val, 0) << "Failed to get brightness (" << ret_val << ")";
}
TEST_F(DISPLAY, SetBrightnessP)
{
- int ret;
- int max = 100;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_set_brightness(max);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_set_brightness(100);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
+
+ ASSERT_EQ(ret_val, 0) << "Failed to set_brightness (" << ret_val << ")";
- EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")";
+ // restore
+ if (DISPLAY::orig_brightness != -1)
+ hal_device_display_set_brightness(DISPLAY::orig_brightness);
}
TEST_F(DISPLAY, SetMultiBrightnessP)
{
- int ret;
+ int ret_val;
int brt = 50, step = 5, delay = 10000;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_set_multi_brightness(brt, step, delay);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_set_multi_brightness(brt, step, delay);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to set multi brightness (" << ret << ")";
+ EXPECT_EQ(ret_val, 0) << "Failed to set multi brightness (" << ret_val << ")";
}
TEST_F(DISPLAY, GetAutoBrightnessP)
{
- int ret;
+ int ret_val;
int brt;
float lmax = 0, lmin = 0, light = 0;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_auto_brightness(lmax, lmin, light, &brt);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_auto_brightness(lmax, lmin, light, &brt);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get auto brightness (" << ret << ")";
+ EXPECT_EQ(ret_val, 0) << "Failed to get auto brightness (" << ret_val << ")";
}
TEST_F(DISPLAY, GetStateP)
{
- int ret;
+ int ret_val;
enum display_state state;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_state(&state);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_state(&state);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get state (" << ret << ")";
+ ASSERT_EQ(ret_val, 0) << "Failed to get state (" << ret_val << ")";
}
TEST_F(DISPLAY, SetStateP)
{
- int ret;
+ int ret_val;
+ enum display_state state;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_set_state(DISPLAY_ON);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_set_state(DISPLAY_ON);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
+
+ ASSERT_EQ(ret_val, 0) << "Failed to set state (" << ret_val << ")";
+
+ ret_val = hal_device_display_get_state(&state);
+ ASSERT_EQ(state, DISPLAY_ON) << "Failed to set DISPLAY_ON (" << ret_val << ")";
- EXPECT_EQ(ret, 0) << "Fail to set state (" << ret << ")";
+ ret_val = hal_device_display_set_state(DISPLAY_OFF);
+ ASSERT_EQ(ret_val, 0) << "Failed to set state (" << ret_val << ")";
+
+ ret_val = hal_device_display_get_state(&state);
+ ASSERT_EQ(state, DISPLAY_OFF) << "Failed to set DISPLAY_ON (" << ret_val << ")";
+
+ // restore
+ if (DISPLAY::orig_state != -1)
+ hal_device_display_set_state((enum display_state)DISPLAY::orig_state);
}
TEST_F(DISPLAY, GetImageEffectP)
{
enum display_image_effect effect;
- int ret;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_image_effect(&effect);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_image_effect(&effect);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get image effect (" << ret << ")";
+ ASSERT_EQ(ret_val, 0) << "Failed to get image effect (" << ret_val << ")";
}
TEST_F(DISPLAY, SetImageEffectP)
{
- int ret;
+ int ret_val;
+ int set_image_effect, get_image_effect;
+ enum display_image_effect get_image_effect_raw;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_set_image_effect(DISPLAY_IMAGE_EFFECT_GREY);
- if (ret == -ENODEV)
- return;
+ for (set_image_effect = DISPLAY_IMAGE_EFFECT_STANDARD;
+ set_image_effect <= DISPLAY_IMAGE_EFFECT_GREY_NEGATIVE; ++set_image_effect) {
+ ret_val = hal_device_display_set_image_effect((enum display_image_effect)set_image_effect);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
+ return;
+ }
+
+ EXPECT_EQ(ret_val, 0) << "Failed to set image effect (" << ret_val << ")";
+
+ ret_val = hal_device_display_get_image_effect(&get_image_effect_raw);
+ get_image_effect = image_effect_raw_to_enum(get_image_effect_raw);
+ EXPECT_EQ(get_image_effect, set_image_effect) << "Failed to set image effect";
- EXPECT_EQ(ret, 0) << "Fail to set image effect (" << ret << ")";
+ usleep(500000); /* 500ms */
+ }
+
+ // restore
+ if (DISPLAY::orig_image_effect != -1)
+ hal_device_display_set_image_effect((enum display_image_effect)DISPLAY::orig_image_effect);
}
TEST_F(DISPLAY, GetPanelModeP)
{
enum display_panel_mode mode;
- int ret;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_panel_mode(&mode);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_panel_mode(&mode);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get panel mode (" << ret << ")";
+ ASSERT_EQ(ret_val, 0) << "Failed to get panel mode (" << ret_val << ")";
}
TEST_F(DISPLAY, SetPanelModeP)
{
- int ret;
+ int ret_val;
+ int panel_mode;
+ enum display_panel_mode panel_mode_raw;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_set_panel_mode(DISPLAY_PANEL_MODE_LOWPOWER);
- if (ret == -ENODEV)
- return;
+ for (panel_mode = DISPLAY_PANEL_MODE_STANDARD;
+ panel_mode <= DISPLAY_PANEL_MODE_LOWPOWER; ++panel_mode) {
+ ret_val = hal_device_display_set_panel_mode((enum display_panel_mode)panel_mode);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
+ return;
+ }
+
+ EXPECT_EQ(ret_val, 0) << "Failed to set panel mode (" << ret_val << ")";
- EXPECT_EQ(ret, 0) << "Fail to set panel mode (" << ret << ")";
+ ret_val = hal_device_display_get_panel_mode(&panel_mode_raw);
+ EXPECT_EQ((int)panel_mode_raw, panel_mode) << "Failed to set panel mode";
+
+ usleep(500000); /* 500ms */
+ }
+
+ // restore
+ if (DISPLAY::orig_panel_mode != -1)
+ hal_device_display_set_panel_mode((enum display_panel_mode)DISPLAY::orig_panel_mode);
}
TEST_F(DISPLAY, GetAodModeP)
{
enum display_aod_mode mode;
- int ret;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_aod_mode(&mode);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_aod_mode(&mode);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_EQ(ret, 0) << "Fail to get aod mode (" << ret << ")";
+ ASSERT_EQ(ret_val, 0) << "Failed to get aod mode (" << ret_val << ")";
}
TEST_F(DISPLAY, GetAodBrightnessP)
{
int max, normal, min, charging;
- int ret;
+ int ret_val;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_aod_brightness(&max, &normal, &min, &charging);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_aod_brightness(&max, &normal, &min, &charging);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
-
- EXPECT_EQ(ret, 0) << "Fail to get aod brightness (" << ret << ")";
+ }
+ EXPECT_EQ(ret_val, 0) << "Failed to get aod brightness (" << ret_val << ")";
}
TEST_F(DISPLAY, GetMaxFrameRateP)
{
- int ret;
+ int ret_val;
int max;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_max_frame_rate(&max);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_max_frame_rate(&max);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_GE(ret, 0) << "Fail to get max frame_rate (" << ret << ")";
+ EXPECT_GE(ret_val, 0) << "Failed to get max frame_rate (" << ret_val << ")";
}
TEST_F(DISPLAY, GetMinFrameRateP)
{
- int ret;
+ int ret_val;
int min;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_min_frame_rate(&min);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_min_frame_rate(&min);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_GE(ret, 0) << "Fail to get min frame rate (" << ret << ")";
+ EXPECT_GE(ret_val, 0) << "Failed to get min frame rate (" << ret_val << ")";
}
TEST_F(DISPLAY, GetFrameRateP)
{
- int ret, rate;
+ int ret_val, rate;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_frame_rate(&rate);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_frame_rate(&rate);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_GE(ret, 0) << "Fail to get frame rate (" << ret << ")";
+ EXPECT_GE(ret_val, 0) << "Failed to get frame rate (" << ret_val << ")";
}
TEST_F(DISPLAY, SetFrameRateP)
{
- int ret, fmax;
+ int ret_val, fmax;
- if (!display_supported) {
+ if (!DISPLAY::supported) {
SKIP_MESSAGE("Display not supported");
return;
}
- ret = hal_device_display_get_max_frame_rate(&fmax);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_get_max_frame_rate(&fmax);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
- EXPECT_GE(ret, 0) << "Fail to get max frame rate (" << ret << ")";
+ EXPECT_GE(ret_val, 0) << "Failed to get max frame rate (" << ret_val << ")";
- ret = hal_device_display_set_frame_rate(fmax);
- if (ret == -ENODEV)
+ ret_val = hal_device_display_set_frame_rate(fmax);
+ if (ret_val == -ENODEV) {
+ SKIP_MESSAGE("Not supported HAL");
return;
+ }
+
+ EXPECT_GE(ret_val, 0) << "Failed to set frame rate (" << ret_val << ")";
- EXPECT_GE(ret, 0) << "Fail to set frame rate (" << ret << ")";
+ // restore
+ if (DISPLAY::orig_frame_rate != -1)
+ hal_device_display_set_frame_rate(DISPLAY::orig_frame_rate);
}