• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "mock.h"
17 
18 #include <filesystem>
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace TextEngine {
MockIFStream(const std::string & filename,std::ios_base::openmode mode)23 MockIFStream::MockIFStream(const std::string &filename, std::ios_base::openmode mode)
24     : std::ifstream(filename, mode) {}
25 
StdFilesystemIsOpen() const26 bool MockIFStream::StdFilesystemIsOpen() const
27 {
28     return std::ifstream::is_open();
29 }
30 
StdFilesystemSeekg(pos_type pos)31 std::istream &MockIFStream::StdFilesystemSeekg(pos_type pos)
32 {
33     return std::ifstream::seekg(pos);
34 }
35 
StdFilesystemSeekg(off_type off,std::ios_base::seekdir dir)36 std::istream &MockIFStream::StdFilesystemSeekg(off_type off, std::ios_base::seekdir dir)
37 {
38     return std::ifstream::seekg(off, dir);
39 }
40 
StdFilesystemTellg()41 std::ifstream::pos_type MockIFStream::StdFilesystemTellg()
42 {
43     return std::ifstream::tellg();
44 }
45 
StdFilesystemRead(char_type * s,std::streamsize count)46 std::istream &MockIFStream::StdFilesystemRead(char_type *s, std::streamsize count)
47 {
48     return std::ifstream::read(s, count);
49 }
50 
StdFilestystemClose()51 void MockIFStream::StdFilestystemClose()
52 {
53     std::ifstream::close();
54 }
55 
StdFilesystemExists(const std::string & p,std::error_code & ec)56 bool StdFilesystemExists(const std::string &p, std::error_code &ec)
57 {
58     return std::filesystem::exists(p, ec);
59 }
60 
61 } // namespace TextEngine
62 } // namespace Rosen
63 } // namespace OHOS
64