• 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 "ecmascript/platform/file.h"
17 #include "ecmascript/tests/test_helper.h"
18 
19 using namespace panda::ecmascript;
20 using namespace panda::ecmascript::base;
21 
22 namespace panda::test {
23 class FilePathHelperTest : public testing::Test {
24 public:
SetUpTestCase()25     static void SetUpTestCase()
26     {
27         GTEST_LOG_(INFO) << "SetUpTestCase";
28     }
29 
TearDownTestCase()30     static void TearDownTestCase()
31     {
32         GTEST_LOG_(INFO) << "TearDownCase";
33     }
34 
SetUp()35     void SetUp() override
36     {
37         TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
38     }
39 
TearDown()40     void TearDown() override
41     {
42         TestHelper::DestroyEcmaVMWithScope(instance, scope);
43     }
44 
45     EcmaVM *instance {nullptr};
46     EcmaHandleScope *scope {nullptr};
47     JSThread *thread {nullptr};
48 };
49 
HWTEST_F_L0(FilePathHelperTest,RealPath)50 HWTEST_F_L0(FilePathHelperTest, RealPath)
51 {
52     std::string filePath = "__FilePathHelperTest.test";
53     EXPECT_TRUE(std::fopen(filePath.c_str(), "r") == nullptr);
54 
55     std::string realPath;
56     bool result = RealPath(filePath, realPath, false);
57     EXPECT_EQ(result, true);
58 
59     std::fstream stream {};
60     stream.open(realPath, std::ios::out);
61     EXPECT_EQ(stream.good(), true);
62     EXPECT_TRUE(std::fopen(realPath.c_str(), "r") != nullptr);
63 
64     stream.close();
65     stream.clear();
66     std::remove(filePath.c_str());
67     std::remove(realPath.c_str());
68 }
69 }  // namespace panda::test
70