• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 
19 #include "datashare_errno.h"
20 #include "datashare_itypes_utils.h"
21 #include "datashare_log.h"
22 #include "datashare_abs_result_set.h"
23 #include "datashare_result_set.h"
24 #include "ikvstore_data_service.h"
25 #include "ipc_types.h"
26 #include "ishared_result_set_stub.h"
27 #include "itypes_util.h"
28 #include "message_parcel.h"
29 
30 namespace OHOS {
31 namespace DataShare {
32 using namespace testing::ext;
33 class DatashareResultSetTest : public testing::Test {
34 public:
SetUpTestCase(void)35     static void SetUpTestCase(void){};
TearDownTestCase(void)36     static void TearDownTestCase(void){};
SetUp()37     void SetUp(){};
TearDown()38     void TearDown(){};
39 };
40 
41 /**
42 * @tc.name: GetDataTypeTest001
43 * @tc.desc: test GetDataType function when sharedBlock_ is nullptr
44 * @tc.type: FUNC
45 * @tc.require: issueIC9GIH
46 * @tc.precon: None
47 * @tc.step:
48     1.Creat a DataShareResultSet object and sharedBlock_ is nullptr
49     2.call GetDataType function and check the result
50 * @tc.experct: GetDataType failed and return E_ERROR
51 */
52 HWTEST_F(DatashareResultSetTest, GetDataTypeTest001, TestSize.Level0)
53 {
54     LOG_INFO("DatashareResultSetTest GetDataTypeTest001::Start");
55     DataShareResultSet dataShareResultSet;
56     int columnIndex = 1;
57     DataShare::DataType dataType;
58     auto result = dataShareResultSet.GetDataType(columnIndex, dataType);
59     EXPECT_EQ(result, E_ERROR);
60     LOG_INFO("DatashareResultSetTest GetDataTypeTest001::End");
61 }
62 
63 /**
64 * @tc.name: CheckStateTest001
65 * @tc.desc: test CheckState function when columnIndex >= 0
66 * @tc.type: FUNC
67 * @tc.require: issueIC9GIH
68 * @tc.precon: None
69 * @tc.step:
70     1.Creat a DataShareResultSet object
71     2.call CheckState function when columnIndex >= 0 and check the result
72 * @tc.experct: CheckState failed and return E_INVALID_COLUMN_INDEX
73 */
74 HWTEST_F(DatashareResultSetTest, CheckStateTest001, TestSize.Level0)
75 {
76     LOG_INFO("DatashareResultSetTest CheckStateTest001::Start");
77     DataShareResultSet dataShareResultSet;
78     int columnIndex = 1;
79     auto result = dataShareResultSet.CheckState(columnIndex);
80     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
81     LOG_INFO("DatashareResultSetTest CheckStateTest001::End");
82 }
83 
84 /**
85 * @tc.name: CheckStateTest002
86 * @tc.desc: test CheckState function when columnIndex < 0
87 * @tc.type: FUNC
88 * @tc.require: issueIC9GIH
89 * @tc.precon: None
90 * @tc.step:
91     1.Creat a DataShareResultSet object
92     2.call CheckState function when columnIndex < 0 and check the result
93 * @tc.experct: CheckState failed and return E_INVALID_COLUMN_INDEX
94 */
95 HWTEST_F(DatashareResultSetTest, CheckStateTest002, TestSize.Level0)
96 {
97     LOG_INFO("DatashareResultSetTest CheckState002::Start");
98     DataShareResultSet dataShareResultSet;
99     int columnIndex = -1;
100     auto result = dataShareResultSet.CheckState(columnIndex);
101     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
102     LOG_INFO("DatashareResultSetTest CheckState002::End");
103 }
104 
105 /**
106 * @tc.name: MarshalTest001
107 * @tc.desc: test Marshal function when resultset = nullptr
108 * @tc.type: FUNC
109 * @tc.require: issueICCAXH
110 * @tc.precon: None
111 * @tc.step:
112     1.Creat a DataShareResultSet object when resultset = nullptr
113     2.call Marshal function and check the result
114 * @tc.experct: Marshal failed and return false
115 */
116 HWTEST_F(DatashareResultSetTest, MarshalTest001, TestSize.Level0)
117 {
118     LOG_INFO("DatashareResultSetTest MarshalTest001::Start");
119     DataShareResultSet dataShareResultSet;
120     std::shared_ptr<DataShareResultSet> resultset = nullptr;
121     MessageParcel parcel;
122     auto result = dataShareResultSet.Marshal(resultset, parcel);
123     EXPECT_FALSE(result);
124     LOG_INFO("DatashareResultSetTest MarshalTest001::End");
125 }
126 
127 /**
128 * @tc.name: UnmarshalTest001
129 * @tc.desc: test Unmarshal function
130 * @tc.type: FUNC
131 * @tc.require: issueICCAXH
132 * @tc.precon: None
133 * @tc.step:
134     1.Creat a DataShareResultSet object
135     2.call Unmarshal function and check the result
136 * @tc.experct: Unmarshal failed and return nullptr
137 */
138 HWTEST_F(DatashareResultSetTest, UnmarshalTest001, TestSize.Level0)
139 {
140     LOG_INFO("DatashareResultSetTest UnmarshalTest001::Start");
141     DataShareResultSet dataShareResultSet;
142     MessageParcel parcel;
143     auto result = dataShareResultSet.Unmarshal(parcel);
144     EXPECT_EQ(result, nullptr);
145     LOG_INFO("DatashareResultSetTest UnmarshalTest001::End");
146 }
147 
148 /**
149 * @tc.name: MarshallingTest001
150 * @tc.desc: test Marshalling function when sharedBlock_ is nullptr
151 * @tc.type: FUNC
152 * @tc.require: issueIC9GIH
153 * @tc.precon: None
154 * @tc.step:
155     1.Creat a DataShareResultSet object
156     2.call Marshalling function when sharedBlock_ is nullptr and check the result
157 * @tc.experct: Marshalling failed and return false
158 */
159 HWTEST_F(DatashareResultSetTest, MarshallingTest001, TestSize.Level0)
160 {
161     LOG_INFO("DatashareResultSetTest MarshallingTest001::Start");
162     DataShareResultSet dataShareResultSet;
163     MessageParcel parcel;
164     auto result = dataShareResultSet.Marshalling(parcel);
165     EXPECT_FALSE(result);
166     LOG_INFO("DatashareResultSetTest MarshallingTest001::End");
167 }
168 }
169 }