/** * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "file_items.h" #include "file_writer.h" #include #include #include #include namespace panda::panda_file::test { HWTEST(LineNumberProgramItem, EmitSpecialOpcode, testing::ext::TestSize.Level0) { LineNumberProgramItem item(nullptr); constexpr int32_t LINE_MAX_INC = LineNumberProgramItem::LINE_RANGE + LineNumberProgramItem::LINE_BASE - 1; constexpr int32_t LINE_MIN_INC = LineNumberProgramItem::LINE_BASE; EXPECT_FALSE(item.EmitSpecialOpcode(0, LINE_MAX_INC + 1)); EXPECT_FALSE(item.EmitSpecialOpcode(0, LINE_MIN_INC - 1)); EXPECT_FALSE(item.EmitSpecialOpcode(100, LINE_MAX_INC)); std::vector> incs = {{1, LINE_MIN_INC}, {2, LINE_MAX_INC}}; std::vector data; for (auto [pc_inc, line_inc] : incs) { ASSERT_TRUE(item.EmitSpecialOpcode(pc_inc, line_inc)); data.push_back((line_inc - LineNumberProgramItem::LINE_BASE) + (pc_inc * LineNumberProgramItem::LINE_RANGE) + LineNumberProgramItem::OPCODE_BASE); } MemoryWriter writer; ASSERT_TRUE(item.Write(&writer)); EXPECT_EQ(writer.GetData(), data); } HWTEST(LineNumberProgramItem, LanguageFromAndToString, testing::ext::TestSize.Level0) { ASSERT_EQ(LanguageFromString("not ECMAScript"), static_cast(1U)); ASSERT_STREQ(LanguageToString(SourceLang::ECMASCRIPT), "ECMAScript"); ASSERT_STREQ(LanguageToString(SourceLang::PANDA_ASSEMBLY), "PandaAssembly"); } HWTEST(LineNumberProgramItem, GetStringClassDescriptor, testing::ext::TestSize.Level0) { ASSERT_STREQ(GetStringClassDescriptor(SourceLang::ECMASCRIPT), "Lpanda/JSString;"); ASSERT_STREQ(GetStringClassDescriptor(SourceLang::PANDA_ASSEMBLY), "Lpanda/String;"); } } // namespace panda::panda_file::test