From cd33f6bfbe9ec019fdc42bc5a0adecaadb58f1f8 Mon Sep 17 00:00:00 2001 From: Rafal Bednarski Date: Mon, 10 Jun 2013 17:54:26 +0200 Subject: [PATCH] [Daily Tests] wrt-commons-tests-dao fix [Issue] LINUXWRT-147 [Problem] wrt-commons-tests-dao tests do not pass in 100% [Cause] N/A [Solution] Fixed wrt_dao_tests_prepare_db.sh script, especially lines responsible for inserting data in the WidgetPreference table. Changed property_dao_get_lists in file TestCase_PropertyDAO.cpp Procedure is not sensitive for WidgetNotExist exception from now. [Verification] 1. Build wrt-commons repository 2. Tests wrt-commons-test-dao on target. All tests should pass in 100%. Change-Id: Ifc3e799287b0d3e74efc8103d24ba867d96ddf94 --- .../widget_dao/dao/property_dao_read_only.cpp | 42 +++++----- tests/dao/TestCases_PropertyDAO.cpp | 81 ++++++++++++++++--- tests/dao/wrt_dao_tests_prepare_db.sh | 12 +-- 3 files changed, 95 insertions(+), 40 deletions(-) diff --git a/modules/widget_dao/dao/property_dao_read_only.cpp b/modules/widget_dao/dao/property_dao_read_only.cpp index 5e06afc..3676d5a 100644 --- a/modules/widget_dao/dao/property_dao_read_only.cpp +++ b/modules/widget_dao/dao/property_dao_read_only.cpp @@ -133,42 +133,40 @@ WidgetPropertyKeyList GetPropertyKeyList(TizenAppId tzAppid) } } -//deprecated -WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle) -{ - Try { - TizenAppId tzAppid = WidgetDAOReadOnly::getTzAppId(widgetHandle); - return GetPropertyList(tzAppid); - } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){ - WidgetPreferenceList empty; - return empty; - } -} -WidgetPreferenceList GetPropertyList(TizenAppId tzAppId) +WidgetPreferenceList GetPropertyListRows(DbWidgetHandle widgetHandle) { - LogDebug("Get Property list. tizenAppId: " << tzAppId); Try { using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt; - - DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppId)); - WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface()) - select->Where(Equals(widgetHandle)); - + select->Where(Equals(widgetHandle)); ORMWidgetPreferenceList ormPrefList = select->GetRowList(); WidgetPreferenceList prefList; convertWidgetPreferenceRow(ormPrefList, prefList); - return prefList; - } - Catch(DPL::DB::SqlConnection::Exception::Base){ + }Catch(DPL::DB::SqlConnection::Exception::Base){ ReThrowMsg(Exception::DatabaseError, - "Failure during getting property list"); + "Failure during getting property list"); } } +WidgetPreferenceList GetPropertyList(DbWidgetHandle widgetHandle) +{ + if(!(WidgetDAOReadOnly::isWidgetInstalled(widgetHandle))) + ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, + "Failed to get widget"); + return GetPropertyListRows(widgetHandle); +} + +WidgetPreferenceList GetPropertyList(TizenAppId tzAppId) +{ + LogDebug("Get Property list. tizenAppId: " << tzAppId); + DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppId)); + return GetPropertyListRows(widgetHandle); +} + + WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid, const WidgetPropertyKey &key) { diff --git a/tests/dao/TestCases_PropertyDAO.cpp b/tests/dao/TestCases_PropertyDAO.cpp index effd898..8ddc977 100644 --- a/tests/dao/TestCases_PropertyDAO.cpp +++ b/tests/dao/TestCases_PropertyDAO.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using namespace WrtDB; using namespace WrtDB::PropertyDAOReadOnly; @@ -46,6 +47,7 @@ using namespace WrtDB::PropertyDAOReadOnly; RUNNER_TEST_GROUP_INIT(DAO) + /* * Name: property_dao_get_lists * Description: tests returning list of properties for given id @@ -55,20 +57,35 @@ RUNNER_TEST_GROUP_INIT(DAO) RUNNER_TEST(property_dao_get_lists) { { //property list - std::map prefsMap; - prefsMap.insert(std::pair(L"tizenid201", 2)); - prefsMap.insert(std::pair(L"tizenid202", 1)); - prefsMap.insert(std::pair(L"tizenid203", 2)); - //no widget - prefsMap.insert(std::pair(L"non_exists", 0)); - - FOREACH(it, prefsMap) { - PropertyDAOReadOnly::WidgetPreferenceList prefs = - PropertyDAOReadOnly::GetPropertyList(it->first); - RUNNER_ASSERT(prefs.size() == it->second); + struct three_field{ + WrtDB::TizenAppId tappid; + DbWidgetHandle whandleid; + size_t nrow; + }; + + three_field f3; + std::list prefList; + std::list::iterator it; + + f3.tappid=L"tizenid201";f3.whandleid=2000;f3.nrow=2; + prefList.push_back(f3); + f3.tappid=L"tizenid202"; f3.whandleid=2001;f3.nrow=1; + prefList.push_back(f3); + f3.tappid=L"tizenid203"; f3.whandleid=2002;f3.nrow=2; + prefList.push_back(f3); + f3.tappid=L"tizenid204"; f3.whandleid=2003;f3.nrow=0; + prefList.push_back(f3); + + for(it=prefList.begin();it!=prefList.end();++it) + { + PropertyDAOReadOnly::WidgetPreferenceList prefs_tid = + PropertyDAOReadOnly::GetPropertyList(it->tappid); + RUNNER_ASSERT(prefs_tid.size() == it->nrow); + PropertyDAOReadOnly::WidgetPreferenceList prefs_aid = + PropertyDAOReadOnly::GetPropertyList(it->whandleid); + RUNNER_ASSERT(prefs_aid.size() == it->nrow); } } - { //property key list WidgetPropertyKeyList orig_2000; orig_2000.push_back(DPL::FromUTF8String("key1_for_2000")); @@ -102,6 +119,46 @@ RUNNER_TEST(property_dao_get_lists) } } + +/* + * Name: property_dao_get_list_exceptions + * Description: tests returning exception for given tizen_appid if is + * not inserted into WidgetInfo table + * Expected: procedure passes when is exception. Widget absent in the WidgetInfo + * table. + */ +RUNNER_TEST(property_dao_get_list_exceptions) +{ + { + bool assert_flag; + WrtDB::TizenAppId app_id_non_exists = L"non_exists"; + + assert_flag=true; + Try{ + PropertyDAOReadOnly::WidgetPreferenceList prefs = + PropertyDAOReadOnly::GetPropertyList(app_id_non_exists); + } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) + { + assert_flag=false; + } + RUNNER_ASSERT_MSG(!(assert_flag),"Error, value doesn't make exception"); + } + { + bool assert_flag; + DbWidgetHandle handle_non_exist(2010); + assert_flag=true; + Try{ + PropertyDAOReadOnly::WidgetPreferenceList prefs = + PropertyDAOReadOnly::GetPropertyList(handle_non_exist); + } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) + { + assert_flag=false; + } + RUNNER_ASSERT_MSG(!(assert_flag),"Error, value doesn't make exception"); + } +} + + /* * Name: property_dao_set_update_remove * Description: tests set new property for widget, updating property and diff --git a/tests/dao/wrt_dao_tests_prepare_db.sh b/tests/dao/wrt_dao_tests_prepare_db.sh index ccb98f6..9666e87 100755 --- a/tests/dao/wrt_dao_tests_prepare_db.sh +++ b/tests/dao/wrt_dao_tests_prepare_db.sh @@ -66,7 +66,7 @@ if [ "x$1" == "xstart" ]; then INS_ALL_WIDGET_STARTFILE="insert into WidgetStartFile(app_id, src)" INS_ALL_WIDGET_LOC_STARTFILE="insert into WidgetLocalizedStartFile(app_id, start_file_id, widget_locale, type, encoding)" INS_ALL_WIDGET_DEFPREF="insert into WidgetDefaultPreference(app_id, key_name, key_value, readonly)" - INS_ALL_WIDGET_PREF="insert into WidgetPreference(tizen_appid, key_name, key_value, readonly)" + INS_ALL_WIDGET_PREF="insert into WidgetPreference(app_id,tizen_appid, key_name, key_value, readonly)" INS_ALL_WIDGET_FEATURE="insert into WidgetFeature(app_id, name)" INS_ALL_WIDGET_WINMODES="insert into WidgetWindowModes(app_id, window_mode)" INS_ALL_WIDGET_WARP="insert into WidgetWARPInfo(app_id, iri, subdomain_access)" @@ -106,11 +106,11 @@ if [ "x$1" == "xstart" ]; then sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2003, 4, 'en', '', '')"; #widget properties - sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tizenid201', 'key1_for_2000', 'value_for_key1_2000', 0)"; - sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tizenid201', 'key2_for_2000', 'value_for_key2_2000', 0)"; - sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tizenid202', 'key1_for_2001', 'value1_for_key_2001', 1)"; - sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tizenid203', 'key1_for_2002', 'value1_for_key_2002', 0)"; - sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tizenid203', 'key2_for_2002', 'value2_for_key_2002', 1)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2000,'tizenid201', 'key1_for_2000', 'value_for_key1_2000', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2000,'tizenid201', 'key2_for_2000', 'value_for_key2_2000', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2001,'tizenid202', 'key1_for_2001', 'value1_for_key_2001', 1)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2002,'tizenid203', 'key1_for_2002', 'value1_for_key_2002', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2002,'tizenid203', 'key2_for_2002', 'value2_for_key_2002', 1)"; #create if not exists and fix autoincrement value sqlite3 $WRT_DB "INSERT INTO WidgetInfo(tizen_appid) VALUES('temp')"; -- 2.34.1