From faf4ae8019f1113aaea9e2b33cb54fda73eb47aa Mon Sep 17 00:00:00 2001 From: Kamil Nowac Date: Fri, 17 May 2013 16:29:30 +0200 Subject: [PATCH] [Unit Tests] wrt-commons: DAO tests [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 | 5 +- .../widget_dao/dao/widget_dao_read_only.cpp | 2 +- tests/dao/TestCases_WidgetDAO.cpp | 88 ++++++++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/modules/widget_dao/dao/widget_dao.cpp b/modules/widget_dao/dao/widget_dao.cpp index ad1b7dc..2e79ea0 100644 --- a/modules/widget_dao/dao/widget_dao.cpp +++ b/modules/widget_dao/dao/widget_dao.cpp @@ -555,15 +555,16 @@ void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle, const WidgetRegisterInfo ®Info) { 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) } } diff --git a/modules/widget_dao/dao/widget_dao_read_only.cpp b/modules/widget_dao/dao/widget_dao_read_only.cpp index 846b32a..3890603 100644 --- a/modules/widget_dao/dao/widget_dao_read_only.cpp +++ b/modules/widget_dao/dao/widget_dao_read_only.cpp @@ -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 diff --git a/tests/dao/TestCases_WidgetDAO.cpp b/tests/dao/TestCases_WidgetDAO.cpp index 1d23c41..204bc3e 100644 --- a/tests/dao/TestCases_WidgetDAO.cpp +++ b/tests/dao/TestCases_WidgetDAO.cpp @@ -782,6 +782,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 @@ -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 -- 2.34.1