• 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 "ecmascript/platform/filesystem.h"
17 #include "ecmascript/platform/os.h"
18 #include "ecmascript/tests/test_helper.h"
19 
20 using namespace panda::ecmascript;
21 
22 namespace panda::test {
23 class OSTest : 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         tempDir_ = filesystem::TempDirectoryPath() + "/os_test_temp";
38         filesystem::CreateDirectory(tempDir_);
39     }
40 
TearDown()41     void TearDown() override
42     {
43         filesystem::RemoveAll(tempDir_);
44     }
45 
46 protected:
47     std::string tempDir_;
48 };
49 
HWTEST_F_L0(OSTest,CheckDiskSpaceTest)50 HWTEST_F_L0(OSTest, CheckDiskSpaceTest)
51 {
52     ASSERT_TRUE(CheckDiskSpace(tempDir_, 1024));
53     std::string invalidPath = "/invalid/path/that/does/not/exist";
54     ASSERT_FALSE(CheckDiskSpace(invalidPath, 1024));
55     size_t largeSize = SIZE_MAX;
56     ASSERT_FALSE(CheckDiskSpace(tempDir_, largeSize));
57     ASSERT_TRUE(CheckDiskSpace(tempDir_, 0));
58 }
59 }