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 "mergecontact_test.h"
17115cd2caSopenharmony_ci
18115cd2caSopenharmony_ci#include <sys/time.h>
19115cd2caSopenharmony_ci
20115cd2caSopenharmony_ci#include "match_candidate.h"
21115cd2caSopenharmony_ci#include "merger_contacts.h"
22115cd2caSopenharmony_ci#include "test_common.h"
23115cd2caSopenharmony_ci
24115cd2caSopenharmony_cinamespace Contacts {
25115cd2caSopenharmony_cinamespace Test {
26115cd2caSopenharmony_civoid MergeContactTest::DeleteRawContact()
27115cd2caSopenharmony_ci{
28115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
29115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
30115cd2caSopenharmony_ci    predicates.NotEqualTo("id", "0");
31115cd2caSopenharmony_ci    predicates.And();
32115cd2caSopenharmony_ci    predicates.EqualTo("is_deleted", "0");
33115cd2caSopenharmony_ci    contactsDataAbility.Delete(uriRawContact, predicates);
34115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE_DELETE;
35115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
36115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
37115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates2;
38115cd2caSopenharmony_ci    OHOS::Uri uriRawContactComplete(ContactsUri::DELETED_RAW_CONTACT);
39115cd2caSopenharmony_ci    predicates2.NotEqualTo("id", "0");
40115cd2caSopenharmony_ci    contactsDataAbility.Delete(uriRawContactComplete, predicates2);
41115cd2caSopenharmony_ci}
42115cd2caSopenharmony_ci
43115cd2caSopenharmony_civoid MergeContactTest::CheckMergeResultId(std::vector<int64_t> ids, bool merge)
44115cd2caSopenharmony_ci{
45115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
46115cd2caSopenharmony_ci    int mergeIdSize = ids.size();
47115cd2caSopenharmony_ci    for (int i = 0; i < mergeIdSize; i++) {
48115cd2caSopenharmony_ci        std::vector<std::string> columns;
49115cd2caSopenharmony_ci        columns.push_back("contact_id");
50115cd2caSopenharmony_ci        OHOS::DataShare::DataSharePredicates predicates;
51115cd2caSopenharmony_ci        predicates.EqualTo("id", std::to_string(ids[i]));
52115cd2caSopenharmony_ci        std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultOne = ContactQuery(columns, predicates);
53115cd2caSopenharmony_ci        int contactIdOne = GetMergeResultContactId(resultOne);
54115cd2caSopenharmony_ci        resultIdVector.push_back(contactIdOne);
55115cd2caSopenharmony_ci    }
56115cd2caSopenharmony_ci    int size = resultIdVector.size();
57115cd2caSopenharmony_ci    int64_t contactId = resultIdVector[0];
58115cd2caSopenharmony_ci    for (int i = 1; i < size; i++) {
59115cd2caSopenharmony_ci        if (merge) {
60115cd2caSopenharmony_ci            EXPECT_EQ(contactId, resultIdVector[i]);
61115cd2caSopenharmony_ci            HILOG_INFO("merge contact_id = %{public}ld, contact_idTwo %{public}ld", contactId, resultIdVector[i]);
62115cd2caSopenharmony_ci        } else {
63115cd2caSopenharmony_ci            EXPECT_NE(contactId, resultIdVector[i]);
64115cd2caSopenharmony_ci            HILOG_INFO("split contact_id = %{public}ld", resultIdVector[i]);
65115cd2caSopenharmony_ci        }
66115cd2caSopenharmony_ci    }
67115cd2caSopenharmony_ci}
68115cd2caSopenharmony_ci
69115cd2caSopenharmony_ciint MergeContactTest::GetMergeResultContactId(const std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet)
70115cd2caSopenharmony_ci{
71115cd2caSopenharmony_ci    std::vector<std::string> columnNames;
72115cd2caSopenharmony_ci    resultSet->GetAllColumnNames(columnNames);
73115cd2caSopenharmony_ci    int resultSetIntValue = 0;
74115cd2caSopenharmony_ci    if (resultSet->GoToFirstRow() == OHOS::NativeRdb::E_OK) {
75115cd2caSopenharmony_ci        std::string typeValue = "contact_id";
76115cd2caSopenharmony_ci        int columnIndex = 0;
77115cd2caSopenharmony_ci        resultSet->GetColumnIndex(typeValue, columnIndex);
78115cd2caSopenharmony_ci        resultSet->GetInt(columnIndex, resultSetIntValue);
79115cd2caSopenharmony_ci    }
80115cd2caSopenharmony_ci    resultSet->Close();
81115cd2caSopenharmony_ci    return resultSetIntValue;
82115cd2caSopenharmony_ci}
83115cd2caSopenharmony_ci
84115cd2caSopenharmony_cistd::vector<int> MergeContactTest::GetMergeResultRawContactId(
85115cd2caSopenharmony_ci    const std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet)
86115cd2caSopenharmony_ci{
87115cd2caSopenharmony_ci    std::vector<int> rawContactIdVector;
88115cd2caSopenharmony_ci    std::vector<std::string> columnNames;
89115cd2caSopenharmony_ci    resultSet->GetAllColumnNames(columnNames);
90115cd2caSopenharmony_ci    int resultSetNum = resultSet->GoToFirstRow();
91115cd2caSopenharmony_ci    while (resultSetNum == OHOS::NativeRdb::E_OK) {
92115cd2caSopenharmony_ci        int resultSetIntValue = 0;
93115cd2caSopenharmony_ci        std::string typeValue = "raw_contact_id";
94115cd2caSopenharmony_ci        int columnIndex = 0;
95115cd2caSopenharmony_ci        resultSet->GetColumnIndex(typeValue, columnIndex);
96115cd2caSopenharmony_ci        resultSet->GetInt(columnIndex, resultSetIntValue);
97115cd2caSopenharmony_ci        rawContactIdVector.push_back(resultSetIntValue);
98115cd2caSopenharmony_ci        resultSetNum = resultSet->GoToNextRow();
99115cd2caSopenharmony_ci    }
100115cd2caSopenharmony_ci    resultSet->Close();
101115cd2caSopenharmony_ci    return rawContactIdVector;
102115cd2caSopenharmony_ci}
103115cd2caSopenharmony_ci
104115cd2caSopenharmony_cistd::vector<int> MergeContactTest::GetMergeRawContactId(
105115cd2caSopenharmony_ci    const std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet)
106115cd2caSopenharmony_ci{
107115cd2caSopenharmony_ci    std::vector<int> rawContactIdVector;
108115cd2caSopenharmony_ci    std::vector<std::string> columnNames;
109115cd2caSopenharmony_ci    resultSet->GetAllColumnNames(columnNames);
110115cd2caSopenharmony_ci    int resultSetNum = resultSet->GoToFirstRow();
111115cd2caSopenharmony_ci    while (resultSetNum == OHOS::NativeRdb::E_OK) {
112115cd2caSopenharmony_ci        int resultSetIntValue = 0;
113115cd2caSopenharmony_ci        std::string typeValue = "id";
114115cd2caSopenharmony_ci        int columnIndex = 0;
115115cd2caSopenharmony_ci        resultSet->GetColumnIndex(typeValue, columnIndex);
116115cd2caSopenharmony_ci        resultSet->GetInt(columnIndex, resultSetIntValue);
117115cd2caSopenharmony_ci        rawContactIdVector.push_back(resultSetIntValue);
118115cd2caSopenharmony_ci        resultSetNum = resultSet->GoToNextRow();
119115cd2caSopenharmony_ci    }
120115cd2caSopenharmony_ci    resultSet->Close();
121115cd2caSopenharmony_ci    return rawContactIdVector;
122115cd2caSopenharmony_ci}
123115cd2caSopenharmony_ci
124115cd2caSopenharmony_cistd::shared_ptr<OHOS::DataShare::DataShareResultSet> MergeContactTest::ContactQuery(
125115cd2caSopenharmony_ci    std::vector<std::string> columns, OHOS::DataShare::DataSharePredicates predicates)
126115cd2caSopenharmony_ci{
127115cd2caSopenharmony_ci    OHOS::Uri uri(ContactsUri::RAW_CONTACT);
128115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
129115cd2caSopenharmony_ci        contactsDataAbility.Query(uri, predicates, columns);
130115cd2caSopenharmony_ci    return resultSet;
131115cd2caSopenharmony_ci}
132115cd2caSopenharmony_ci
133115cd2caSopenharmony_ciint64_t MergeContactTest::RawContactInsert(std::string displayName)
134115cd2caSopenharmony_ci{
135115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
136115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket rawContactValues;
137115cd2caSopenharmony_ci    rawContactValues.Put("display_name", displayName);
138115cd2caSopenharmony_ci    int64_t code = contactsDataAbility.Insert(uriRawContact, rawContactValues);
139115cd2caSopenharmony_ci    rawContactValues.Clear();
140115cd2caSopenharmony_ci    return code;
141115cd2caSopenharmony_ci}
142115cd2caSopenharmony_ci
143115cd2caSopenharmony_ciint64_t MergeContactTest::ContactDataInsert(
144115cd2caSopenharmony_ci    int64_t rawContactId, std::string contentType, std::string detailInfo, std::string position)
145115cd2caSopenharmony_ci{
146115cd2caSopenharmony_ci    OHOS::Uri uriContactData(ContactsUri::CONTACT_DATA);
147115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket contactDataValues;
148115cd2caSopenharmony_ci    contactDataValues.Put("raw_contact_id", rawContactId);
149115cd2caSopenharmony_ci    contactDataValues.Put("content_type", contentType);
150115cd2caSopenharmony_ci    contactDataValues.Put("detail_info", detailInfo);
151115cd2caSopenharmony_ci    contactDataValues.Put("position", position);
152115cd2caSopenharmony_ci    int64_t code = contactsDataAbility.Insert(uriContactData, contactDataValues);
153115cd2caSopenharmony_ci    contactDataValues.Clear();
154115cd2caSopenharmony_ci    return code;
155115cd2caSopenharmony_ci}
156115cd2caSopenharmony_ci
157115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_test_start, testing::ext::TestSize.Level1)
158115cd2caSopenharmony_ci{
159115cd2caSopenharmony_ci    DeleteRawContact();
160115cd2caSopenharmony_ci}
161115cd2caSopenharmony_ci
162115cd2caSopenharmony_ci/*
163115cd2caSopenharmony_ci * @tc.number  merge_Query_test_100
164115cd2caSopenharmony_ci * @tc.name    Insert contacts with the same name and different mobile numbers,
165115cd2caSopenharmony_ci *              and check whether the database can find the contacts that can be merged
166115cd2caSopenharmony_ci * @tc.desc    A: xiaowuwuwu 123456, B: xiaowuwuwu 1234567
167115cd2caSopenharmony_ci * @tc.level   Level1
168115cd2caSopenharmony_ci * @tc.size    MediumTest
169115cd2caSopenharmony_ci * @tc.type    Function
170115cd2caSopenharmony_ci */
171115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Query_test_100, testing::ext::TestSize.Level1)
172115cd2caSopenharmony_ci{
173115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Query_test_100 query is starting! ---");
174115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaowuww");
175115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
176115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaowuww", "");
177115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
178115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_100 dataIdOne  = %{public}ld", dataIdOne);
179115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaowuww");
180115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
181115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaowuww", "");
182115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "1234567", "");
183115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_100 dataIdTwo  = %{public}ld", dataIdTwo);
184115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
185115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
186115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
187115cd2caSopenharmony_ci    OHOS::Uri uriQueryMergeList(ContactsUri::MERGE_LIST);
188115cd2caSopenharmony_ci    std::vector<std::string> columns;
189115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
190115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
191115cd2caSopenharmony_ci        contactsDataAbility.Query(uriQueryMergeList, predicates, columns);
192115cd2caSopenharmony_ci    int rowCount = 0;
193115cd2caSopenharmony_ci    resultSet->GetRowCount(rowCount);
194115cd2caSopenharmony_ci    EXPECT_EQ(2, rowCount);
195115cd2caSopenharmony_ci    std::vector<int> rawVector = GetMergeResultRawContactId(resultSet);
196115cd2caSopenharmony_ci    EXPECT_EQ(rawOne, rawVector[0]);
197115cd2caSopenharmony_ci    EXPECT_EQ(rawTwo, rawVector[1]);
198115cd2caSopenharmony_ci    DeleteRawContact();
199115cd2caSopenharmony_ci}
200115cd2caSopenharmony_ci
201115cd2caSopenharmony_ci/*
202115cd2caSopenharmony_ci * @tc.number  merge_Update_test_200
203115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name to check whether the database can be merged successfully
204115cd2caSopenharmony_ci * @tc.desc    A: xiaochenc, B: xiaochenc
205115cd2caSopenharmony_ci * @tc.level   Level1
206115cd2caSopenharmony_ci * @tc.size    MediumTest
207115cd2caSopenharmony_ci * @tc.type    Function
208115cd2caSopenharmony_ci */
209115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_200, testing::ext::TestSize.Level1)
210115cd2caSopenharmony_ci{
211115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_200 Add is starting! ---");
212115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaochenc");
213115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaochenc", "");
214115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_200 :  = %{public}ld", dataIdOne);
215115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaochenc");
216115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaochenc", "");
217115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_200 :  = %{public}ld", dataIdTwo);
218115cd2caSopenharmony_ci    int time = 2000;
219115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
220115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
221115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
222115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
223115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
224115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
225115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
226115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
227115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
228115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
229115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
230115cd2caSopenharmony_ci    DeleteRawContact();
231115cd2caSopenharmony_ci}
232115cd2caSopenharmony_ci
233115cd2caSopenharmony_ci/*
234115cd2caSopenharmony_ci * @tc.number  merge_Update_test_300
235115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. One of them has a mobile phone number.
236115cd2caSopenharmony_ci *              Check whether the database can be merged
237115cd2caSopenharmony_ci * @tc.desc    A: xiaomingmingming 123456, B: xiaomingmingming
238115cd2caSopenharmony_ci * @tc.level   Level1
239115cd2caSopenharmony_ci * @tc.size    MediumTest
240115cd2caSopenharmony_ci * @tc.type    Function
241115cd2caSopenharmony_ci */
242115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_300, testing::ext::TestSize.Level1)
243115cd2caSopenharmony_ci{
244115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_300 Add is starting! ---");
245115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaomingmm");
246115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaomingmm", "");
247115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
248115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_300 :  = %{public}ld", dataIdOne);
249115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaomingmm");
250115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaomingmm", "");
251115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_300 :  = %{public}ld", dataIdTwo);
252115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
253115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
254115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
255115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
256115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
257115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
258115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
259115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
260115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
261115cd2caSopenharmony_ci    value.Clear();
262115cd2caSopenharmony_ci    std::vector<std::string> ids;
263115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
264115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
265115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
266115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
267115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
268115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
269115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
270115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
271115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
272115cd2caSopenharmony_ci    DeleteRawContact();
273115cd2caSopenharmony_ci}
274115cd2caSopenharmony_ci
275115cd2caSopenharmony_ci/*
276115cd2caSopenharmony_ci * @tc.number  merge_Update_test_400
277115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. The mobile phone numbers of contacts a and B are the same.
278115cd2caSopenharmony_ci *              Check whether the database can be merged
279115cd2caSopenharmony_ci * @tc.desc    A: xiaohong、123456, B: xiaohong、123456
280115cd2caSopenharmony_ci * @tc.level   Level1
281115cd2caSopenharmony_ci * @tc.size    MediumTest
282115cd2caSopenharmony_ci * @tc.type    Function
283115cd2caSopenharmony_ci */
284115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_400, testing::ext::TestSize.Level1)
285115cd2caSopenharmony_ci{
286115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_400 Add is starting! ---");
287115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaohong");
288115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaohong", "");
289115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
290115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_400 :  = %{public}ld", dataIdOne);
291115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaohong");
292115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaohong", "");
293115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
294115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_400 :  = %{public}ld", dataIdTwo);
295115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
296115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
297115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
298115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
299115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
300115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
301115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
302115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
303115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
304115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
305115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
306115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
307115cd2caSopenharmony_ci    DeleteRawContact();
308115cd2caSopenharmony_ci}
309115cd2caSopenharmony_ci
310115cd2caSopenharmony_ci/*
311115cd2caSopenharmony_ci * @tc.number  merge_Update_test_500
312115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. The mobile phone numbers of contacts a and B are different.
313115cd2caSopenharmony_ci *              Check whether the database can be merged
314115cd2caSopenharmony_ci * @tc.desc    A: xiaozhang、123456, B: xiaozhang、1234567
315115cd2caSopenharmony_ci * @tc.level   Level1
316115cd2caSopenharmony_ci * @tc.size    MediumTest
317115cd2caSopenharmony_ci * @tc.type    Function
318115cd2caSopenharmony_ci */
319115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_500, testing::ext::TestSize.Level1)
320115cd2caSopenharmony_ci{
321115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_500 Add is starting! ---");
322115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaozhang");
323115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaozhang", "");
324115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
325115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_500 :  = %{public}ld", dataIdOne);
326115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaozhang");
327115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaozhang", "");
328115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "1234567", "");
329115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_500 :  = %{public}ld", dataIdTwo);
330115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
331115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
332115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
333115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
334115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
335115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
336115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
337115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
338115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
339115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
340115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
341115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
342115cd2caSopenharmony_ci
343115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
344115cd2caSopenharmony_ci    value.Clear();
345115cd2caSopenharmony_ci    std::vector<std::string> ids;
346115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
347115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
348115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
349115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
350115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
351115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
352115cd2caSopenharmony_ci    DeleteRawContact();
353115cd2caSopenharmony_ci}
354115cd2caSopenharmony_ci
355115cd2caSopenharmony_ci/*
356115cd2caSopenharmony_ci * @tc.number  merge_Update_test_600
357115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Contact a has two mobile phone numbers
358115cd2caSopenharmony_ci *              and contact B has no mobile phone number. Check whether the database can be merged
359115cd2caSopenharmony_ci * @tc.desc    A: xiaozhou 123456/1234567, B: xiaozhou
360115cd2caSopenharmony_ci * @tc.level   Level1
361115cd2caSopenharmony_ci * @tc.size    MediumTest
362115cd2caSopenharmony_ci * @tc.type    Function
363115cd2caSopenharmony_ci */
364115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_600, testing::ext::TestSize.Level1)
365115cd2caSopenharmony_ci{
366115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_600 Add is starting! ---");
367115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaozhou");
368115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaozhou", "");
369115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
370115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_600 dataIdOne_1  = %{public}ld", dataIdOne);
371115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
372115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_600 dataIdOne_2  = %{public}ld", dataIdOne);
373115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaozhou");
374115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaozhou", "");
375115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_600 :  = %{public}ld", dataIdTwo);
376115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
377115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
378115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
379115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
380115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
381115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
382115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
383115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
384115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
385115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
386115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
387115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
388115cd2caSopenharmony_ci
389115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
390115cd2caSopenharmony_ci    value.Clear();
391115cd2caSopenharmony_ci    std::vector<std::string> ids;
392115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
393115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
394115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
395115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
396115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
397115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
398115cd2caSopenharmony_ci    DeleteRawContact();
399115cd2caSopenharmony_ci}
400115cd2caSopenharmony_ci
401115cd2caSopenharmony_ci/*
402115cd2caSopenharmony_ci * @tc.number  merge_Update_test_700
403115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Both contacts a and B have the same mobile phone numbers.
404115cd2caSopenharmony_ci *              Check whether the database can be merged
405115cd2caSopenharmony_ci * @tc.desc    A: xiaobai、123456/1234567, B: xiaobai、123456/1234567
406115cd2caSopenharmony_ci * @tc.level   Level1
407115cd2caSopenharmony_ci * @tc.size    MediumTest
408115cd2caSopenharmony_ci * @tc.type    Function
409115cd2caSopenharmony_ci */
410115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_700, testing::ext::TestSize.Level1)
411115cd2caSopenharmony_ci{
412115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_700 Add is starting! ---");
413115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaobai");
414115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaobai", "");
415115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
416115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_700 dataIdOne_1  = %{public}ld", dataIdOne);
417115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
418115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_700 dataIdOne_2  = %{public}ld", dataIdOne);
419115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaobai");
420115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaobai", "");
421115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
422115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_700 dataIdTwo_1  = %{public}ld", dataIdTwo);
423115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "1234567", "");
424115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_700 dataIdTwo_2  = %{public}ld", dataIdTwo);
425115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
426115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
427115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
428115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
429115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
430115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
431115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
432115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
433115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
434115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
435115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
436115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
437115cd2caSopenharmony_ci    DeleteRawContact();
438115cd2caSopenharmony_ci}
439115cd2caSopenharmony_ci
440115cd2caSopenharmony_ci/*
441115cd2caSopenharmony_ci * @tc.number  merge_Update_test_800
442115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Each contact a and B has two mobile phone numbers, one of which
443115cd2caSopenharmony_ci * is the same. Check whether the database can be merged
444115cd2caSopenharmony_ci * @tc.desc    A: xiaomi、123456/1234567, B: xiaomi、123456/12345678
445115cd2caSopenharmony_ci * @tc.level   Level1
446115cd2caSopenharmony_ci * @tc.size    MediumTest
447115cd2caSopenharmony_ci * @tc.type    Function
448115cd2caSopenharmony_ci */
449115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_800, testing::ext::TestSize.Level1)
450115cd2caSopenharmony_ci{
451115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_800 Add is starting! ---");
452115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaomi");
453115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaomi", "");
454115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
455115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_800 dataIdOne_1  = %{public}ld", dataIdOne);
456115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
457115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_800 dataIdOne_2  = %{public}ld", dataIdOne);
458115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaomi");
459115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaomi", "");
460115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
461115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_800 dataIdTwo_1  = %{public}ld", dataIdTwo);
462115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "12345678", "");
463115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_800 dataIdTwo_2  = %{public}ld", dataIdTwo);
464115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
465115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
466115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
467115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
468115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
469115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
470115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
471115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
472115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
473115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
474115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
475115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
476115cd2caSopenharmony_ci
477115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
478115cd2caSopenharmony_ci    value.Clear();
479115cd2caSopenharmony_ci    std::vector<std::string> ids;
480115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
481115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
482115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
483115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
484115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
485115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
486115cd2caSopenharmony_ci    DeleteRawContact();
487115cd2caSopenharmony_ci}
488115cd2caSopenharmony_ci
489115cd2caSopenharmony_ci/*
490115cd2caSopenharmony_ci * @tc.number  merge_Update_test_900
491115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Contact a has two mobile phone numbers, and contact B has one
492115cd2caSopenharmony_ci * mobile phone number and is the same as one of the mobile phone numbers of A. check whether the database can be merged
493115cd2caSopenharmony_ci * @tc.desc    A: daniu、123456/1234567, B: daniu、123456
494115cd2caSopenharmony_ci * @tc.level   Level1
495115cd2caSopenharmony_ci * @tc.size    MediumTest
496115cd2caSopenharmony_ci * @tc.type    Function
497115cd2caSopenharmony_ci */
498115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_900, testing::ext::TestSize.Level1)
499115cd2caSopenharmony_ci{
500115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_900 Add is starting! ---");
501115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("daniu");
502115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "daniu", "");
503115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
504115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_900 dataIdOne_1  = %{public}ld", dataIdOne);
505115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
506115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_900 dataIdOne_2  = %{public}ld", dataIdOne);
507115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("daniu");
508115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "daniu", "");
509115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
510115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_900 dataIdTwo  = %{public}ld", dataIdTwo);
511115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
512115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
513115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
514115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
515115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
516115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
517115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
518115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
519115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
520115cd2caSopenharmony_ci    value.Clear();
521115cd2caSopenharmony_ci    std::vector<std::string> ids;
522115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
523115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
524115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
525115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
526115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
527115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
528115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
529115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
530115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
531115cd2caSopenharmony_ci    DeleteRawContact();
532115cd2caSopenharmony_ci}
533115cd2caSopenharmony_ci
534115cd2caSopenharmony_ci/*
535115cd2caSopenharmony_ci * @tc.number  merge_Update_test_1000
536115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Contact a has two mobile phone numbers
537115cd2caSopenharmony_ci *              and contact B has one mobile phone number. Check whether the database can be merged
538115cd2caSopenharmony_ci * @tc.desc    A: mazi、123456/1234567, B: mazi、123456789
539115cd2caSopenharmony_ci * @tc.level   Level1
540115cd2caSopenharmony_ci * @tc.size    MediumTest
541115cd2caSopenharmony_ci * @tc.type    Function
542115cd2caSopenharmony_ci */
543115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_1000, testing::ext::TestSize.Level1)
544115cd2caSopenharmony_ci{
545115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_1000 Add is starting! ---");
546115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("mazi");
547115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "mazi", "");
548115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
549115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1000 dataIdOne_1  = %{public}ld", dataIdOne);
550115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
551115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1000 dataIdOne_2  = %{public}ld", dataIdOne);
552115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("mazi");
553115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "mazi", "");
554115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456789", "");
555115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1000 dataIdTwo  = %{public}ld", dataIdTwo);
556115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
557115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
558115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
559115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
560115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
561115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
562115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
563115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
564115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
565115cd2caSopenharmony_ci    value.Clear();
566115cd2caSopenharmony_ci    std::vector<std::string> ids;
567115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
568115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
569115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
570115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
571115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
572115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
573115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
574115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
575115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
576115cd2caSopenharmony_ci    DeleteRawContact();
577115cd2caSopenharmony_ci}
578115cd2caSopenharmony_ci
579115cd2caSopenharmony_ci/*
580115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_1100
581115cd2caSopenharmony_ci * @tc.name    After consolidation, it is transferred to - 1 for splitting
582115cd2caSopenharmony_ci * @tc.desc    Exception use case: Merge and pass -1 to split
583115cd2caSopenharmony_ci * @tc.level   Level1
584115cd2caSopenharmony_ci * @tc.size    MediumTest
585115cd2caSopenharmony_ci * @tc.type    Function
586115cd2caSopenharmony_ci */
587115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_1100, testing::ext::TestSize.Level1)
588115cd2caSopenharmony_ci{
589115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_1100 Add is starting! ---");
590115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaocai");
591115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaocai", "");
592115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1100 :  = %{public}ld", dataIdOne);
593115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaocai");
594115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaocai", "");
595115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1100 :  = %{public}ld", dataIdTwo);
596115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
597115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
598115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
599115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
600115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueOne;
601115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
602115cd2caSopenharmony_ci    contactsDataAbility.Update(uriAutoMerge, predicates, valueOne);
603115cd2caSopenharmony_ci    OHOS::Uri uriSplitContact(ContactsUri::SPLIT_CONTACT);
604115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueTwo;
605115cd2caSopenharmony_ci    std::vector<std::string> ids;
606115cd2caSopenharmony_ci    ids.push_back("-1");
607115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
608115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriSplitContact, predicates, valueTwo);
609115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
610115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
611115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
612115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
613115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
614115cd2caSopenharmony_ci    DeleteRawContact();
615115cd2caSopenharmony_ci}
616115cd2caSopenharmony_ci
617115cd2caSopenharmony_ci/*
618115cd2caSopenharmony_ci * @tc.number  merge_Update_test_1200
619115cd2caSopenharmony_ci * @tc.name    Insert multiple automatically merged contacts to check whether the database can be merged
620115cd2caSopenharmony_ci * @tc.desc    A: xiaoliu、123456, B: xiaoliu、123456, C:xiaoliu、123456
621115cd2caSopenharmony_ci * @tc.level   Level1
622115cd2caSopenharmony_ci * @tc.size    MediumTest
623115cd2caSopenharmony_ci * @tc.type    Function
624115cd2caSopenharmony_ci */
625115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_1200, testing::ext::TestSize.Level1)
626115cd2caSopenharmony_ci{
627115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaoliu");
628115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
629115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "name", "xiaoliu", "");
630115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1200 :  = %{public}ld", dataIdOne);
631115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaoliu");
632115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
633115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaoliu", "");
634115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1200 :  = %{public}ld", dataIdTwo);
635115cd2caSopenharmony_ci    int64_t rawThree = RawContactInsert("xiaoliu");
636115cd2caSopenharmony_ci    int64_t dataIdThree = ContactDataInsert(rawThree, "phone", "123456", "");
637115cd2caSopenharmony_ci    dataIdThree = ContactDataInsert(rawThree, "name", "xiaoliu", "");
638115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1200 :  = %{public}ld", dataIdThree);
639115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
640115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
641115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
642115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
643115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
644115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
645115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
646115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
647115cd2caSopenharmony_ci    std::vector<std::string> ids;
648115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
649115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
650115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawThree));
651115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
652115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
653115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
654115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
655115cd2caSopenharmony_ci    HILOG_INFO("ret : %{public}d ", ret);
656115cd2caSopenharmony_ci    DeleteRawContact();
657115cd2caSopenharmony_ci}
658115cd2caSopenharmony_ci
659115cd2caSopenharmony_ci/*
660115cd2caSopenharmony_ci * @tc.number  merge_Update_test_1300
661115cd2caSopenharmony_ci * @tc.name    Insert two automatically merged contacts, modify a's name,
662115cd2caSopenharmony_ci *              and then automatically merge to see whether the database can be merged
663115cd2caSopenharmony_ci * @tc.desc    A: xiaohua、123456, B: xiaohua、123456 --> A: xiaohua、123456, B: dayu、123456
664115cd2caSopenharmony_ci * @tc.level   Level1
665115cd2caSopenharmony_ci * @tc.size    MediumTest
666115cd2caSopenharmony_ci * @tc.type    Function
667115cd2caSopenharmony_ci */
668115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_1300, testing::ext::TestSize.Level1)
669115cd2caSopenharmony_ci{
670115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_1300 Add is starting! ---");
671115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaohua");
672115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaohua", "");
673115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
674115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1300 dataIdOne  = %{public}ld", dataIdOne);
675115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaohua");
676115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaohua", "");
677115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
678115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1300 dataIdTwo  = %{public}ld", dataIdTwo);
679115cd2caSopenharmony_ci
680115cd2caSopenharmony_ci    OHOS::Uri uriContactData(ContactsUri::CONTACT_DATA);
681115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket values;
682115cd2caSopenharmony_ci    values.Put("detail_info", "dayuy");
683115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
684115cd2caSopenharmony_ci    predicates.EqualTo("raw_contact_id", std::to_string(rawTwo));
685115cd2caSopenharmony_ci    predicates.And();
686115cd2caSopenharmony_ci    predicates.EqualTo("type_id", "6");
687115cd2caSopenharmony_ci    contactsDataAbility.Update(uriContactData, predicates, values);
688115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
689115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
690115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
691115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
692115cd2caSopenharmony_ci    values.Clear();
693115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates2;
694115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates2, values);
695115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
696115cd2caSopenharmony_ci    std::vector<std::string> ids;
697115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
698115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
699115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
700115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
701115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
702115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
703115cd2caSopenharmony_ci    DeleteRawContact();
704115cd2caSopenharmony_ci}
705115cd2caSopenharmony_ci
706115cd2caSopenharmony_ci/*
707115cd2caSopenharmony_ci * @tc.number  merge_Update_test_1400
708115cd2caSopenharmony_ci * @tc.name    Insert two automatically merged contacts, modify a's mobile phone number,
709115cd2caSopenharmony_ci *              and then manually merge contacts to see whether the database can be merged
710115cd2caSopenharmony_ci * @tc.desc    A: xiaobei、123456, B: xiaobei、123456 --> A: xiaobei、123456, B: xiaobei、1234567
711115cd2caSopenharmony_ci * @tc.level   Level1
712115cd2caSopenharmony_ci * @tc.size    MediumTest
713115cd2caSopenharmony_ci * @tc.type    Function
714115cd2caSopenharmony_ci */
715115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_1400, testing::ext::TestSize.Level1)
716115cd2caSopenharmony_ci{
717115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_1400 Add is starting! ---");
718115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaobei");
719115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaobei", "");
720115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "17612345689", "");
721115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1400 dataIdOne  = %{public}ld", dataIdOne);
722115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaobei");
723115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaobei", "");
724115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "17612345689", "");
725115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1400 dataIdTwo  = %{public}ld", dataIdTwo);
726115cd2caSopenharmony_ci
727115cd2caSopenharmony_ci    OHOS::Uri uriContactData(ContactsUri::CONTACT_DATA);
728115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket values;
729115cd2caSopenharmony_ci    values.Put("detail_info", "18355421566");
730115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
731115cd2caSopenharmony_ci    predicates.EqualTo("raw_contact_id", std::to_string(rawTwo));
732115cd2caSopenharmony_ci    predicates.And();
733115cd2caSopenharmony_ci    predicates.EqualTo("type_id", "5");
734115cd2caSopenharmony_ci    contactsDataAbility.Update(uriContactData, predicates, values);
735115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
736115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
737115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
738115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
739115cd2caSopenharmony_ci    values.Clear();
740115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates2;
741115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates2, values);
742115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
743115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
744115cd2caSopenharmony_ci    values.Clear();
745115cd2caSopenharmony_ci    std::vector<std::string> ids;
746115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
747115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
748115cd2caSopenharmony_ci    predicates2.In("raw_contact_id", ids);
749115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates2, values);
750115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
751115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
752115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
753115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
754115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
755115cd2caSopenharmony_ci    DeleteRawContact();
756115cd2caSopenharmony_ci}
757115cd2caSopenharmony_ci
758115cd2caSopenharmony_ci/*
759115cd2caSopenharmony_ci * @tc.number  merge_Update_test_1500
760115cd2caSopenharmony_ci * @tc.name    After consolidation, it is transferred to rowid1 for splitting
761115cd2caSopenharmony_ci * @tc.desc    After merging, pass rowId1 to split
762115cd2caSopenharmony_ci * @tc.level   Level1
763115cd2caSopenharmony_ci * @tc.size    MediumTest
764115cd2caSopenharmony_ci * @tc.type    Function
765115cd2caSopenharmony_ci */
766115cd2caSopenharmony_ci
767115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_1500, testing::ext::TestSize.Level1)
768115cd2caSopenharmony_ci{
769115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_1500 Add is starting! ---");
770115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaolil");
771115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaolil", "");
772115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1500 :  = %{public}ld", dataIdOne);
773115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaoli");
774115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaolil", "");
775115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_1500 :  = %{public}ld", dataIdTwo);
776115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
777115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
778115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
779115cd2caSopenharmony_ci    int ret;
780115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
781115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueOne;
782115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
783115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriAutoMerge, predicates, valueOne);
784115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
785115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
786115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
787115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
788115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
789115cd2caSopenharmony_ci
790115cd2caSopenharmony_ci    OHOS::Uri uriSplitContact(ContactsUri::SPLIT_CONTACT);
791115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueTwo;
792115cd2caSopenharmony_ci    std::vector<std::string> ids;
793115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
794115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
795115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriSplitContact, predicates, valueTwo);
796115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
797115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
798115cd2caSopenharmony_ci    DeleteRawContact();
799115cd2caSopenharmony_ci}
800115cd2caSopenharmony_ci
801115cd2caSopenharmony_ci/*
802115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Query_test_1600
803115cd2caSopenharmony_ci * @tc.name    Insert contacts with the same name and different mobile numbers.
804115cd2caSopenharmony_ci *              The URI address is wrong. Check whether the database can find the contacts that can be merged
805115cd2caSopenharmony_ci * @tc.desc    A: xiaoma 123456, B: xiaoma 1234567
806115cd2caSopenharmony_ci * @tc.level   Level1
807115cd2caSopenharmony_ci * @tc.size    MediumTest
808115cd2caSopenharmony_ci * @tc.type    Function
809115cd2caSopenharmony_ci */
810115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Query_test_1600, testing::ext::TestSize.Level1)
811115cd2caSopenharmony_ci{
812115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Query_test_1600 Add is starting! ---");
813115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaoma");
814115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
815115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaoma", "");
816115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
817115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Query_test_1600 dataIdOne  = %{public}ld", dataIdOne);
818115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaoma");
819115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
820115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaoma", "");
821115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawTwo, "phone", "1234567", "");
822115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Query_test_1600 dataIdTwo  = %{public}ld", dataIdTwo);
823115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
824115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
825115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
826115cd2caSopenharmony_ci    OHOS::Uri uriQueryMergeList(ContactsUri::MERGE_LIST_ERROR);
827115cd2caSopenharmony_ci    std::vector<std::string> columns;
828115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
829115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
830115cd2caSopenharmony_ci        contactsDataAbility.Query(uriQueryMergeList, predicates, columns);
831115cd2caSopenharmony_ci    EXPECT_EQ(resultSet, nullptr);
832115cd2caSopenharmony_ci    DeleteRawContact();
833115cd2caSopenharmony_ci}
834115cd2caSopenharmony_ci
835115cd2caSopenharmony_ci/*
836115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_1700
837115cd2caSopenharmony_ci * @tc.name    Parameter URI address error
838115cd2caSopenharmony_ci * @tc.desc    Passing an error auto_merge uri
839115cd2caSopenharmony_ci * @tc.level   Level1
840115cd2caSopenharmony_ci * @tc.size    MediumTest
841115cd2caSopenharmony_ci * @tc.type    Function
842115cd2caSopenharmony_ci */
843115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_1700, testing::ext::TestSize.Level1)
844115cd2caSopenharmony_ci{
845115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_1700 Add is starting! ---");
846115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaoqian");
847115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaoqian", "");
848115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
849115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaoqian");
850115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaoqian", "");
851115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
852115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1700 dataIdTwo  = %{public}ld", dataIdTwo);
853115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
854115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
855115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
856115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::MERGE_ERROR);
857115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
858115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
859115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
860115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
861115cd2caSopenharmony_ci    std::vector<std::string> ids;
862115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
863115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
864115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
865115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
866115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
867115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
868115cd2caSopenharmony_ci
869115cd2caSopenharmony_ci    HILOG_INFO("ret : %{public}d ", ret);
870115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
871115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawOne));
872115cd2caSopenharmony_ci    predicates.Or();
873115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawTwo));
874115cd2caSopenharmony_ci    contactsDataAbility.Delete(uriRawContact, predicates);
875115cd2caSopenharmony_ci    DeleteRawContact();
876115cd2caSopenharmony_ci}
877115cd2caSopenharmony_ci
878115cd2caSopenharmony_ci/*
879115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_1800
880115cd2caSopenharmony_ci * @tc.name    Insert two contacts with different names and merge them automatically to see if the database can be
881115cd2caSopenharmony_ci * merged
882115cd2caSopenharmony_ci * @tc.desc    A: xiaosun、123456, B: xiaomei、123456
883115cd2caSopenharmony_ci * @tc.level   Level1
884115cd2caSopenharmony_ci * @tc.size    MediumTest
885115cd2caSopenharmony_ci * @tc.type    Function
886115cd2caSopenharmony_ci */
887115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_1800, testing::ext::TestSize.Level1)
888115cd2caSopenharmony_ci{
889115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_1800 Add is starting! ---");
890115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaosun");
891115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaosun", "");
892115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
893115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1800 dataIdOne  = %{public}ld", dataIdOne);
894115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaomei");
895115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaomei", "");
896115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
897115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1800 dataIdTwo  = %{public}ld", dataIdTwo);
898115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
899115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
900115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
901115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
902115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
903115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
904115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
905115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
906115cd2caSopenharmony_ci    HILOG_INFO("ret : %{public}d ", ret);
907115cd2caSopenharmony_ci    std::vector<std::string> ids;
908115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
909115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
910115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
911115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
912115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
913115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
914115cd2caSopenharmony_ci    DeleteRawContact();
915115cd2caSopenharmony_ci}
916115cd2caSopenharmony_ci
917115cd2caSopenharmony_ci/*
918115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_1900
919115cd2caSopenharmony_ci * @tc.name    Insert two contacts with different names for automatic merging and manual merging
920115cd2caSopenharmony_ci * @tc.desc    A: bob2300, B: lileibob2300 --> A: bob2300, B: lileibob2300
921115cd2caSopenharmony_ci * @tc.level   Level1
922115cd2caSopenharmony_ci * @tc.size    MediumTest
923115cd2caSopenharmony_ci * @tc.type    Function
924115cd2caSopenharmony_ci */
925115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_1900, testing::ext::TestSize.Level1)
926115cd2caSopenharmony_ci{
927115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_1900 Add is starting! ---");
928115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("bob2300");
929115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "bob2300", "");
930115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1900 dataIdOne  = %{public}ld", dataIdOne);
931115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("lileibob2300");
932115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "lileibob2300", "");
933115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_1900 dataIdTwo  = %{public}ld", dataIdTwo);
934115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
935115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
936115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
937115cd2caSopenharmony_ci
938115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket values;
939115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
940115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
941115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, values);
942115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
943115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
944115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
945115cd2caSopenharmony_ci    values.Clear();
946115cd2caSopenharmony_ci    std::vector<std::string> ids;
947115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
948115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
949115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
950115cd2caSopenharmony_ci    ret = contactsDataAbility.Update(uriManualMerge, predicates, values);
951115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
952115cd2caSopenharmony_ci    DeleteRawContact();
953115cd2caSopenharmony_ci}
954115cd2caSopenharmony_ci
955115cd2caSopenharmony_ci/*
956115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_2000
957115cd2caSopenharmony_ci * @tc.name    Pass in the wrong field name -- nameee, name
958115cd2caSopenharmony_ci * @tc.desc    A: xiaowang, B: xiaowang
959115cd2caSopenharmony_ci * @tc.level   Level1
960115cd2caSopenharmony_ci * @tc.size    MediumTest
961115cd2caSopenharmony_ci * @tc.type    Function
962115cd2caSopenharmony_ci */
963115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_2000, testing::ext::TestSize.Level1)
964115cd2caSopenharmony_ci{
965115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_2000 Add is starting! ---");
966115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaowang");
967115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
968115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "nameee", "xiaowang", "");
969115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_2000 dataIdOne  = %{public}ld", dataIdOne);
970115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaowang");
971115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
972115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaowang", "");
973115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_2000 dataIdTwo  = %{public}ld", dataIdTwo);
974115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
975115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
976115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
977115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
978115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
979115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
980115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriAutoMerge, predicates, value);
981115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
982115cd2caSopenharmony_ci    std::vector<std::string> ids;
983115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
984115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
985115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
986115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
987115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
988115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, false);
989115cd2caSopenharmony_ci
990115cd2caSopenharmony_ci    HILOG_INFO("ret : %{public}d ", ret);
991115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
992115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(dataIdOne));
993115cd2caSopenharmony_ci    predicates.Or();
994115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(dataIdTwo));
995115cd2caSopenharmony_ci    contactsDataAbility.Delete(uriRawContact, predicates);
996115cd2caSopenharmony_ci    DeleteRawContact();
997115cd2caSopenharmony_ci}
998115cd2caSopenharmony_ci
999115cd2caSopenharmony_ci/*
1000115cd2caSopenharmony_ci * @tc.number  abnormal_merge_Update_test_2100
1001115cd2caSopenharmony_ci * @tc.name    After consolidation, it is transferred to 0 for splitting
1002115cd2caSopenharmony_ci * @tc.desc    Exception use case: Merge and pass 0 to split
1003115cd2caSopenharmony_ci * @tc.level   Level1
1004115cd2caSopenharmony_ci * @tc.size    MediumTest
1005115cd2caSopenharmony_ci * @tc.type    Function
1006115cd2caSopenharmony_ci */
1007115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, abnormal_merge_Update_test_2100, testing::ext::TestSize.Level1)
1008115cd2caSopenharmony_ci{
1009115cd2caSopenharmony_ci    HILOG_INFO("--- abnormal_merge_Update_test_2100 Add is starting! ---");
1010115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaocheng");
1011115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaocheng", "");
1012115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_2100 :  = %{public}ld", dataIdOne);
1013115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaocheng");
1014115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaocheng", "");
1015115cd2caSopenharmony_ci    HILOG_INFO("abnormal_merge_Update_test_2100 :  = %{public}ld", dataIdTwo);
1016115cd2caSopenharmony_ci    std::chrono::milliseconds dura(Time::SLEEP_TIME_MERGE);
1017115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1018115cd2caSopenharmony_ci    OHOS::Uri uriAutoMerge(ContactsUri::AUTO_MERGE);
1019115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueOne;
1020115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1021115cd2caSopenharmony_ci    contactsDataAbility.Update(uriAutoMerge, predicates, valueOne);
1022115cd2caSopenharmony_ci    OHOS::Uri uriSplitContact(ContactsUri::SPLIT_CONTACT);
1023115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket valueTwo;
1024115cd2caSopenharmony_ci    std::vector<std::string> ids;
1025115cd2caSopenharmony_ci    ids.push_back("0");
1026115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
1027115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriSplitContact, predicates, valueTwo);
1028115cd2caSopenharmony_ci    EXPECT_EQ(ret, -1);
1029115cd2caSopenharmony_ci
1030115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
1031115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
1032115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
1033115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
1034115cd2caSopenharmony_ci    DeleteRawContact();
1035115cd2caSopenharmony_ci}
1036115cd2caSopenharmony_ci
1037115cd2caSopenharmony_ci/*
1038115cd2caSopenharmony_ci * @tc.number  merge_Update_test_2200
1039115cd2caSopenharmony_ci * @tc.name    Insert multiple manually merged contacts to check whether the database can be merged
1040115cd2caSopenharmony_ci * @tc.desc    A: xiaocai、1234567, B: xiaocai、123456, C:xiaocai、12345678
1041115cd2caSopenharmony_ci * @tc.level   Level1
1042115cd2caSopenharmony_ci * @tc.size    MediumTest
1043115cd2caSopenharmony_ci * @tc.type    Function
1044115cd2caSopenharmony_ci */
1045115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_2200, testing::ext::TestSize.Level1)
1046115cd2caSopenharmony_ci{
1047115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaocai");
1048115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaocai", "");
1049115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234567", "");
1050115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_2200 :  = %{public}ld", dataIdOne);
1051115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaocai");
1052115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
1053115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaocai", "");
1054115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_2200 :  = %{public}ld", dataIdTwo);
1055115cd2caSopenharmony_ci    int64_t rawThree = RawContactInsert("xiaocai");
1056115cd2caSopenharmony_ci    int64_t dataIdThree = ContactDataInsert(rawThree, "phone", "12345678", "");
1057115cd2caSopenharmony_ci    dataIdThree = ContactDataInsert(rawThree, "name", "xiaocai", "");
1058115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_2200 :  = %{public}ld", dataIdThree);
1059115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1060115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1061115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1062115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
1063115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
1064115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1065115cd2caSopenharmony_ci    std::vector<std::string> ids;
1066115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
1067115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
1068115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawThree));
1069115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
1070115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
1071115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
1072115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
1073115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
1074115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
1075115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
1076115cd2caSopenharmony_ci    HILOG_INFO("ret : %{public}d ", ret);
1077115cd2caSopenharmony_ci    DeleteRawContact();
1078115cd2caSopenharmony_ci}
1079115cd2caSopenharmony_ci
1080115cd2caSopenharmony_ci/*
1081115cd2caSopenharmony_ci * @tc.number  merge_Query_test_2300
1082115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name to check whether the database
1083115cd2caSopenharmony_ci *             can find the contacts that can be merged
1084115cd2caSopenharmony_ci * @tc.desc    A: xsiaowuwwwww  B: xsiaowuwwwww
1085115cd2caSopenharmony_ci * @tc.level   Level1
1086115cd2caSopenharmony_ci * @tc.size    MediumTest
1087115cd2caSopenharmony_ci * @tc.type    Function
1088115cd2caSopenharmony_ci */
1089115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Query_test_2300, testing::ext::TestSize.Level1)
1090115cd2caSopenharmony_ci{
1091115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Query_test_2300 query is starting! ---");
1092115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xsiaowuwwwww");
1093115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
1094115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xsiaowuwwwww", "");
1095115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2300 dataIdOne  = %{public}ld", dataIdOne);
1096115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xsiaowuwwwww");
1097115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
1098115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xsiaowuwwwww", "");
1099115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2300 dataIdTwo  = %{public}ld", dataIdTwo);
1100115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1101115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1102115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1103115cd2caSopenharmony_ci    std::vector<std::string> columns;
1104115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1105115cd2caSopenharmony_ci    predicates.BeginWrap();
1106115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawOne));
1107115cd2caSopenharmony_ci    predicates.Or();
1108115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawTwo));
1109115cd2caSopenharmony_ci    predicates.EndWrap();
1110115cd2caSopenharmony_ci    predicates.And();
1111115cd2caSopenharmony_ci    predicates.EqualTo("merge_mode", "2");
1112115cd2caSopenharmony_ci    predicates.And();
1113115cd2caSopenharmony_ci    predicates.EqualTo("is_deleted", "0");
1114115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
1115115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
1116115cd2caSopenharmony_ci        contactsDataAbility.Query(uriRawContact, predicates, columns);
1117115cd2caSopenharmony_ci    int rowCount = 0;
1118115cd2caSopenharmony_ci    resultSet->GetRowCount(rowCount);
1119115cd2caSopenharmony_ci    EXPECT_EQ(2, rowCount);
1120115cd2caSopenharmony_ci    std::vector<int> rawVector = GetMergeRawContactId(resultSet);
1121115cd2caSopenharmony_ci    EXPECT_EQ(rawOne, rawVector[0]);
1122115cd2caSopenharmony_ci    EXPECT_EQ(rawTwo, rawVector[1]);
1123115cd2caSopenharmony_ci    DeleteRawContact();
1124115cd2caSopenharmony_ci}
1125115cd2caSopenharmony_ci
1126115cd2caSopenharmony_ci/*
1127115cd2caSopenharmony_ci * @tc.number  merge_Query_test_2400
1128115cd2caSopenharmony_ci * @tc.name    Insert two contacts with different names to check whether the database
1129115cd2caSopenharmony_ci *             can find the contacts that can be merged
1130115cd2caSopenharmony_ci * @tc.desc    A: jackxsiaowuwwwww, B: xsiaowuwwwww
1131115cd2caSopenharmony_ci * @tc.level   Level1
1132115cd2caSopenharmony_ci * @tc.size    MediumTest
1133115cd2caSopenharmony_ci * @tc.type    Function
1134115cd2caSopenharmony_ci */
1135115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Query_test_2400, testing::ext::TestSize.Level1)
1136115cd2caSopenharmony_ci{
1137115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Query_test_2400 query is starting! ---");
1138115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("jackxsiaowuwwwww");
1139115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
1140115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "jackxsiaowuwwwww", "");
1141115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2400 dataIdOne  = %{public}ld", dataIdOne);
1142115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xsiaowuwwwww");
1143115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
1144115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xsiaowuwwwww", "");
1145115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2400 dataIdTwo  = %{public}ld", dataIdTwo);
1146115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1147115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1148115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1149115cd2caSopenharmony_ci    OHOS::Uri uriQueryMergeList(ContactsUri::MERGE_LIST);
1150115cd2caSopenharmony_ci    std::vector<std::string> columns;
1151115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1152115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
1153115cd2caSopenharmony_ci        contactsDataAbility.Query(uriQueryMergeList, predicates, columns);
1154115cd2caSopenharmony_ci    int rowCount = 0;
1155115cd2caSopenharmony_ci    resultSet->GetRowCount(rowCount);
1156115cd2caSopenharmony_ci    EXPECT_EQ(0, rowCount);
1157115cd2caSopenharmony_ci    DeleteRawContact();
1158115cd2caSopenharmony_ci}
1159115cd2caSopenharmony_ci
1160115cd2caSopenharmony_ci/*
1161115cd2caSopenharmony_ci * @tc.number  merge_Query_test_2500
1162115cd2caSopenharmony_ci * @tc.name    Insert contacts with the same name and phone number, and check whether the database
1163115cd2caSopenharmony_ci *              can find contacts that can be merged
1164115cd2caSopenharmony_ci * @tc.desc    A: xiaowuwwl 123456, B: xiaowuwwl 123456
1165115cd2caSopenharmony_ci * @tc.level   Level1
1166115cd2caSopenharmony_ci * @tc.size    MediumTest
1167115cd2caSopenharmony_ci * @tc.type    Function
1168115cd2caSopenharmony_ci */
1169115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Query_test_2500, testing::ext::TestSize.Level1)
1170115cd2caSopenharmony_ci{
1171115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Query_test_2500 query is starting! ---");
1172115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("xiaowuwwl");
1173115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
1174115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "xiaowuwwl", "");
1175115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456", "");
1176115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2500 dataIdOne  = %{public}ld", dataIdOne);
1177115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("xiaowuww");
1178115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
1179115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "xiaowuwwl", "");
1180115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "123456", "");
1181115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2500 dataIdTwo  = %{public}ld", dataIdTwo);
1182115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1183115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1184115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1185115cd2caSopenharmony_ci    std::vector<std::string> columns;
1186115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1187115cd2caSopenharmony_ci    predicates.BeginWrap();
1188115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawOne));
1189115cd2caSopenharmony_ci    predicates.Or();
1190115cd2caSopenharmony_ci    predicates.EqualTo("id", std::to_string(rawTwo));
1191115cd2caSopenharmony_ci    predicates.EndWrap();
1192115cd2caSopenharmony_ci    predicates.And();
1193115cd2caSopenharmony_ci    predicates.EqualTo("merge_mode", "2");
1194115cd2caSopenharmony_ci    predicates.And();
1195115cd2caSopenharmony_ci    predicates.EqualTo("is_deleted", "0");
1196115cd2caSopenharmony_ci    OHOS::Uri uriRawContact(ContactsUri::RAW_CONTACT);
1197115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
1198115cd2caSopenharmony_ci        contactsDataAbility.Query(uriRawContact, predicates, columns);
1199115cd2caSopenharmony_ci    int rowCount = 0;
1200115cd2caSopenharmony_ci    resultSet->GetRowCount(rowCount);
1201115cd2caSopenharmony_ci    EXPECT_EQ(2, rowCount);
1202115cd2caSopenharmony_ci    std::vector<int> rawVector = GetMergeRawContactId(resultSet);
1203115cd2caSopenharmony_ci    EXPECT_EQ(rawOne, rawVector[0]);
1204115cd2caSopenharmony_ci    EXPECT_EQ(rawTwo, rawVector[1]);
1205115cd2caSopenharmony_ci    DeleteRawContact();
1206115cd2caSopenharmony_ci}
1207115cd2caSopenharmony_ci
1208115cd2caSopenharmony_ci/*
1209115cd2caSopenharmony_ci * @tc.number  merge_Query_test_2600
1210115cd2caSopenharmony_ci * @tc.name    Insert contacts with different names and phone numbers, and check whether the
1211115cd2caSopenharmony_ci *             database can find the contacts that can be merged
1212115cd2caSopenharmony_ci * @tc.desc    A: cxiaowuwwl 123456565454, B: nxiaowuwwl 1234564488
1213115cd2caSopenharmony_ci * @tc.level   Level1
1214115cd2caSopenharmony_ci * @tc.size    MediumTest
1215115cd2caSopenharmony_ci * @tc.type    Function
1216115cd2caSopenharmony_ci */
1217115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Query_test_2600, testing::ext::TestSize.Level1)
1218115cd2caSopenharmony_ci{
1219115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Query_test_2600 query is starting! ---");
1220115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("cxiaowuwwl");
1221115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
1222115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "cxiaowuwwl", "");
1223115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456565454", "");
1224115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2600 dataIdOne  = %{public}ld", dataIdOne);
1225115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("nxiaowuww");
1226115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
1227115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "nxiaowuwwl", "");
1228115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "1234564488", "");
1229115cd2caSopenharmony_ci    HILOG_INFO("merge_Query_test_2600 dataIdTwo  = %{public}ld", dataIdTwo);
1230115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1231115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1232115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1233115cd2caSopenharmony_ci    OHOS::Uri uriQueryMergeList(ContactsUri::MERGE_LIST);
1234115cd2caSopenharmony_ci    std::vector<std::string> columns;
1235115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1236115cd2caSopenharmony_ci    std::shared_ptr<OHOS::DataShare::DataShareResultSet> resultSet =
1237115cd2caSopenharmony_ci        contactsDataAbility.Query(uriQueryMergeList, predicates, columns);
1238115cd2caSopenharmony_ci    int rowCount = 0;
1239115cd2caSopenharmony_ci    resultSet->GetRowCount(rowCount);
1240115cd2caSopenharmony_ci    EXPECT_EQ(0, rowCount);
1241115cd2caSopenharmony_ci    DeleteRawContact();
1242115cd2caSopenharmony_ci}
1243115cd2caSopenharmony_ci
1244115cd2caSopenharmony_ci/*
1245115cd2caSopenharmony_ci * @tc.number  merge_Update_test_2700
1246115cd2caSopenharmony_ci * @tc.name    Insert two contacts with the same name. Contacts A and B have two different mobile
1247115cd2caSopenharmony_ci *             phone numbers, and check whether the database can be merged
1248115cd2caSopenharmony_ci * @tc.desc    A: jack12345 123456565454 1234565654546 , B: jack12345 1234564488 12345644888
1249115cd2caSopenharmony_ci * @tc.level   Level1
1250115cd2caSopenharmony_ci * @tc.size    MediumTest
1251115cd2caSopenharmony_ci * @tc.type    Function
1252115cd2caSopenharmony_ci */
1253115cd2caSopenharmony_ciHWTEST_F(MergeContactTest, merge_Update_test_2700, testing::ext::TestSize.Level1)
1254115cd2caSopenharmony_ci{
1255115cd2caSopenharmony_ci    HILOG_INFO("--- merge_Update_test_2700 query is starting! ---");
1256115cd2caSopenharmony_ci    int64_t rawOne = RawContactInsert("jack12345");
1257115cd2caSopenharmony_ci    EXPECT_GT(rawOne, 0);
1258115cd2caSopenharmony_ci    int64_t dataIdOne = ContactDataInsert(rawOne, "name", "jack12345", "");
1259115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "123456565454", "");
1260115cd2caSopenharmony_ci    dataIdOne = ContactDataInsert(rawOne, "phone", "1234565654546", "");
1261115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_2700 dataIdOne  = %{public}ld", dataIdOne);
1262115cd2caSopenharmony_ci    int64_t rawTwo = RawContactInsert("jack12345");
1263115cd2caSopenharmony_ci    EXPECT_GT(rawTwo, 0);
1264115cd2caSopenharmony_ci    int64_t dataIdTwo = ContactDataInsert(rawTwo, "name", "jack12345", "");
1265115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "1234564488", "");
1266115cd2caSopenharmony_ci    dataIdTwo = ContactDataInsert(rawTwo, "phone", "12345644888", "");
1267115cd2caSopenharmony_ci    HILOG_INFO("merge_Update_test_2700 dataIdTwo  = %{public}ld", dataIdTwo);
1268115cd2caSopenharmony_ci    int time = Time::SLEEP_TIME_MERGE;
1269115cd2caSopenharmony_ci    std::chrono::milliseconds dura(time);
1270115cd2caSopenharmony_ci    std::this_thread::sleep_for(dura);
1271115cd2caSopenharmony_ci    OHOS::Uri uriManualMerge(ContactsUri::MANUAL_MERGE);
1272115cd2caSopenharmony_ci    OHOS::DataShare::DataShareValuesBucket value;
1273115cd2caSopenharmony_ci    OHOS::DataShare::DataSharePredicates predicates;
1274115cd2caSopenharmony_ci    std::vector<std::string> ids;
1275115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawOne));
1276115cd2caSopenharmony_ci    ids.push_back(std::to_string(rawTwo));
1277115cd2caSopenharmony_ci    predicates.In("raw_contact_id", ids);
1278115cd2caSopenharmony_ci    int ret = contactsDataAbility.Update(uriManualMerge, predicates, value);
1279115cd2caSopenharmony_ci    EXPECT_EQ(ret, 0);
1280115cd2caSopenharmony_ci    std::vector<int64_t> resultIdVector;
1281115cd2caSopenharmony_ci    resultIdVector.push_back(rawOne);
1282115cd2caSopenharmony_ci    resultIdVector.push_back(rawTwo);
1283115cd2caSopenharmony_ci    CheckMergeResultId(resultIdVector, true);
1284115cd2caSopenharmony_ci    DeleteRawContact();
1285115cd2caSopenharmony_ci}
1286115cd2caSopenharmony_ci} // namespace Test
1287115cd2caSopenharmony_ci} // namespace Contacts