• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <fcntl.h>
17 #include <gtest/gtest.h>
18 #include <sys/stat.h>
19 #include <sys/types.h>
20 
21 #include "libpandabase/os/file.h"
22 
23 namespace panda::test {
24 
25 HWTEST(UnixFileTest, OpenAndGetFlagsTest, testing::ext::TestSize.Level0)
26 {
27     remove("./test_openfile.txt");
28     os::file::File file1 = os::file::Open("./test_openfile.txt", os::file::Mode::READONLY);
29     ASSERT_FALSE(file1.IsValid());
30     remove("./test_openfile.txt");
31     os::file::File file2 = os::file::Open("./test_openfile.txt", os::file::Mode::READWRITE);
32     ASSERT_FALSE(file2.IsValid());
33     remove("./test_openfile.txt");
34     os::file::File file3 = os::file::Open("./test_openfile.txt", os::file::Mode::WRITEONLY);
35     ASSERT_TRUE(file3.IsValid());
36     remove("./test_openfile.txt");
37     os::file::File file4 = os::file::Open("./test_openfile.txt", os::file::Mode::READWRITECREATE);
38     ASSERT_TRUE(file4.IsValid());
39 }
40 
41 }  // namespace panda::test