1/* 2 * Copyright (c) 2021-2022 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 <iostream> 17#include <string> 18 19#include <gtest/gtest.h> 20#include "disassembler.h" 21 22using namespace panda::disasm; 23 24#cmakedefine DISASM_BIN_DIR "@DISASM_BIN_DIR@/" 25 26TEST(literals_test, literals_test_names) 27{ 28 Disassembler d {}; 29 30 std::stringstream ss {}; 31 d.Disassemble(std::string(DISASM_BIN_DIR) + "literals_same.bc"); 32 d.Serialize(ss, false); 33 34 ASSERT_NE(ss.str().find(".language PandaAssembly"), std::string::npos); 35 36 ASSERT_NE(ss.str().find(".array array_0 i32 3 { 2 3 4 }"), std::string::npos); 37 ASSERT_NE(ss.str().find(".array array_1 i32 3 { 2 3 4 }"), std::string::npos); 38 ASSERT_NE(ss.str().find(".array array_2 i32 3 { 2 3 4 }"), std::string::npos); 39 ASSERT_NE(ss.str().find(".array array_3 i32 3 { 2 3 4 }"), std::string::npos); 40} 41 42TEST(literals_test, literals_test) 43{ 44 Disassembler d {}; 45 46 std::stringstream ss {}; 47 d.Disassemble(std::string(DISASM_BIN_DIR) + "literals.bc"); 48 d.Serialize(ss, false); 49 50 ASSERT_NE(ss.str().find(".language PandaAssembly"), std::string::npos); 51 52 ASSERT_NE(ss.str().find(".record panda.String <external>"), std::string::npos); 53 ASSERT_NE(ss.str().find("panda.String 3 { \"a\" \"ab\" \"abc\" }"), std::string::npos); 54 ASSERT_NE(ss.str().find("u1 3 { 0 1 0 }"), std::string::npos); 55 ASSERT_NE(ss.str().find("i32 3 { 2 3 4 }"), std::string::npos); 56 ASSERT_NE(ss.str().find("f32 3 { 5.1 6.2 7.3 }"), std::string::npos); 57} 58 59#undef DISASM_BIN_DIR 60