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"
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);
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);
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
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);
}
#include <memory>
#include <string>
+#include <vector>
#include "theme/loader/theme_info.h"
#include "theme_provider/db_manager.h"
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;
#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_;
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);
}
#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_;
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);
+}