1115cd2caSopenharmony_ci/* 2115cd2caSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3115cd2caSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4115cd2caSopenharmony_ci * you may not use this file except in compliance with the License. 5115cd2caSopenharmony_ci * You may obtain a copy of the License at 6115cd2caSopenharmony_ci * 7115cd2caSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8115cd2caSopenharmony_ci * 9115cd2caSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10115cd2caSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11115cd2caSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12115cd2caSopenharmony_ci * See the License for the specific language governing permissions and 13115cd2caSopenharmony_ci * limitations under the License. 14115cd2caSopenharmony_ci */ 15115cd2caSopenharmony_ci 16115cd2caSopenharmony_ci#include "contactpinyin_test.h" 17115cd2caSopenharmony_ci 18115cd2caSopenharmony_ci#include "construction_name.h" 19115cd2caSopenharmony_ci#include "test_common.h" 20115cd2caSopenharmony_ci 21115cd2caSopenharmony_cinamespace Contacts { 22115cd2caSopenharmony_cinamespace Test { 23115cd2caSopenharmony_ciContactPinyinTest::ContactPinyinTest() 24115cd2caSopenharmony_ci{ 25115cd2caSopenharmony_ci} 26115cd2caSopenharmony_ci 27115cd2caSopenharmony_ciContactPinyinTest::~ContactPinyinTest() 28115cd2caSopenharmony_ci{ 29115cd2caSopenharmony_ci} 30115cd2caSopenharmony_ci 31115cd2caSopenharmony_ciint64_t ContactPinyinTest::RawContactInsert(std::string displayName, 32115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket &rawContactValues) 33115cd2caSopenharmony_ci{ 34115cd2caSopenharmony_ci OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT); 35115cd2caSopenharmony_ci rawContactValues.Put("display_name", displayName); 36115cd2caSopenharmony_ci int64_t code = contactsDataAbility.Insert(uriRawContact, rawContactValues); 37115cd2caSopenharmony_ci return code; 38115cd2caSopenharmony_ci} 39115cd2caSopenharmony_ci 40115cd2caSopenharmony_ciint64_t ContactPinyinTest::ContactDataInsert(int64_t rawContactId, std::string contentType, std::string detailInfo, 41115cd2caSopenharmony_ci std::string position, OHOS::DataShare::DataShareValuesBucket &contactDataValues) 42115cd2caSopenharmony_ci{ 43115cd2caSopenharmony_ci OHOS::Uri uriContactData(ContactsUri::CONTACT_DATA); 44115cd2caSopenharmony_ci contactDataValues.Put("raw_contact_id", rawContactId); 45115cd2caSopenharmony_ci contactDataValues.Put("content_type", contentType); 46115cd2caSopenharmony_ci contactDataValues.Put("detail_info", detailInfo); 47115cd2caSopenharmony_ci contactDataValues.Put("position", position); 48115cd2caSopenharmony_ci int64_t code = contactsDataAbility.Insert(uriContactData, contactDataValues); 49115cd2caSopenharmony_ci return code; 50115cd2caSopenharmony_ci} 51115cd2caSopenharmony_ci 52115cd2caSopenharmony_cistd::shared_ptr<OHOS::DataShare::DataShareResultSet> ContactPinyinTest::ContactQuery( 53115cd2caSopenharmony_ci const std::string &tableName, std::vector<std::string> columns, OHOS::DataShare::DataSharePredicates predicates) 54115cd2caSopenharmony_ci{ 55115cd2caSopenharmony_ci std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet; 56115cd2caSopenharmony_ci if (tableName == ContactTabName::RAW_CONTACT) { 57115cd2caSopenharmony_ci OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT); 58115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriRawContact, predicates, columns); 59115cd2caSopenharmony_ci } else if (tableName == ContactTabName::CONTACT_DATA) { 60115cd2caSopenharmony_ci OHOS::Uri uriContactData(ContactsUri::CONTACT_DATA); 61115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriContactData, predicates, columns); 62115cd2caSopenharmony_ci } else if (tableName == ContactTabName::CONTACT) { 63115cd2caSopenharmony_ci OHOS::Uri uriContact(ContactsUri::CONTACT); 64115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriContact, predicates, columns); 65115cd2caSopenharmony_ci } else if (tableName == ContactTabName::GROUPS) { 66115cd2caSopenharmony_ci OHOS::Uri uriGroups(ContactsUri::GROUPS); 67115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriGroups, predicates, columns); 68115cd2caSopenharmony_ci } else if (tableName == ContactTabName::CONTACT_BLOCKLIST) { 69115cd2caSopenharmony_ci OHOS::Uri uriBlocklist(ContactsUri::BLOCKLIST); 70115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriBlocklist, predicates, columns); 71115cd2caSopenharmony_ci } else if (tableName == ContactTabName::DELETED_RAW_CONTACT) { 72115cd2caSopenharmony_ci OHOS::Uri uriDeletedRawContact(ContactsUri::DELETED_RAW_CONTACT); 73115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriDeletedRawContact, predicates, columns); 74115cd2caSopenharmony_ci } else if (tableName == ContactTabName::SEARCH_CONTACT) { 75115cd2caSopenharmony_ci OHOS::Uri uriSearchContact(ContactsUri::SEARCH); 76115cd2caSopenharmony_ci resultSet = contactsDataAbility.Query(uriSearchContact, predicates, columns); 77115cd2caSopenharmony_ci } else { 78115cd2caSopenharmony_ci HILOG_ERROR("ContactsDataAbility ====>no match uri action"); 79115cd2caSopenharmony_ci } 80115cd2caSopenharmony_ci return resultSet; 81115cd2caSopenharmony_ci} 82115cd2caSopenharmony_ci 83115cd2caSopenharmony_civoid ContactPinyinTest::QueryAndExpectResult(std::string &tableName, OHOS::DataShare::DataSharePredicates predicates, 84115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket &values, std::string testName) 85115cd2caSopenharmony_ci{ 86115cd2caSopenharmony_ci std::vector<std::string> columns; 87115cd2caSopenharmony_ci std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet = ContactQuery(tableName, columns, predicates); 88115cd2caSopenharmony_ci CheckResultSet(values, resultSet, testName); 89115cd2caSopenharmony_ci} 90115cd2caSopenharmony_ci 91115cd2caSopenharmony_civoid ContactPinyinTest::ClearData() 92115cd2caSopenharmony_ci{ 93115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 94115cd2caSopenharmony_ci OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT); 95115cd2caSopenharmony_ci predicates.NotEqualTo("id", "0"); 96115cd2caSopenharmony_ci predicates.And(); 97115cd2caSopenharmony_ci predicates.EqualTo("is_deleted", "0"); 98115cd2caSopenharmony_ci contactsDataAbility.Delete(uriRawContact, predicates); 99115cd2caSopenharmony_ci int time = 1000; 100115cd2caSopenharmony_ci std::chrono::milliseconds dura(time); 101115cd2caSopenharmony_ci std::this_thread::sleep_for(dura); 102115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates2; 103115cd2caSopenharmony_ci OHOS::Uri uriRawContactComplete(ContactsUri::DELETED_RAW_CONTACT); 104115cd2caSopenharmony_ci predicates2.NotEqualTo("id", "0"); 105115cd2caSopenharmony_ci contactsDataAbility.Delete(uriRawContactComplete, predicates2); 106115cd2caSopenharmony_ci} 107115cd2caSopenharmony_ci 108115cd2caSopenharmony_ci/* 109115cd2caSopenharmony_ci * @tc.number name_convert_to_pinyin_test_100 110115cd2caSopenharmony_ci * @tc.name Insert a simplified Chinese name to view the converted Pinyin 111115cd2caSopenharmony_ci * @tc.desc Contacts name conversion pinyin ability 112115cd2caSopenharmony_ci * @tc.level Level1 113115cd2caSopenharmony_ci * @tc.size MediumTest 114115cd2caSopenharmony_ci * @tc.type Function 115115cd2caSopenharmony_ci */ 116115cd2caSopenharmony_ciHWTEST_F(ContactPinyinTest, pinyin_conversion_Insert_test_100, testing::ext::TestSize.Level1) 117115cd2caSopenharmony_ci{ 118115cd2caSopenharmony_ci HILOG_INFO("-------pinyin_conversion_Insert_test_100 is starting!------"); 119115cd2caSopenharmony_ci std::string tag("pinyin_conversion_Insert_test_100"); 120115cd2caSopenharmony_ci OHOS::Contacts::ConstructionName::local = "zh-CN"; 121115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket rawContactValues; 122115cd2caSopenharmony_ci int64_t rawContactId = RawContactInsert("李想", rawContactValues); 123115cd2caSopenharmony_ci EXPECT_GT(rawContactId, 0); 124115cd2caSopenharmony_ci 125115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket values; 126115cd2caSopenharmony_ci int64_t contactDataId = ContactDataInsert(rawContactId, "name", "李想", "", values); 127115cd2caSopenharmony_ci EXPECT_GT(contactDataId, 0); 128115cd2caSopenharmony_ci 129115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 130115cd2caSopenharmony_ci predicates.EqualTo("raw_contact_id", std::to_string(rawContactId)); 131115cd2caSopenharmony_ci std::string searchContact = ContactTabName::SEARCH_CONTACT; 132115cd2caSopenharmony_ci QueryAndExpectResult(searchContact, predicates, values, "pinyin_conversion_Insert_test_100"); 133115cd2caSopenharmony_ci ClearData(); 134115cd2caSopenharmony_ci} 135115cd2caSopenharmony_ci 136115cd2caSopenharmony_ci/* 137115cd2caSopenharmony_ci * @tc.number pinyin_conversion_Insert_test_200 138115cd2caSopenharmony_ci * @tc.name Insert a traditional Chinese name and view the converted Pinyin 139115cd2caSopenharmony_ci * @tc.desc Contacts name conversion pinyin ability 140115cd2caSopenharmony_ci * @tc.level Level1 141115cd2caSopenharmony_ci * @tc.size MediumTest 142115cd2caSopenharmony_ci * @tc.type Function 143115cd2caSopenharmony_ci */ 144115cd2caSopenharmony_ciHWTEST_F(ContactPinyinTest, pinyin_conversion_Insert_test_200, testing::ext::TestSize.Level1) 145115cd2caSopenharmony_ci{ 146115cd2caSopenharmony_ci HILOG_INFO("-------pinyin_conversion_Insert_test_200 is starting!------"); 147115cd2caSopenharmony_ci std::string tag("pinyin_conversion_Insert_test_200"); 148115cd2caSopenharmony_ci OHOS::Contacts::ConstructionName::local = "zh-CN"; 149115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket rawContactValues; 150115cd2caSopenharmony_ci int64_t rawContactId = RawContactInsert("張三", rawContactValues); 151115cd2caSopenharmony_ci EXPECT_GT(rawContactId, 0); 152115cd2caSopenharmony_ci 153115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket values; 154115cd2caSopenharmony_ci int64_t contactDataId = ContactDataInsert(rawContactId, "name", "張三", "", values); 155115cd2caSopenharmony_ci EXPECT_GT(contactDataId, 0); 156115cd2caSopenharmony_ci 157115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 158115cd2caSopenharmony_ci predicates.EqualTo("raw_contact_id", std::to_string(rawContactId)); 159115cd2caSopenharmony_ci std::string searchContact = ContactTabName::SEARCH_CONTACT; 160115cd2caSopenharmony_ci QueryAndExpectResult(searchContact, predicates, values, "pinyin_conversion_Insert_test_200"); 161115cd2caSopenharmony_ci ClearData(); 162115cd2caSopenharmony_ci} 163115cd2caSopenharmony_ci 164115cd2caSopenharmony_ci/* 165115cd2caSopenharmony_ci * @tc.number pinyin_conversion_Insert_test_300 166115cd2caSopenharmony_ci * @tc.name Insert an English name to view the converted Pinyin 167115cd2caSopenharmony_ci * @tc.desc Contacts name conversion pinyin ability 168115cd2caSopenharmony_ci * @tc.level Level1 169115cd2caSopenharmony_ci * @tc.size MediumTest 170115cd2caSopenharmony_ci * @tc.type Function 171115cd2caSopenharmony_ci */ 172115cd2caSopenharmony_ciHWTEST_F(ContactPinyinTest, pinyin_conversion_Insert_test_300, testing::ext::TestSize.Level1) 173115cd2caSopenharmony_ci{ 174115cd2caSopenharmony_ci HILOG_INFO("-------pinyin_conversion_Insert_test_300 is starting!------"); 175115cd2caSopenharmony_ci OHOS::Contacts::ConstructionName::local = "other"; 176115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket rawContactValues; 177115cd2caSopenharmony_ci int64_t rawContactId = RawContactInsert("Tom", rawContactValues); 178115cd2caSopenharmony_ci EXPECT_GT(rawContactId, 0); 179115cd2caSopenharmony_ci 180115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket values; 181115cd2caSopenharmony_ci int64_t contactDataId = ContactDataInsert(rawContactId, "name", "Tom", "", values); 182115cd2caSopenharmony_ci HILOG_INFO("pinyin_conversion_Insert_test_300 : contactDataId = %{public}ld", contactDataId); 183115cd2caSopenharmony_ci EXPECT_GT(contactDataId, 0); 184115cd2caSopenharmony_ci 185115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 186115cd2caSopenharmony_ci predicates.EqualTo("raw_contact_id", std::to_string(rawContactId)); 187115cd2caSopenharmony_ci std::string searchContact = ContactTabName::SEARCH_CONTACT; 188115cd2caSopenharmony_ci QueryAndExpectResult(searchContact, predicates, values, "Tom||Tom||Tom"); 189115cd2caSopenharmony_ci ClearData(); 190115cd2caSopenharmony_ci} 191115cd2caSopenharmony_ci 192115cd2caSopenharmony_ci/* 193115cd2caSopenharmony_ci * @tc.number abnormal_pinyin_conversion_Insert_test_400 194115cd2caSopenharmony_ci * @tc.name Insert a name with special characters to view the converted Pinyin 195115cd2caSopenharmony_ci * @tc.desc Exception use case 196115cd2caSopenharmony_ci * @tc.level Level1 197115cd2caSopenharmony_ci * @tc.size MediumTest 198115cd2caSopenharmony_ci * @tc.type Function 199115cd2caSopenharmony_ci */ 200115cd2caSopenharmony_ciHWTEST_F(ContactPinyinTest, abnormal_pinyin_conversion_Insert_test_400, testing::ext::TestSize.Level1) 201115cd2caSopenharmony_ci{ 202115cd2caSopenharmony_ci HILOG_INFO("-------abnormal_pinyin_conversion_Insert_test_400 is starting!------"); 203115cd2caSopenharmony_ci OHOS::Contacts::ConstructionName::local = "zh-CN"; 204115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket rawContactValues; 205115cd2caSopenharmony_ci int64_t rawContactId = RawContactInsert("李%^玉@成", rawContactValues); 206115cd2caSopenharmony_ci EXPECT_GT(rawContactId, 0); 207115cd2caSopenharmony_ci 208115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket values; 209115cd2caSopenharmony_ci int64_t contactDataId = ContactDataInsert(rawContactId, "name", "李%^玉@成", "", values); 210115cd2caSopenharmony_ci EXPECT_GT(contactDataId, 0); 211115cd2caSopenharmony_ci 212115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 213115cd2caSopenharmony_ci predicates.EqualTo("raw_contact_id", std::to_string(rawContactId)); 214115cd2caSopenharmony_ci std::string searchContact = ContactTabName::SEARCH_CONTACT; 215115cd2caSopenharmony_ci QueryAndExpectResult(searchContact, predicates, values, "李%^玉@成||li%^yu@cheng||l%^y@c"); 216115cd2caSopenharmony_ci ClearData(); 217115cd2caSopenharmony_ci} 218115cd2caSopenharmony_ci 219115cd2caSopenharmony_ci/* 220115cd2caSopenharmony_ci * @tc.number abnormal_pinyin_conversion_Insert_test_500 221115cd2caSopenharmony_ci * @tc.name Insert a name in multiple languages and view the converted Pinyin 222115cd2caSopenharmony_ci * @tc.desc Exception use case 223115cd2caSopenharmony_ci * @tc.level Level1 224115cd2caSopenharmony_ci * @tc.size MediumTest 225115cd2caSopenharmony_ci * @tc.type Function 226115cd2caSopenharmony_ci */ 227115cd2caSopenharmony_ciHWTEST_F(ContactPinyinTest, abnormal_pinyin_conversion_Insert_test_500, testing::ext::TestSize.Level1) 228115cd2caSopenharmony_ci{ 229115cd2caSopenharmony_ci HILOG_INFO("-------abnormal_pinyin_conversion_Insert_test_500 is starting!------"); 230115cd2caSopenharmony_ci OHOS::Contacts::ConstructionName::local = "zh-CN"; 231115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket rawContactValues; 232115cd2caSopenharmony_ci int64_t rawContactId = RawContactInsert("李bp玉成욱", rawContactValues); 233115cd2caSopenharmony_ci EXPECT_GT(rawContactId, 0); 234115cd2caSopenharmony_ci 235115cd2caSopenharmony_ci OHOS::DataShare::DataShareValuesBucket values; 236115cd2caSopenharmony_ci int64_t contactDataId = ContactDataInsert(rawContactId, "name", "李bp玉成욱", "", values); 237115cd2caSopenharmony_ci EXPECT_GT(contactDataId, 0); 238115cd2caSopenharmony_ci 239115cd2caSopenharmony_ci OHOS::DataShare::DataSharePredicates predicates; 240115cd2caSopenharmony_ci predicates.EqualTo("raw_contact_id", std::to_string(rawContactId)); 241115cd2caSopenharmony_ci std::string searchContact = ContactTabName::SEARCH_CONTACT; 242115cd2caSopenharmony_ci QueryAndExpectResult(searchContact, predicates, values, "李bp玉成욱||libpyucheng욱||lbpyc욱"); 243115cd2caSopenharmony_ci ClearData(); 244115cd2caSopenharmony_ci} 245115cd2caSopenharmony_ci} // namespace Test 246115cd2caSopenharmony_ci} // namespace Contacts