• 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 "read_core.h"
17 
18 #include <cstdint>
19 #include <climits>
20 #include <gtest/gtest.h>
21 
22 
23 namespace OHOS::FileManagement::ModuleFileIO::Test {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 
28 class ReadCoreTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void ReadCoreTest::SetUpTestCase(void)
37 {
38     GTEST_LOG_(INFO) << "SetUpTestCase";
39 }
40 
TearDownTestCase(void)41 void ReadCoreTest::TearDownTestCase(void)
42 {
43     GTEST_LOG_(INFO) << "TearDownTestCase";
44 }
45 
SetUp(void)46 void ReadCoreTest::SetUp(void)
47 {
48     GTEST_LOG_(INFO) << "SetUp";
49 }
50 
TearDown(void)51 void ReadCoreTest::TearDown(void)
52 {
53     GTEST_LOG_(INFO) << "TearDown";
54 }
55 
56 /**
57  * @tc.name: ReadCoreTest_DoRead_001
58  * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS.
59  * @tc.size: MEDIUM
60  * @tc.type: FUNC
61  * @tc.level Level 1
62  */
63 HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1)
64 {
65     GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_001";
66 
67     int32_t fd = -1;
68     void *buf = nullptr;
69     ArrayBuffer arrayBuffer(buf, 0);
70 
71     auto res = ReadCore::DoRead(fd, arrayBuffer);
72     EXPECT_EQ(res.IsSuccess(), false);
73 
74     GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_001";
75 }
76 
77 /**
78  * @tc.name: ReadCoreTest_DoRead_002
79  * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS.
80  * @tc.size: MEDIUM
81  * @tc.type: FUNC
82  * @tc.level Level 1
83  */
84 HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1)
85 {
86     GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_002";
87 
88     int32_t fd = 1;
89     void *buf = nullptr;
90     ArrayBuffer arrayBuffer(buf, 0xffffffff + 1);
91 
92     auto res = ReadCore::DoRead(fd, arrayBuffer);
93     EXPECT_EQ(res.IsSuccess(), false);
94 
95     GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_002";
96 }
97 
98 /**
99  * @tc.name: ReadCoreTest_DoRead_003
100  * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS.
101  * @tc.size: MEDIUM
102  * @tc.type: FUNC
103  * @tc.level Level 1
104  */
105 HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_003, testing::ext::TestSize.Level1)
106 {
107     GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_003";
108 
109     int32_t fd = 1;
110     void *buf = nullptr;
111     ArrayBuffer arrayBuffer(buf, 0);
112     optional<ReadOptions> options = std::make_optional<ReadOptions>();
113     options->offset = std::make_optional<int64_t>(-1);
114 
115     auto res = ReadCore::DoRead(fd, arrayBuffer, options);
116     EXPECT_EQ(res.IsSuccess(), false);
117 
118     GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_003";
119 }
120 
121 } // namespace OHOS::FileManagement::ModuleFileIO::Test