• 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 "fs_reader_iterator.h"
17 
18 #include <filesystem>
19 #include <fstream>
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 FsReaderIteratorTest : public testing::Test {
28 public:
29     static std::filesystem::path tempFilePath;
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
36 filesystem::path FsReaderIteratorTest::tempFilePath;
37 
SetUpTestCase(void)38 void FsReaderIteratorTest::SetUpTestCase(void)
39 {
40     GTEST_LOG_(INFO) << "SetUpTestCase";
41     tempFilePath = std::filesystem::temp_directory_path() / "fs_reader_iterator_test_file.txt";
42     ofstream tempfile(tempFilePath);
43     tempfile << "Test content\n123\n456";
44     tempfile.close();
45 }
46 
TearDownTestCase(void)47 void FsReaderIteratorTest::TearDownTestCase(void)
48 {
49     GTEST_LOG_(INFO) << "TearDownTestCase";
50     filesystem::remove(tempFilePath);
51 }
52 
SetUp(void)53 void FsReaderIteratorTest::SetUp(void)
54 {
55     GTEST_LOG_(INFO) << "SetUp";
56 }
57 
TearDown(void)58 void FsReaderIteratorTest::TearDown(void)
59 {
60     GTEST_LOG_(INFO) << "TearDown";
61 }
62 
63 /**
64  * @tc.name: FsReaderIteratorTest_Constructor_001
65  * @tc.desc: Test FsReaderIterator::Constructor for success case
66  * @tc.size: SMALL
67  * @tc.type: FUNC
68  * @tc.level Level 1
69  */
70 HWTEST_F(FsReaderIteratorTest, FsReaderIteratorTest_Constructor_001, testing::ext::TestSize.Level1)
71 {
72     GTEST_LOG_(INFO) << "FsReaderIteratorTest-begin FsReaderIteratorTest_Constructor_001";
73 
74     auto result = FsReaderIterator::Constructor();
75     EXPECT_EQ(result.IsSuccess(), true);
76 
77     GTEST_LOG_(INFO) << "FsReaderIteratorTest-end FsReaderIteratorTest_Constructor_001";
78 }
79 
80 }