• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 "intrinsics.h"
17 #include <gtest/gtest.h>
18 #include "ets_coroutine.h"
19 #include "types/ets_string.h"
20 #include "types/ets_array.h"
21 #include "libpandabase/utils/utf.h"
22 
23 // NOLINTBEGIN(readability-magic-numbers)
24 // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic)
25 
26 namespace ark::ets::test {
27 class EtsStringBuilderTest : public testing::Test {
28 public:
EtsStringBuilderTest()29     EtsStringBuilderTest()
30     {
31         options_.SetShouldLoadBootPandaFiles(true);
32         options_.SetShouldInitializeIntrinsics(false);
33         options_.SetCompilerEnableJit(false);
34         options_.SetGcType("epsilon");
35         options_.SetLoadRuntimes({"ets"});
36 
37         auto stdlib = std::getenv("PANDA_STD_LIB");
38         if (stdlib == nullptr) {
39             std::cerr << "PANDA_STD_LIB env variable should be set and point to mock_stdlib.abc" << std::endl;
40             std::abort();
41         }
42         options_.SetBootPandaFiles({stdlib});
43 
44         Runtime::Create(options_);
45     }
46 
~EtsStringBuilderTest()47     ~EtsStringBuilderTest() override
48     {
49         Runtime::Destroy();
50     }
51 
52     NO_COPY_SEMANTIC(EtsStringBuilderTest);
53     NO_MOVE_SEMANTIC(EtsStringBuilderTest);
54 
SetUp()55     void SetUp() override
56     {
57         coroutine_ = EtsCoroutine::GetCurrent();
58         coroutine_->ManagedCodeBegin();
59     }
60 
TearDown()61     void TearDown() override
62     {
63         coroutine_->ManagedCodeEnd();
64     }
65 
66 private:
67     RuntimeOptions options_;
68     EtsCoroutine *coroutine_ = nullptr;
69 };
70 
TEST_F(EtsStringBuilderTest,CharToString)71 TEST_F(EtsStringBuilderTest, CharToString)
72 {
73     EtsChar etsCh = L'٩';
74     EtsString *charToString = intrinsics::StdCoreToStringChar(etsCh);
75 
76     ASSERT_TRUE(charToString->GetLength() == 1);
77     ASSERT_TRUE(charToString->GetDataUtf16()[0] == etsCh);
78 }
79 
80 }  // namespace ark::ets::test
81 
82 // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic)
83 // NOLINTEND(readability-magic-numbers)
84