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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18
19 #include "lstat_core.h"
20 #include "uv_fs_mock.h"
21
22 namespace OHOS::FileManagement::ModuleFileIO::Test {
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace std;
26
27 class LstatCoreMockTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 static inline shared_ptr<UvfsMock> uvMock = nullptr;
34 };
35
SetUpTestCase(void)36 void LstatCoreMockTest::SetUpTestCase(void)
37 {
38 GTEST_LOG_(INFO) << "SetUpTestCase";
39 uvMock = make_shared<UvfsMock>();
40 Uvfs::ins = uvMock;
41 }
42
TearDownTestCase(void)43 void LstatCoreMockTest::TearDownTestCase(void)
44 {
45 GTEST_LOG_(INFO) << "TearDownTestCase";
46 Uvfs::ins = nullptr;
47 uvMock = nullptr;
48 }
49
SetUp(void)50 void LstatCoreMockTest::SetUp(void)
51 {
52 GTEST_LOG_(INFO) << "SetUp";
53 }
54
TearDown(void)55 void LstatCoreMockTest::TearDown(void)
56 {
57 GTEST_LOG_(INFO) << "TearDown";
58 }
59
60 /**
61 * @tc.name: LstatCoreMockTest_DoLstat_001
62 * @tc.desc: Test function of LstatCore::DoLstat interface for FALSE.
63 * @tc.size: MEDIUM
64 * @tc.type: FUNC
65 * @tc.level Level 1
66 */
67 HWTEST_F(LstatCoreMockTest, LstatCoreMockTest_DoLstat_001, testing::ext::TestSize.Level1)
68 {
69 GTEST_LOG_(INFO) << "LstatCoreMockTest-begin LstatCoreMockTest_DoLstat_001";
70
71 EXPECT_CALL(*uvMock, uv_fs_lstat(_, _, _, _)).WillOnce(Return(-1));
72
73 auto res = LstatCore::DoLstat("/data/test/LstatCoreMockTestLstat.txt");
74 EXPECT_EQ(res.IsSuccess(), false);
75
76 GTEST_LOG_(INFO) << "LstatCoreMockTest-end LstatCoreMockTest_DoLstat_001";
77 }
78
79 }