Implement GET_IDS command 24/234624/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 27 May 2020 11:29:39 +0000 (20:29 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 27 May 2020 11:30:21 +0000 (20:30 +0900)
Change-Id: I4a5f5bc6f429f508ba40bcc93f948cb8120b3106
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme_provider/db_manager.cc
src/theme_provider/db_manager.h
src/theme_provider/selection_request_handler.cc
src/theme_provider/theme_info_proxy.cc
src/theme_provider/theme_info_proxy.h
src/unit_tests/test_request_handlers.cc
src/unit_tests/test_theme_info_proxy.cc

index 4ed4e1e..fa4afec 100644 (file)
@@ -38,6 +38,7 @@ const char kDeleteQuery[] =
 const char kSelectQuery[] =
     "SELECT id, version, tool_version, title, description, preview, resolution,"
     "  details FROM theme WHERE id = ?";
+const char kSelectIdsQuery[] = "SELECT id FROM theme";
 const char kCreateThemeSettingTableQuery[] =
     "CREATE TABLE IF NOT EXISTS theme_setting (\n"
     "  dummy   INTEGER CHECK (dummy = 0),\n"
@@ -178,6 +179,17 @@ tizen_base::Bundle DbManager::Select(const std::string& id) {
   return b;
 }
 
+std::vector<std::string> DbManager::SelectIds() {
+  std::unique_ptr<SQLiteStatement> stmt =
+      conn_->PrepareStatement(kSelectIdsQuery);
+
+  std::vector<std::string> ids;
+  while (stmt->Step() == SQLiteStatement::StepResult::ROW)
+    ids.emplace_back(stmt->GetColumnString(0));
+
+  return ids;
+}
+
 bool DbManager::UpdateCurrentId(const std::string& id) {
   std::unique_ptr<SQLiteStatement> stmt =
       conn_->PrepareStatement(kSetThemeQuery);
index 1de8bfc..8fd820c 100644 (file)
@@ -30,6 +30,7 @@ class DbManager {
   bool Update(const std::string& id, const tizen_base::Bundle& info);
   bool Delete(const std::string& id);
   tizen_base::Bundle Select(const std::string& id);
+  std::vector<std::string> SelectIds();
   bool UpdateCurrentId(const std::string& id);
   void AddPackageEventListener(IThemePackageEvent* listener);
 
index e11ea43..e938b13 100644 (file)
@@ -16,10 +16,26 @@ namespace provider {
 
 tizen_base::Bundle SelectionRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
-  std::string id = args.GetString("id");
-  std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
-  return themeinfo->Serialize();
+  tizen_base::Bundle b;
+  switch (cmd) {
+    case dbus::Command::GET: {
+      std::string id = args.GetString("id");
+      std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
+      return themeinfo->Serialize();
+    }
+    case dbus::Command::GET_IDS: {
+      std::vector<std::string> ids = proxy_->GetThemeIds();
+      b.Add("ids", ids);
+      return b;
+    }
+    default: {
+      // this temporary return value should be fixed.
+      b.Add("result", "error");
+      return b;
+    }
+  }
 }
 
+
 }  // namespace provider
 }  // namespace ttm
index 201da06..3813c3a 100644 (file)
@@ -42,6 +42,10 @@ std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetLoadedTheme() {
   return cur_theme_;
 }
 
+std::vector<std::string> ThemeInfoProxy::GetThemeIds() {
+  return db_manager_->SelectIds();
+}
+
 bool ThemeInfoProxy::SetCurrentTheme(const std::string& id) {
   return db_manager_->UpdateCurrentId(id);
 }
index faa8fe1..1000155 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <memory>
 #include <string>
+#include <vector>
 
 #include "theme/loader/theme_info.h"
 #include "theme_provider/db_manager.h"
@@ -22,6 +23,7 @@ class ThemeInfoProxy : public IThemePackageEvent {
   bool UpdateTheme(const loader::ThemeInfo& info);
   bool RemoveTheme(const std::string& id);
   std::shared_ptr<loader::ThemeInfo> GetLoadedTheme();
+  std::vector<std::string> GetThemeIds();
   bool SetCurrentTheme(const std::string& id);
   void OnThemePackageChanged(const std::string& id) override;
 
index ed4dc29..efcaa53 100644 (file)
@@ -17,6 +17,7 @@
 #include <bundle_cpp.h>
 #include <gtest/gtest.h>
 
+#include <cstdio>
 #include <memory>
 
 #include "theme/dbus/request_handler.h"
 using ttm::loader::ThemeInfo;
 using ttm::provider::ThemeInfoProxy;
 
+namespace {
+
+const char kTestDb[] = "request_handler_test.db";
+
+}  // namespace
+
 class RequestHandlersTest : public testing::Test {
  public:
   virtual ~RequestHandlersTest() {}
 
   virtual void SetUp() {
-    proxy_ = std::make_shared<ThemeInfoProxy>("request_handler_test.db");
+    proxy_ = std::make_shared<ThemeInfoProxy>(kTestDb);
   }
 
   virtual void TearDown() {
+    std::remove(kTestDb);
   }
 
   std::shared_ptr<ThemeInfoProxy> proxy_;
@@ -95,10 +103,18 @@ TEST_F(RequestHandlersTest, SelectionRequestHandler_OnRequest) {
   ThemeInfo info("testid3", "1.0", "1.1", "Test3", "360X360",
       "shared/res/preview.png", "test");
   proxy_->SaveTheme(info);
+  ThemeInfo info2("testid4", "1.0", "1.1", "Test4", "360X360",
+      "shared/res/preview.png", "test");
+  proxy_->SaveTheme(info2);
+
   tizen_base::Bundle b;
   b.Add("id", "testid3");
 
   auto rb = handler.OnRequest(ttm::dbus::Command::GET, b);
   ThemeInfo theme(rb);
   EXPECT_EQ(theme.GetId(), "testid3");
+
+  rb = handler.OnRequest(ttm::dbus::Command::GET_IDS, {});
+  std::vector<std::string> ids = rb.GetStringArray("ids");
+  EXPECT_EQ(ids.size(), 2);
 }
index bb8569a..73d71aa 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <gtest/gtest.h>
 
+#include <cstdio>
 #include <memory>
 
 #include "theme_provider/theme_info_proxy.h"
 using ttm::loader::ThemeInfo;
 using ttm::provider::ThemeInfoProxy;
 
+namespace {
+
+const char kTestDb[] = "test.db";
+
+}  // namespace
+
 class ThemeInfoProxyTest : public testing::Test {
  public:
   virtual ~ThemeInfoProxyTest() {}
 
   virtual void SetUp() {
-    proxy_ = std::make_unique<ThemeInfoProxy>("test.db");
+    proxy_ = std::make_unique<ThemeInfoProxy>(kTestDb);
   }
 
   virtual void TearDown() {
+    std::remove(kTestDb);
   }
 
   std::unique_ptr<ThemeInfoProxy> proxy_;
@@ -91,3 +99,15 @@ TEST_F(ThemeInfoProxyTest, SetCurrentTheme_OnThemePackageChanged) {
   EXPECT_NE(cur, nullptr);
   EXPECT_EQ(cur->GetId(), "testid4");
 }
+
+TEST_F(ThemeInfoProxyTest, GetThemeIds) {
+  ThemeInfo info1("testid5", "1.0", "1.1", "Test5", "360X360",
+      "shared/res/preview.png", "test");
+  EXPECT_TRUE(proxy_->SaveTheme(info1));
+  ThemeInfo info2("testid6", "1.0", "1.1", "Test6", "360X360",
+      "shared/res/preview.png", "test");
+  EXPECT_TRUE(proxy_->SaveTheme(info2));
+
+  std::vector<std::string> ids = proxy_->GetThemeIds();
+  EXPECT_EQ(ids.size(), 2);
+}