Add unit tests for Theme getter APIs 38/234538/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 27 May 2020 06:05:45 +0000 (15:05 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 27 May 2020 09:53:27 +0000 (09:53 +0000)
Change-Id: Ibc35dd8d55279b621155e374ae95c29cc168890e
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/unit_tests/test_theme.cc [new file with mode: 0644]

diff --git a/src/unit_tests/test_theme.cc b/src/unit_tests/test_theme.cc
new file mode 100644 (file)
index 0000000..c7c44b3
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <memory>
+
+#include "theme/loader/theme_info.h"
+#include "theme/api/theme.h"
+#include "theme/api/theme_error.h"
+
+using ttm::loader::ThemeInfo;
+
+class ThemeTest : public testing::Test {
+ public:
+  virtual ~ThemeTest() {}
+
+  virtual void SetUp() {
+  }
+
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(ThemeTest, Theme_GetId) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.0", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+  theme_h handle = static_cast<void*>(&info);
+  char *id;
+  int ret = theme_get_id(handle, &id);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(id), "testid");
+
+  free(id);
+}
+
+TEST_F(ThemeTest, Theme_GetVersion) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+  theme_h handle = static_cast<void*>(&info);
+  char *version;
+  int ret = theme_get_version(handle, &version);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(version), "1.0");
+
+  free(version);
+}
+
+TEST_F(ThemeTest, Theme_GetToolVersion) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+
+  theme_h handle = static_cast<void*>(&info);
+  char *version;
+  int ret = theme_get_tool_version(handle, &version);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(version), "1.1");
+
+  free(version);
+}
+
+TEST_F(ThemeTest, Theme_GetTitle) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+
+  theme_h handle = static_cast<void*>(&info);
+  char *title;
+  int ret = theme_get_title(handle, &title);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(title), "Test");
+
+  free(title);
+}
+
+TEST_F(ThemeTest, Theme_GetResolution) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+
+  theme_h handle = static_cast<void*>(&info);
+  char *resolution;
+  int ret = theme_get_resolution(handle, &resolution);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(resolution), "360X360");
+}
+
+TEST_F(ThemeTest, Theme_GetPreview) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+
+  theme_h handle = static_cast<void*>(&info);
+  char *preview;
+  int ret = theme_get_preview(handle, &preview);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(preview), "shared/res/preview.png");
+
+  free(preview);
+}
+
+TEST_F(ThemeTest, Theme_GetDescription) {
+  std::shared_ptr<ThemeInfo> info(
+      new ThemeInfo("testid", "1.0", "1.1", "Test", "360X360",
+          "shared/res/preview.png", "test"));
+
+  theme_h handle = static_cast<void*>(&info);
+  char *description;
+  int ret = theme_get_description(handle, &description);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(std::string(description), "test");
+
+  free(description);
+}