• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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/mem/assert_scope.h"
17 #include "ecmascript/tests/test_helper.h"
18 
19 using namespace panda::ecmascript;
20 
21 namespace panda::test {
22 class AssertScopeTest : public testing::Test {
23 public:
SetUpTestCase()24     static void SetUpTestCase()
25     {
26         GTEST_LOG_(INFO) << "SetUpTestCase";
27     }
28 
TearDownTestCase()29     static void TearDownTestCase()
30     {
31         GTEST_LOG_(INFO) << "TearDownCase";
32     }
33 
SetUp()34     void SetUp() override {}
35 
TearDown()36     void TearDown() override {}
37 };
38 
HWTEST_F_L0(AssertScopeTest,AssertScopeChecker)39 HWTEST_F_L0(AssertScopeTest, AssertScopeChecker)
40 {
41 #if !defined(NDEBUG)
42     {
43         EXPECT_TRUE(AllowHeapAlloc::IsAllowed());
44         EXPECT_TRUE(AllowGarbageCollection::IsAllowed());
45         [[maybe_unused]] DisallowGarbageCollection noGc;  // set dis-allow gc
46         {
47             [[maybe_unused]] AllowGarbageCollection allowGc;  // set allow gc
48             EXPECT_TRUE(AllowGarbageCollection::IsAllowed());
49 
50             [[maybe_unused]] DisAllowHeapAlloc noHeapAlloc;  // set dis-allow alloc
51             {
52                 [[maybe_unused]] AllowHeapAlloc heapAlloc;  // set allow alloc
53                 EXPECT_TRUE(AllowHeapAlloc::IsAllowed());
54             }
55             EXPECT_FALSE(AllowHeapAlloc::IsAllowed());
56         }
57         // allow alloc
58         EXPECT_TRUE(AllowHeapAlloc::IsAllowed());
59         // dis-allow gc
60         EXPECT_FALSE(AllowGarbageCollection::IsAllowed());
61     }
62     // allow gc
63     EXPECT_TRUE(AllowGarbageCollection::IsAllowed());
64 #endif
65     EXPECT_TRUE(AllowHeapAlloc::IsAllowed());
66     EXPECT_TRUE(AllowGarbageCollection::IsAllowed());
67 }
68 }  // namespace panda::test
69