1 /*
2 * Copyright (c) 2021 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 <cstdio>
17
18 #include <gtest/gtest.h>
19
20 #include "ifms_client.h"
21 #include "file_manager_proxy.h"
22 #include "fms_manager_proxy_mock.h"
23
24 namespace {
25 using namespace std;
26 using namespace OHOS;
27 using namespace FileManagerService;
28 class FileManagerProxyTest : public testing::Test {
29 public:
SetUpTestCase(void)30 static void SetUpTestCase(void)
31 {
32 cout << "FileManagerProxyTest code test" << endl;
33 }
TearDownTestCase()34 static void TearDownTestCase() {};
35 void SetUp();
TearDown()36 void TearDown() {};
37 std::shared_ptr<FileManagerProxy> proxy_ = nullptr;
38 sptr<FmsManagerProxyMock> mock_ = nullptr;
39 };
40
SetUp()41 void FileManagerProxyTest::SetUp()
42 {
43 mock_ = new OHOS::FileManagerService::FmsManagerProxyMock();
44 proxy_ = std::make_shared<FileManagerProxy>(mock_);
45 }
46
47 /**
48 * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000
49 * @tc.name: File_Manager_Proxy_GetFmsInstance_0000
50 * @tc.desc: Test function of GetFmsInstance interface for SUCCESS.
51 * @tc.size: MEDIUM
52 * @tc.type: FUNC
53 * @tc.level Level 1
54 * @tc.require: AR000GJ9T3
55 */
56 HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1)
57 {
58 GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000";
59 try {
60 IFmsClient* result = IFmsClient::GetFmsInstance();
61 EXPECT_NE(result, nullptr);
62 } catch (...) {
63 GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred.";
64 }
65 GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000";
66 }
67
68 /**
69 * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000
70 * @tc.name: File_Manager_Proxy_Mkdir_0000
71 * @tc.desc: Test function of Mkdir interface for SUCCESS.
72 * @tc.size: MEDIUM
73 * @tc.type: FUNC
74 * @tc.level Level 1
75 * @tc.require: AR000GJ9T3
76 */
77 HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1)
78 {
79 GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000";
80 std::string name = "File_Manager_Proxy_Mkdir_0000";
81 std::string path = "dataability:///album";
82 EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
83 .Times(1)
84 .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest));
85 int ret = proxy_->Mkdir(name, path);
86 EXPECT_TRUE(ret == ERR_NONE);
87 GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000";
88 }
89 } // namespace