• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <unistd.h>
18 #include "datashare_valuebucket_convert.h"
19 
20 namespace OHOS {
21 namespace DataShare {
22 using namespace testing::ext;
23 class ValueProxyTest : public testing::Test {
24 };
25 
26 /**
27 * @tc.name: VBucketsDataShare2Normal
28 * @tc.desc: Test conversion from DataShareValuesBucket vector to normal VBuckets
29 * @tc.type: FUNC
30 * @tc.require: NA
31 * @tc.precon: NA
32 * @tc.step:
33 * 1. Create two DataShareValuesBucket objects and add key-value pairs
34 * 2. Put the buckets into a vector
35 * 3. Convert the vector using ValueProxy::Convert()
36 * 4. Verify the converted VBuckets size is 2
37 * @tc.expect: The converted VBuckets has size 2, matching original vector size
38 */
39 HWTEST_F(ValueProxyTest, VBucketsDataShare2Normal, TestSize.Level0)
40 {
41     using DataShareBucket = OHOS::DataShare::DataShareValuesBucket;
42     DataShareBucket valuesBucket1;
43     DataShareBucket valuesBucket2;
44     valuesBucket1.Put("phoneNumber", 20.07);
45     valuesBucket1.Put("name", "dataShareTest003");
46     valuesBucket2.Put("age", 1001);
47     std::vector<DataShareBucket> VBuckets = {valuesBucket1, valuesBucket2};
48     DataShareObserver::ChangeInfo::VBuckets extends;
49     extends = ValueProxy::Convert(std::move(VBuckets));
50     ASSERT_EQ(extends.size(), 2);
51 }
52 
53 /**
54 * @tc.name: VBucketsNormal2DataShare
55 * @tc.desc: Test conversion from normal VBuckets to DataShareValuesBucket vector
56 * @tc.type: FUNC
57 * @tc.require: NA
58 * @tc.precon: NA
59 * @tc.step:
60 * 1. Create a VBuckets object with two entries containing key-value pairs
61 * 2. Convert the VBuckets using ValueProxy::Convert()
62 * 3. Verify the converted DataShareValuesBucket vector size is 2
63 * @tc.expect: The converted vector has size 2, matching original VBuckets size
64 */
65 HWTEST_F(ValueProxyTest, VBucketsNormal2DataShare, TestSize.Level0)
66 {
67     using DataShareBucket = OHOS::DataShare::DataShareValuesBucket;
68     std::vector<DataShareBucket> VBuckets;
69     DataShareObserver::ChangeInfo::VBuckets extends = {
70         {{"phoneNumber", 20.07}, {"name", "dataShareTest003"}},
71         {{"age", 1001}}
72     };
73     VBuckets = ValueProxy::Convert(std::move(extends));
74     ASSERT_EQ(VBuckets.size(), 2);
75 }
76 } // namespace DataShare
77 }