• 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 "dup_core.h"
17 
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <gtest/gtest.h>
21 
22 namespace OHOS::FileManagement::ModuleFileIO::Test {
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace std;
26 
27 class DupCoreTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void DupCoreTest::SetUpTestCase(void)
36 {
37     GTEST_LOG_(INFO) << "SetUpTestCase";
38 }
39 
TearDownTestCase(void)40 void DupCoreTest::TearDownTestCase(void)
41 {
42     GTEST_LOG_(INFO) << "TearDownTestCase";
43 }
44 
SetUp(void)45 void DupCoreTest::SetUp(void)
46 {
47     GTEST_LOG_(INFO) << "SetUp";
48 }
49 
TearDown(void)50 void DupCoreTest::TearDown(void)
51 {
52     GTEST_LOG_(INFO) << "TearDown";
53 }
54 
55 /**
56  * @tc.name: DupCoreTest_DoDup_001
57  * @tc.desc: Test function of DupCore::DoDup interface for FALSE.
58  * @tc.size: MEDIUM
59  * @tc.type: FUNC
60  * @tc.level Level 1
61  */
62 HWTEST_F(DupCoreTest, DupCoreTest_DoDup_001, testing::ext::TestSize.Level1)
63 {
64     GTEST_LOG_(INFO) << "NClassTest-begin DupCoreTest_DoDup_001";
65     int32_t fd = -1;
66     auto res = DupCore::DoDup(fd);
67 
68     EXPECT_EQ(res.IsSuccess(), false);
69 
70     GTEST_LOG_(INFO) << "NClassTest-end DupCoreTest_DoDup_001";
71 }
72 
73 /**
74  * @tc.name: DupCoreTest_DoDup_002
75  * @tc.desc: Test function of DupCore::DoDup interface for FALSE.
76  * @tc.size: MEDIUM
77  * @tc.type: FUNC
78  * @tc.level Level 1
79  */
80 HWTEST_F(DupCoreTest, DupCoreTest_DoDup_002, testing::ext::TestSize.Level1)
81 {
82     GTEST_LOG_(INFO) << "NClassTest-begin DupCoreTest_DoDup_002";
83     int32_t fd = open("temp_file.txt", O_CREAT | O_RDWR, 0666);
84     ASSERT_NE(fd, -1);
85     close(fd);
86 
87     auto res = DupCore::DoDup(fd);
88 
89     EXPECT_EQ(res.IsSuccess(), false);
90 
91     GTEST_LOG_(INFO) << "NClassTest-end DupCoreTest_DoDup_002";
92 }
93 
94 } // namespace OHOS::FileManagement::ModuleFileIO::Test