1 /* 2 * Copyright (c) 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 <gtest/gtest.h> 17 #include <string> 18 #include "disassembler.h" 19 #include <iostream> 20 21 using namespace testing::ext; 22 23 namespace panda::disasm { 24 25 static const std::string CHECK_ECMASCRIPT = ".language ECMAScript\n.record default {"; 26 static const std::string CHECK_JAVASCRIPT = ".language JavaScript\n.record js {"; 27 static const std::string CHECK_ARKTSSCRIPT = ".language ArkTS\n.record ets {"; 28 static const std::string CHECK_TYPESCRIPT = ".language TypeScript\n.record ts {"; 29 30 static const std::string CHECK_ETS_STR_ANNO = ".language ArkTS\n.record ets.EtsStringAnno {"; 31 static const std::string CHECK_TS_ANNO = ".language TypeScript\n.record ts.TsAnno {"; 32 static const std::string CHECK_PANDA_STR = ".language ECMAScript\n.record panda.String <external>"; 33 34 class DisasmSourceLangTest : public testing::Test { 35 public: SetUpTestCase(void)36 static void SetUpTestCase(void) {}; TearDownTestCase(void)37 static void TearDownTestCase(void) {}; SetUp()38 void SetUp() {}; TearDown()39 void TearDown() {}; 40 Find(std::stringstream & ss,const std::string & dst)41 bool Find(std::stringstream &ss, const std::string &dst) 42 { 43 return ss.str().find(dst) != std::string::npos; 44 } 45 }; 46 47 /** 48 * @tc.name: disassembler_source_lang_test_001 49 * @tc.desc: Check source files types in abc. 50 * @tc.type: FUNC 51 * @tc.require: file path and name 52 */ 53 HWTEST_F(DisasmSourceLangTest, disassembler_source_lang_test_001, TestSize.Level1) 54 { 55 const std::string file_name = GRAPH_TEST_ABC_DIR "sourceLang.abc"; 56 panda::disasm::Disassembler disasm {}; 57 disasm.Disassemble(file_name, false, false); 58 std::stringstream ss {}; 59 disasm.Serialize(ss); 60 EXPECT_TRUE(Find(ss, CHECK_ECMASCRIPT)); 61 EXPECT_TRUE(Find(ss, CHECK_JAVASCRIPT)); 62 EXPECT_TRUE(Find(ss, CHECK_ARKTSSCRIPT)); 63 EXPECT_TRUE(Find(ss, CHECK_TYPESCRIPT)); 64 65 EXPECT_TRUE(Find(ss, CHECK_ETS_STR_ANNO)); 66 EXPECT_TRUE(Find(ss, CHECK_TS_ANNO)); 67 EXPECT_TRUE(Find(ss, CHECK_PANDA_STR)); 68 } 69 } 70