* limitations under the License.
*/
-#include <bundle_cpp.h>
#include <gio/gio.h>
#include <gtest/gtest.h>
#include <memory>
#include <string>
-#include "theme/dbus/command.h"
-#include "theme/loader/theme_event.h"
-#include "theme/loader/theme_info.h"
-#include "theme/loader/theme_info_loader.h"
+#include "api/theme.h"
+#include "api/theme_error.h"
+#include "api/theme_loader.h"
+
+#include "loader/theme_event.h"
+#include "loader/theme_info.h"
+#include "loader/theme_info_loader.h"
+
#include "unit_tests/mock/gio_mock.h"
#include "unit_tests/mock/test_fixture.h"
using namespace ttm::loader;
+
using ::testing::_;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::StrEq;
+int changed_cb(theme_h handle, void *data) {
+ return 0;
+}
+
class ThemeEvent : public IThemeEvent {
public:
void OnThemeChanged(const ThemeInfo* theme,
class Mocks : public ::testing::NiceMock<GioMock> {};
-class ThemeInfoLoaderTest : public TestFixture {
+class ThemeLoaderTest : public TestFixture {
public:
- ThemeInfoLoaderTest() : TestFixture(std::make_unique<Mocks>()) {}
+ ThemeLoaderTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~ThemeLoaderTest() {}
virtual void SetUp() {
}
virtual void TearDown() {
}
- std::shared_ptr<ThemeInfoLoader> loader_ =
- std::make_shared<ThemeInfoLoader>();
+ theme_loader_h loader_handle_;
+ theme_loader_event_h event_handle_;
};
-TEST_F(ThemeInfoLoaderTest, RemoveEvent_N) {
- std::string id("id");
- int ret = loader_->RemoveEvent(id);
- EXPECT_NE(0, ret);
+TEST_F(ThemeLoaderTest, Create) {
+ theme_loader_h handle;
+ int ret = theme_loader_create(&handle);
+
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+ EXPECT_NE(handle, nullptr);
+
+ loader_handle_ = handle;
}
-TEST_F(ThemeInfoLoaderTest, QueryThemeId_N) {
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _)).
- WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
+TEST_F(ThemeLoaderTest, SetCurrent) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
GDBusMessage* msg =
reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
WillOnce(Return(msg));
tizen_base::Bundle b;
- std::vector<std::string> ids_vec;
+ ThemeInfo ti;
b.Add(ttm::dbus::kCmdResultKey, "ok");
- b.Add(ttm::dbus::kCmdDataKey, ids_vec);
+ b.Add(ttm::dbus::kCmdDataKey,
+ reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
auto br = b.ToRaw();
char* b_raw = reinterpret_cast<char*>(br.first.get());
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_message_get_body(_)).WillOnce(
Return(reinterpret_cast<GVariant*>(g_variant_new("(s)", b_raw))));
- std::vector<std::string> ids = loader_->QueryThemeId();
- EXPECT_EQ(0, ids.size());
-}
+ int ret;
-TEST_F(ThemeInfoLoaderTest, SetCurrent) {
- loader_->SetCurrent(std::string("id"));
+ ret = theme_loader_set_current(loader_handle_, "id");
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
-TEST_F(ThemeInfoLoaderTest, LoadCurrent) {
+TEST_F(ThemeLoaderTest, LoadCurrent) {
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_message_new_method_call(_, _, _, _)).
WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
g_dbus_message_get_body(_)).WillOnce(
Return(reinterpret_cast<GVariant*>(g_variant_new("(s)", b_raw))));
- std::shared_ptr<ThemeInfo> info = loader_->LoadCurrent();
- EXPECT_NE(nullptr, info);
+ int ret;
+ theme_h theme_handle;
+
+ ret = theme_loader_load_current(loader_handle_, &theme_handle);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+ EXPECT_NE(theme_handle, nullptr);
+
+ theme_destroy(theme_handle);
}
-TEST_F(ThemeInfoLoaderTest, Load) {
+TEST_F(ThemeLoaderTest, Load) {
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_message_new_method_call(StrEq("org.tizen.ThemeManager"),
StrEq("/org/tizen/ThemeManager"), StrEq("org.tizen.ThemeManager"),
g_dbus_message_get_body(_)).WillOnce(
Return(reinterpret_cast<GVariant*>(g_variant_new("(s)", b_raw))));
- std::shared_ptr<ThemeInfo> info = loader_->Load(std::string("id"));
- EXPECT_NE(nullptr, info);
+ theme_h theme_handle;
+ int ret;
+
+ ret = theme_loader_load(loader_handle_, "id", &theme_handle);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+ EXPECT_NE(theme_handle, nullptr);
+
+ theme_destroy(theme_handle);
+}
+
+TEST_F(ThemeLoaderTest, QueryID) {
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
+ GDBusMessage* msg =
+ reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
+ WillOnce(Return(msg));
+ tizen_base::Bundle b;
+ std::vector<std::string> ids_vec;
+ b.Add(ttm::dbus::kCmdResultKey, "ok");
+ b.Add(ttm::dbus::kCmdDataKey, ids_vec);
+ auto br = b.ToRaw();
+ char* b_raw = reinterpret_cast<char*>(br.first.get());
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_get_body(_)).WillOnce(
+ Return(reinterpret_cast<GVariant*>(g_variant_new("(s)", b_raw))));
+
+ int ret;
+ int count;
+ char **ids;
+
+ ret = theme_loader_query_id(loader_handle_, &ids, &count);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+ EXPECT_EQ(count, 0);
+}
+
+TEST_F(ThemeLoaderTest, AddEvent) {
+ theme_loader_event_h event_handle;
+ int ret;
+
+ ret = theme_loader_add_event(loader_handle_, changed_cb,
+ nullptr, &event_handle);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+ EXPECT_NE(event_handle, nullptr);
+
+ event_handle_ = event_handle;
+}
+
+TEST_F(ThemeLoaderTest, RemoveEvent) {
+ int ret;
+
+ ret = theme_loader_remove_event(loader_handle_, event_handle_);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
+
+TEST_F(ThemeLoaderTest, Destroy) {
+ int ret = theme_loader_destroy(loader_handle_);
+ EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+}
\ No newline at end of file