• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <singleton.h>
18 #include <cassert>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <string>
23 
24 #include "remote_file_share.h"
25 
26 namespace {
27     using namespace std;
28     using namespace OHOS::AppFileService::ModuleRemoteFileShare;
29 
30     const int E_INVALID_ARGUMENT = 22;
31     const int E_OK = 0;
32 
33     class RemoteFileShareTest : public testing::Test {
34     public:
SetUpTestCase(void)35         static void SetUpTestCase(void) {};
TearDownTestCase()36         static void TearDownTestCase() {};
SetUp()37         void SetUp() {};
TearDown()38         void TearDown() {};
39     };
40 
41     /**
42      * @tc.name: remote_file_share_test_0000
43      * @tc.desc: Test function of RemoteFileShare() interface for SUCCESS.
44      * @tc.size: MEDIUM
45      * @tc.type: FUNC
46      * @tc.level Level 1
47      * @tc.require: SR000H63TL
48      */
49     HWTEST_F(RemoteFileShareTest, Remote_file_share_RemoteFileShare_0000, testing::ext::TestSize.Level1)
50     {
51         GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_RemoteFileShare_0000";
52         RemoteFileShare* test = new RemoteFileShare;
53         ASSERT_TRUE(test != nullptr) << "RemoteFileShare Construct Failed!";
54         delete test;
55         GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_RemoteFileShare_0000";
56     }
57 
58     /**
59      * @tc.name: remote_file_share_test_0001
60      * @tc.desc: Test function of CreateSharePath() interface for SUCCESS.
61      * @tc.size: MEDIUM
62      * @tc.type: FUNC
63      * @tc.level Level 1
64      * @tc.require: SR000H63TL
65      */
66     HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0001, testing::ext::TestSize.Level1)
67     {
68         GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0001";
69         const int fd = -1;
70         const int userId = 100;
71         const string deviceId = "0";
72         string sharePath = "";
73         int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId);
74         EXPECT_EQ(ret, E_INVALID_ARGUMENT);
75         GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0001";
76     }
77 
78     /**
79      * @tc.name: remote_file_share_test_0002
80      * @tc.desc: Test function of CreateSharePath() interface for SUCCESS.
81      * @tc.size: MEDIUM
82      * @tc.type: FUNC
83      * @tc.level Level 1
84      * @tc.require: SR000H63TL
85      */
86     HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0002, testing::ext::TestSize.Level1)
87     {
88         GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0002";
89         const int fd = 10;
90         const int userId = 90;
91         const string deviceId = "0";
92         string sharePath = "";
93         int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId);
94         EXPECT_EQ(ret, E_INVALID_ARGUMENT);
95         GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0002";
96     }
97 
98     /**
99      * @tc.name: remote_file_share_test_0003
100      * @tc.desc: Test function of CreateSharePath() interface for SUCCESS.
101      * @tc.size: MEDIUM
102      * @tc.type: FUNC
103      * @tc.level Level 1
104      * @tc.require: SR000H63TL
105      */
106     HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0003, testing::ext::TestSize.Level1)
107     {
108         GTEST_LOG_(INFO) << "RemoteFileShareTest-begin  Remote_file_share_CreateSharePath_0003";
109         const int fd = 10;
110         const int userId = 100;
111         const string deviceId = "00";
112         string sharePath = "";
113         int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId);
114         EXPECT_EQ(ret, E_INVALID_ARGUMENT);
115         GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0003";
116     }
117 
118     /**
119      * @tc.name: remote_file_share_test_0004
120      * @tc.desc: Test function of CreateSharePath() interface for SUCCESS.
121      * @tc.size: MEDIUM
122      * @tc.type: FUNC
123      * @tc.level Level 1
124      * @tc.require: SR000H63TL
125      */
126     HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0004, testing::ext::TestSize.Level1)
127     {
128         GTEST_LOG_(INFO) << "RemoteFileShareTest-begin  Remote_file_share_CreateSharePath_0004";
129         const string fileStr = "/data/test/remote_file_share_test.txt";
130         int fd = open(fileStr.c_str(), O_RDWR);
131         ASSERT_TRUE(fd != -1) << "RemoteFileShareTest Create File Failed!";
132         const int userId = 100;
133         const string deviceId = "0";
134         string sharePath = "";
135         int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId);
136         close(fd);
137         EXPECT_EQ(ret, E_OK);
138         GTEST_LOG_(INFO) << "RemoteFileShareTest Create Share Path " << sharePath;
139         GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0004";
140     }
141 }
142