• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "lstat_core.h"
19 
20 namespace OHOS::FileManagement::ModuleFileIO::Test {
21 using namespace testing;
22 using namespace testing::ext;
23 using namespace std;
24 
25 class LstatCoreTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase(void)33 void LstatCoreTest::SetUpTestCase(void)
34 {
35     GTEST_LOG_(INFO) << "SetUpTestCase";
36     int32_t fd = open("/data/test/lstat.txt", CREATE | O_RDWR, 0644);
37     if (fd <= 0) {
38         ASSERT_TRUE(false);
39     }
40     close(fd);
41 }
42 
TearDownTestCase(void)43 void LstatCoreTest::TearDownTestCase(void)
44 {
45     GTEST_LOG_(INFO) << "TearDownTestCase";
46     rmdir("/data/test/lstat.txt");
47 }
48 
SetUp(void)49 void LstatCoreTest::SetUp(void)
50 {
51     GTEST_LOG_(INFO) << "SetUp";
52 }
53 
TearDown(void)54 void LstatCoreTest::TearDown(void)
55 {
56     GTEST_LOG_(INFO) << "TearDown";
57 }
58 
59 /**
60  * @tc.name: LstatCoreTest_DoLstat_001
61  * @tc.desc: Test function of LstatCore::DoLstat interface for FALSE.
62  * @tc.size: MEDIUM
63  * @tc.type: FUNC
64  * @tc.level Level 1
65  */
66 HWTEST_F(LstatCoreTest, LstatCoreTest_DoLstat_001, testing::ext::TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "LstatCoreTest-begin LstatCoreTest_DoLstat_001";
69 
70     auto res = LstatCore::DoLstat("/invalid/test/lstat.txt");
71     EXPECT_EQ(res.IsSuccess(), false);
72     auto err = res.GetError();
73     EXPECT_EQ(err.GetErrNo(), 13900002);
74 
75     GTEST_LOG_(INFO) << "LstatCoreTest-end LstatCoreTest_DoLstat_001";
76 }
77 
78 /**
79  * @tc.name: LstatCoreTest_DoLstat_002
80  * @tc.desc: Test function of LstatCore::DoLstat interface for SUCCESS.
81  * @tc.size: MEDIUM
82  * @tc.type: FUNC
83  * @tc.level Level 1
84  */
85 HWTEST_F(LstatCoreTest, LstatCoreTest_DoLstat_002, testing::ext::TestSize.Level1)
86 {
87     GTEST_LOG_(INFO) << "LstatCoreTest-begin LstatCoreTest_DoLstat_002";
88 
89     auto res = LstatCore::DoLstat("/data/test/lstat.txt");
90     EXPECT_EQ(res.IsSuccess(), true);
91 
92     GTEST_LOG_(INFO) << "LstatCoreTest-end LstatCoreTest_DoLstat_002";
93 }
94 }