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 <filesystem> 17 18 #include "gtest/gtest.h" 19 #include "ts2abc.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 namespace fs = std::filesystem; 24 25 namespace ARK::Ts2Abc::Ts2Abc { 26 class FunctionTest : public testing::Test { 27 public: 28 static void SetUpTestCase(); 29 static void TearDownTestCase(); 30 void SetUp(); 31 void TearDown(); 32 }; 33 34 Json::Value function = {}; 35 SetUpTestCase()36 void FunctionTest::SetUpTestCase() {} TearDownTestCase()37 void FunctionTest::TearDownTestCase() {} SetUp()38 const void FunctionTest::SetUp() 39 { 40 std::string file = "../../ark/ts2abc/ts2panda/ts2abc/tests/sources/add.json"; 41 std::string data = ""; 42 int ret = HandleJsonFile(file, data); 43 EXPECT_EQ(ret, 1); 44 Json::Value rootValue; 45 ret = ParseJson(data, rootValue); 46 EXPECT_EQ(ret, panda::ts2abc::RETURN_SUCCESS); 47 function = rootValue["func_body"]; 48 } TearDown()49 const void FunctionTest::TearDown() {} 50 51 HWTEST_F(FunctionTest, FunctionTest_GetFunctionDefintion, TestSize.Level0) 52 { 53 auto pandaFunc = GetFunctionDefintion(function); 54 EXPECT_EQ(pandaFunc.name, function["name"].asString()); 55 EXPECT_EQ(pandaFunc.return_type.GetName(), "any"); 56 auto signature = function["signature"]; 57 EXPECT_EQ(pandaFunc.params.size(), signature["params"].asUInt()); 58 EXPECT_EQ(pandaFunc.regs_num, function["regs_num"].asUInt()); 59 } 60 } // namespace ARK::Ts2Abc::Ts2Abc