[Unit Tests] wrt-commons: DAO tests
authorKamil Nowac <k.nowac@partner.samsung.com>
Fri, 17 May 2013 14:29:30 +0000 (16:29 +0200)
committerGerrit Code Review <gerrit2@kim11>
Tue, 28 May 2013 13:52:22 +0000 (22:52 +0900)
[Issue#] LINUXWRT-147
[Problem] Lack of the privileges and app_control
[Cause] N/A
[Solution] Added widget_dao_test_register_app_control
and widget_dao_test_register_widget_privileges
[Verification]
1.Build wrt-commons repository with --define "WITH_TESTS ON"
2.Test wrt-commons-tests-dao on target. All tests should pass.

Change-Id: I5e880b195425b27ed7403be7500d9e1cb49a4ad1

modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/dao/widget_dao_read_only.cpp
tests/dao/TestCases_WidgetDAO.cpp

index ad1b7dc..2e79ea0 100644 (file)
@@ -555,15 +555,16 @@ void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
                                         const WidgetRegisterInfo &regInfo)
 {
     using namespace DPL::DB::ORM;
+    using namespace DPL::DB::ORM::wrt;
     const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
 
     FOREACH(it, widgetConfigurationInfo.privilegeList)
     {
-        wrt::WidgetPrivilege::Row widgetPrivilege;
+        WidgetPrivilege::Row widgetPrivilege;
         widgetPrivilege.Set_app_id(widgetHandle);
         widgetPrivilege.Set_name(it->name);
 
-        DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
+        DO_INSERT(widgetPrivilege, WidgetPrivilege)
     }
 }
 
index 846b32a..3890603 100644 (file)
@@ -1270,4 +1270,4 @@ WidgetSecurityModelVersion WidgetDAOReadOnly::getSecurityModelVersion() const
 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
 #undef CHECK_WIDGET_EXISTENCE
-} // namespace WrtDB
+} // namespace WrtDB
\ No newline at end of file
index 1d23c41..204bc3e 100644 (file)
@@ -783,6 +783,92 @@ RUNNER_TEST(widget_dao_test_register_widget_certificates)
 }
 
 /*
+ * Name: widget_dao_test_register_widget_privileges
+ * Description: Tests registration of widget privileges
+ */
+RUNNER_TEST(widget_dao_test_register_widget_privileges)
+{
+
+    WacSecurityMock sec;
+    WidgetRegisterInfo regInfo;
+
+    ConfigParserData::PrivilegeList& privilegeList =
+            regInfo.configInfo.privilegeList;
+    privilegeList.insert(DPL::FromUTF8String("name"));
+    privilegeList.insert(DPL::FromUTF8String("name2"));
+
+    TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
+    WidgetDAO dao(tizenAppId);
+
+    WrtDB::PrivilegeList privListFromDB;
+    privListFromDB = dao.getWidgetPrivilege();
+
+    RUNNER_ASSERT(privilegeList.size() == privListFromDB.size());
+
+    auto privListIt = privilegeList.begin();
+    auto privDBIt = privListFromDB.begin();
+    for(; privListIt != privilegeList.end() && privDBIt != privListFromDB.end();
+            ++privListIt, ++privDBIt)
+    {
+        RUNNER_ASSERT(*privDBIt == privListIt->name);
+    }
+}
+
+/*
+ * Name: widget_dao_test_register_app_control
+ * Description: Tests app control
+ */
+RUNNER_TEST(widget_dao_test_register_app_control)
+{
+    WacSecurityMock sec;
+    WidgetRegisterInfo regInfo;
+
+    ConfigParserData::AppControlInfo appControl(DPL::FromUTF8String("operation"));
+    appControl.m_disposition
+            = ConfigParserData::AppControlInfo::Disposition::WINDOW;
+    appControl.m_mimeList.insert(DPL::FromUTF8String("mime"));
+    appControl.m_src = DPL::FromUTF8String("src");
+    appControl.m_uriList.insert(DPL::FromUTF8String("uri"));
+
+    ConfigParserData::AppControlInfoList& appControlListRef
+            = regInfo.configInfo.appControlList;
+    appControlListRef.push_back(appControl);
+
+    TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
+
+    WidgetDAO dao(tizenAppId);
+
+    WrtDB::WidgetAppControlList appControlInfoListDB;
+    dao.getAppControlList(appControlInfoListDB);
+    RUNNER_ASSERT(appControlInfoListDB.size() == appControlListRef.size());
+    auto appDBIt = appControlInfoListDB.begin();
+    auto appRefIt = appControlListRef.begin();
+
+    for (;appDBIt != appControlInfoListDB.end()
+            && appRefIt != appControlListRef.end();
+            ++appDBIt, ++appRefIt)
+    {
+        RUNNER_ASSERT((WidgetAppControl::Disposition)
+                appRefIt->m_disposition == appDBIt->disposition);
+        RUNNER_ASSERT(appRefIt->m_index == appDBIt->index);
+        RUNNER_ASSERT(appRefIt->m_operation == appDBIt->operation);
+        RUNNER_ASSERT(appRefIt->m_src == appDBIt->src);
+        for(auto it = appRefIt->m_mimeList.begin();
+                it != appRefIt->m_mimeList.end();
+                ++it)
+        {
+            RUNNER_ASSERT((*it) == appDBIt->mime);
+        }
+        for(auto it = appRefIt->m_uriList.begin();
+                it != appRefIt->m_uriList.end();
+                ++it)
+        {
+            RUNNER_ASSERT((*it) == appDBIt->uri);
+        }
+    }
+}
+
+/*
  * Name: widget_dao_test_is_widget_installed
  * Description: Tests checking if widgets are installed
  * Expected: installed widgets should be stated as installed
@@ -1056,4 +1142,4 @@ RUNNER_TEST(widget_dao_test_register_csp_empty)
         RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
     }
 }
-#undef RUNNER_ASSERT_WHAT_EQUALS
+#undef RUNNER_ASSERT_WHAT_EQUALS
\ No newline at end of file