From 7d6594ea2777dc0c4e5c14b84c3709a22bc84f75 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 23 Jun 2020 16:31:55 +0900 Subject: [PATCH] Improve coverage for theme_info Change-Id: Ice576c3ee77052af4a4b0e02751cd31e2becb797 Signed-off-by: Inkyun Kil --- test/unit_tests/test_theme.cc | 121 +++++++++++++++++++++++++++++++++++++ test/unit_tests/test_theme_info.cc | 116 ----------------------------------- 2 files changed, 121 insertions(+), 116 deletions(-) delete mode 100644 test/unit_tests/test_theme_info.cc diff --git a/test/unit_tests/test_theme.cc b/test/unit_tests/test_theme.cc index 817fdb9..1ef386c 100644 --- a/test/unit_tests/test_theme.cc +++ b/test/unit_tests/test_theme.cc @@ -31,6 +31,7 @@ class ThemeTest : public testing::Test { virtual ~ThemeTest() {} virtual void SetUp() { + std::vector ar = {"str1", "str2"}; b_.Add("id", "testid"); b_.Add("version", "1.0"); b_.Add("tool_version", "1.1"); @@ -38,6 +39,11 @@ class ThemeTest : public testing::Test { b_.Add("resolution", "360X360"); b_.Add("preview", "shared/res/preview.png"); b_.Add("description", "test"); + b_.Add("stringkey", "value"); + b_.Add("intkey", "1"); + b_.Add("floatkey", "2.0"); + b_.Add("boolkey", "true"); + b_.Add("arraykey", ar); } virtual void TearDown() { @@ -189,3 +195,118 @@ TEST_F(ThemeTest, Theme_GetDescription_N) { EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); } + +TEST_F(ThemeTest, Theme_GetString) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + char *str; + int ret = theme_get_string(handle, "stringkey", &str); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(std::string(str), "value"); + + free(str); +} + +TEST_F(ThemeTest, Theme_GetString_N) { + char *str; + int ret = theme_get_string(nullptr, "stringkey", &str); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); +} + +TEST_F(ThemeTest, Theme_GetStringArray) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + char **strarr; + int count; + int ret = theme_get_string_array(handle, "arraykey", &strarr, &count); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(std::string(strarr[0]), "str1"); + EXPECT_EQ(std::string(strarr[1]), "str2"); + EXPECT_EQ(count, 2); + + free(strarr); +} + +TEST_F(ThemeTest, Theme_GetStringArray_N) { + char **strarr; + int count; + int ret = theme_get_string_array(nullptr, "arraykey", &strarr, &count); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); +} + +TEST_F(ThemeTest, Theme_GetInt) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + int val; + int ret = theme_get_int(handle, "intkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(val, 1); +} + +TEST_F(ThemeTest, Theme_GetInt_N) { + int val; + int ret = theme_get_int(nullptr, "intkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); +} + +TEST_F(ThemeTest, Theme_GetFloat) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + float val; + int ret = theme_get_float(handle, "floatkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(val, 2.0); +} + +TEST_F(ThemeTest, Theme_GetFloat_N) { + float val; + int ret = theme_get_float(nullptr, "floatkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); +} + +TEST_F(ThemeTest, Theme_GetBool) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + bool val; + int ret = theme_get_bool(handle, "boolkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(val, true); +} + +TEST_F(ThemeTest, Theme_GetBool_N1) { + bool val; + int ret = theme_get_bool(nullptr, "boolkey", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER); +} + +TEST_F(ThemeTest, Theme_GetBool_N2) { + std::shared_ptr info( + new ThemeInfo(b_)); + + theme_h handle = static_cast(&info); + bool val; + int ret = theme_get_bool(handle, "boolkey_n", &val); + + EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE); + EXPECT_EQ(val, false); +} \ No newline at end of file diff --git a/test/unit_tests/test_theme_info.cc b/test/unit_tests/test_theme_info.cc deleted file mode 100644 index a57d846..0000000 --- a/test/unit_tests/test_theme_info.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include - -#include "theme/loader/theme_info.h" - -using ttm::loader::ThemeInfo; - -class ThemeInfoTest : public testing::Test { - public: - virtual ~ThemeInfoTest() {} - - virtual void SetUp() { - b_.Add("id", "testid"); - b_.Add("pkgid", "testpkgid"); - b_.Add("uid", "5001"); - b_.Add("version", "1.0"); - b_.Add("tool_version", "1.1"); - b_.Add("title", "Test"); - b_.Add("resolution", "360X360"); - b_.Add("preview", "shared/res/preview.png"); - b_.Add("description", "test"); - } - - virtual void TearDown() { - } - - tizen_base::Bundle b_; -}; - -TEST_F(ThemeInfoTest, ThemeInfo_GetId) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetId(), "testid"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetPkgid) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetPkgid(), "testpkgid"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetUid) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetUid(), 5001); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetVersion) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetVersion(), "1.0"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetToolVersion) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetToolVersion(), "1.1"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetTitle) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetTitle(), "Test"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetResolution) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetResolution(), "360X360"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetPreview) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetPreview(), "shared/res/preview.png"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_GetDescription) { - ThemeInfo info(b_); - - EXPECT_EQ(info.GetDescription(), "test"); -} - -TEST_F(ThemeInfoTest, ThemeInfo_Serialize) { - ThemeInfo info(b_); - - tizen_base::Bundle b = info.Serialize(); - EXPECT_EQ(b.GetString("id"), "testid"); - EXPECT_EQ(b.GetString("pkgid"), "testpkgid"); - EXPECT_EQ(b.GetString("uid"), "5001"); - EXPECT_EQ(b.GetString("version"), "1.0"); - EXPECT_EQ(b.GetString("tool_version"), "1.1"); - EXPECT_EQ(b.GetString("title"), "Test"); - EXPECT_EQ(b.GetString("resolution"), "360X360"); - EXPECT_EQ(b.GetString("preview"), "shared/res/preview.png"); - EXPECT_EQ(b.GetString("description"), "test"); -} \ No newline at end of file -- 2.7.4