1 /*
2 * Copyright (c) 2023 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 <string>
18
19 #include "data_share_profile_info.h"
20
21 using namespace testing::ext;
22 using namespace OHOS::RdbBMSAdapter;
23
24 class RdbBMSAdapterTest : public testing::Test {
25 public:
26 static void SetUpTestCase(void);
27
28 static void TearDownTestCase(void);
29
30 void SetUp();
31
32 void TearDown();
33 };
34
SetUpTestCase(void)35 void RdbBMSAdapterTest::SetUpTestCase(void)
36 {
37 }
38
TearDownTestCase(void)39 void RdbBMSAdapterTest::TearDownTestCase(void)
40 {
41 }
42
SetUp(void)43 void RdbBMSAdapterTest::SetUp(void)
44 {
45 }
46
TearDown(void)47 void RdbBMSAdapterTest::TearDown(void)
48 {
49 }
50
51 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_001, TestSize.Level1)
52 {
53 OHOS::AppExecFwk::ExtensionAbilityInfo extensionInfo;
54 std::vector<std::string> profileInfos;
55 auto ret = DataShareProfileInfo::GetResConfigFile(extensionInfo, profileInfos);
56 EXPECT_EQ(ret, false);
57 }
58
59 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_002, TestSize.Level1)
60 {
61 OHOS::AppExecFwk::ProxyData proxyData;
62 DataProperties properties;
63 auto ret = DataShareProfileInfo::GetDataPropertiesFromProxyDatas(proxyData, "", false, properties);
64 EXPECT_EQ(ret, false);
65 }
66
67 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_003, TestSize.Level1)
68 {
69 Config config;
70 config.uri = "uri";
71 config.crossUserMode = 1;
72 config.writePermission = "writePermission";
73 config.readPermission = "readPermission";
74
75 auto jstr = to_string(config.Marshall());
76 Config config1;
77 config1.Unmarshall(jstr);
78
79 EXPECT_EQ(config.uri, config1.uri);
80 EXPECT_EQ(config.crossUserMode, config1.crossUserMode);
81 EXPECT_EQ(config.writePermission, config1.writePermission);
82 EXPECT_EQ(config.readPermission, config1.readPermission);
83 }
84
85 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_004, TestSize.Level1)
86 {
87 ProfileInfo profileInfo;
88 Config config;
89 config.uri = "uri";
90 config.crossUserMode = 1;
91 config.writePermission = "writePermission";
92 config.readPermission = "readPermission";
93 profileInfo.tableConfig.emplace_back(config);
94
95 auto jstr = to_string(profileInfo.Marshall());
96 ProfileInfo profileInfo1;
97 profileInfo1.Unmarshall(jstr);
98 EXPECT_EQ(profileInfo.tableConfig.size(), profileInfo1.tableConfig.size());
99 }
100
101 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_005, TestSize.Level1)
102 {
103 DataProperties dataProperties;
104 dataProperties.storeName = "store1";
105 dataProperties.tableName = "table1";
106
107 auto jstr = to_string(dataProperties.Marshall());
108 DataProperties dataProperties1;
109 dataProperties1.Unmarshall(jstr);
110
111 EXPECT_EQ(dataProperties.storeName, dataProperties1.storeName);
112 EXPECT_EQ(dataProperties.tableName, dataProperties1.tableName);
113 EXPECT_EQ(dataProperties.scope, dataProperties1.scope);
114 EXPECT_EQ(dataProperties.type, dataProperties1.type);
115 }
116
117 HWTEST_F(RdbBMSAdapterTest, Rdb_BMS_Adapter_006, TestSize.Level1)
118 {
119 DataProperties dataProperties;
120 dataProperties.storeName = "store1";
121 dataProperties.tableName = "table1";
122
123 auto dataPropertiesStr = to_string(dataProperties.Marshall());
124 bool isJson = OHOS::Serializable::IsJson(dataPropertiesStr);
125 EXPECT_EQ(isJson, true);
126
127 auto jsonObject = OHOS::Serializable::ToJson(dataPropertiesStr);
128 auto jsonStr = to_string(jsonObject);
129 EXPECT_EQ(dataPropertiesStr, jsonStr);
130 }