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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18
19 #include "dk_container.h"
20
21 namespace OHOS::FileManagement::CloudSync::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 using namespace DriveKit;
26
27 class DKContainerTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 };
SetUpTestCase(void)34 void DKContainerTest::SetUpTestCase(void)
35 {
36 GTEST_LOG_(INFO) << "SetUpTestCase";
37 }
38
TearDownTestCase(void)39 void DKContainerTest::TearDownTestCase(void)
40 {
41 GTEST_LOG_(INFO) << "TearDownTestCase";
42 }
43
SetUp(void)44 void DKContainerTest::SetUp(void)
45 {
46 GTEST_LOG_(INFO) << "SetUp";
47 }
48
TearDown(void)49 void DKContainerTest::TearDown(void)
50 {
51 GTEST_LOG_(INFO) << "TearDown";
52 }
53
54 /**
55 * @tc.name: GetPrivateDatabase
56 * @tc.desc: Verify the DKContainer::GetPrivateDatabase function
57 * @tc.type: FUNC
58 * @tc.require: SR000HRKKA
59 */
60 HWTEST_F(DKContainerTest, GetPrivateDatabase, TestSize.Level1)
61 {
62 DKAppBundleName bundleName = "DKContainerTest";
63 DKContainerName containerName = "GetPrivateDatabase";
64 shared_ptr<DriveKitNative> driveKit = nullptr;
65 DKContainer mDkContainer(bundleName, containerName, driveKit);
66 shared_ptr<DKDatabase> databasePtr = mDkContainer.GetPrivateDatabase();
67 EXPECT_EQ(databasePtr, nullptr);
68 }
69
70 /**
71 * @tc.name: GetDatabaseWithdatabaseScope001
72 * @tc.desc: Verify the DKContainer::GetDatabaseWithdatabaseScope function
73 * @tc.type: FUNC
74 * @tc.require: SR000HRKKA
75 */
76 HWTEST_F(DKContainerTest, GetDatabaseWithdatabaseScope001, TestSize.Level1)
77 {
78 DKAppBundleName bundleName = "DKContainerTest";
79 DKContainerName containerName = "GetDatabaseWithdatabaseScope001";
80 shared_ptr<DriveKitNative> driveKit = nullptr;
81 DKDatabaseScope databaseScope = DKDatabaseScope::DK_PUBLIC_DATABASE;
82 DKContainer mDkContainer(bundleName, containerName, driveKit);
83 shared_ptr<DKDatabase> databasePtr = mDkContainer.GetDatabaseWithdatabaseScope(databaseScope);
84 EXPECT_EQ(databasePtr, nullptr);
85 }
86
87 /**
88 * @tc.name: GetDatabaseWithdatabaseScope002
89 * @tc.desc: Verify the DKContainer::GetDatabaseWithdatabaseScope function
90 * @tc.type: FUNC
91 * @tc.require: SR000HRKKA
92 */
93 HWTEST_F(DKContainerTest, GetDatabaseWithdatabaseScope002, TestSize.Level1)
94 {
95 DKAppBundleName bundleName = "DKContainerTest";
96 DKContainerName containerName = "GetDatabaseWithdatabaseScope002";
97 shared_ptr<DriveKitNative> driveKit = nullptr;
98 DKDatabaseScope databaseScope = DKDatabaseScope::DK_PRIVATE_DATABASE;
99 DKContainer mDkContainer(bundleName, containerName, driveKit);
100 shared_ptr<DKDatabase> databasePtr = mDkContainer.GetDatabaseWithdatabaseScope(databaseScope);
101 EXPECT_EQ(databasePtr, nullptr);
102 }
103
104 /**
105 * @tc.name: GetDatabaseWithdatabaseScope003
106 * @tc.desc: Verify the DKContainer::GetDatabaseWithdatabaseScope function
107 * @tc.type: FUNC
108 * @tc.require: SR000HRKKA
109 */
110 HWTEST_F(DKContainerTest, GetDatabaseWithdatabaseScope003, TestSize.Level1)
111 {
112 DKAppBundleName bundleName = "DKContainerTest";
113 DKContainerName containerName = "GetDatabaseWithdatabaseScope003";
114 shared_ptr<DriveKitNative> driveKit = nullptr;
115 DKDatabaseScope databaseScope = DKDatabaseScope::DK_SHARED_DATABASE;
116 DKContainer mDkContainer(bundleName, containerName, driveKit);
117 shared_ptr<DKDatabase> databasePtr = mDkContainer.GetDatabaseWithdatabaseScope(databaseScope);
118 EXPECT_EQ(databasePtr, nullptr);
119 }
120
121 /**
122 * @tc.name: SaveSubscription
123 * @tc.desc: Verify the DKContainer::SaveSubscription function
124 * @tc.type: FUNC
125 * @tc.require: SR000HRKKA
126 */
127 HWTEST_F(DKContainerTest, SaveSubscription, TestSize.Level1)
128 {
129 DKAppBundleName bundleName = "DKContainerTest";
130 DKContainerName containerName = "SaveSubscription";
131 shared_ptr<DriveKitNative> driveKit = nullptr;
132 shared_ptr<DKContext> contex = nullptr;
133 DKSubscription subscription;
134 SaveSubscriptionCallback callback = nullptr;
135 DKContainer mDkContainer(bundleName, containerName, driveKit);
136 DKLocalErrorCode ret = mDkContainer.SaveSubscription(contex, subscription, callback);
137 EXPECT_EQ(ret, DKLocalErrorCode::NO_ERROR);
138 }
139
140 /**
141 * @tc.name: DeleteSubscription
142 * @tc.desc: Verify the DKContainer::DeleteSubscription function
143 * @tc.type: FUNC
144 * @tc.require: SR000HRKKA
145 */
146 HWTEST_F(DKContainerTest, DeleteSubscription, TestSize.Level1)
147 {
148 DKAppBundleName bundleName = "DKContainerTest";
149 DKContainerName containerName = "DeleteSubscription";
150 shared_ptr<DriveKitNative> driveKit = nullptr;
151 shared_ptr<DKContext> contex = nullptr;
152 DKSubscriptionId id = "";
153 DelSubscriptionCallback callback = nullptr;;
154 DKContainer mDkContainer(bundleName, containerName, driveKit);
155 DKLocalErrorCode ret = mDkContainer.DeleteSubscription(contex, id, callback);
156 EXPECT_EQ(ret, DKLocalErrorCode::NO_ERROR);
157 }
158 } // namespace OHOS::FileManagement::CloudSync::Test
159