1 /*
2  * Copyright (c) 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 <gtest/gtest.h>
17 #include "ast/ast_parameter.h"
18 #include "ast/ast_void_type.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 using namespace OHOS::Idl;
23 
24 class AstParameterUnitTest : public testing::Test {
25 public:
AstParameterUnitTest()26     AstParameterUnitTest() {}
27 
~AstParameterUnitTest()28     virtual ~AstParameterUnitTest() {}
29 
30     static void SetUpTestCase();
31 
32     static void TearDownTestCase();
33 
34     void SetUp();
35 
36     void TearDown();
37 };
38 
SetUpTestCase()39 void AstParameterUnitTest::SetUpTestCase() {}
40 
TearDownTestCase()41 void AstParameterUnitTest::TearDownTestCase() {}
42 
SetUp()43 void AstParameterUnitTest::SetUp() {}
44 
TearDown()45 void AstParameterUnitTest::TearDown() {}
46 
47 /*
48  * @tc.name: DumpTest_0100
49  * @tc.desc: test if isInParameter in AstParameterUnitTest's Dump function is true.
50  * @tc.type: FUNC
51  * @tc.require:
52  */
53 HWTEST_F(AstParameterUnitTest, DumpTest_0100, Function | MediumTest | Level1)
54 {
55     GTEST_LOG_(INFO)
56         << "AstParameterUnitTest, DumpTest_0100, TestSize.Level1";
57     std::shared_ptr<ASTParameter> imageASTParameter = std::make_shared<ASTParameter>();
58     bool inParameter = true;
59     bool outParameter = true;
60     ASTType *imageASTType = new ASTVoidType();
61     String name = "test";
62     imageASTParameter->SetInParameter(inParameter);
63     imageASTParameter->SetOutParameter(outParameter);
64     imageASTParameter->SetType(imageASTType);
65     imageASTParameter->SetName(name);
66     String prefix = "abctest";
67     String result = imageASTParameter->Dump(prefix);
68     String typeString = imageASTParameter->GetType()->ToString();
69     String expectString = prefix + "[in, out] " + typeString + " " + name;
70 
71     ASSERT_STREQ(result, expectString);
72 }
73 
74 /*
75  * @tc.name: DumpTest_0200
76  * @tc.desc: test if isInParameter in AstParameterUnitTest's Dump function is false, isOutParameter is true.
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(AstParameterUnitTest, DumpTest_0200, Function | MediumTest | Level1)
81 {
82     GTEST_LOG_(INFO)
83         << "AstParameterUnitTest, DumpTest_0200, TestSize.Level1";
84     std::shared_ptr<ASTParameter> imageASTParameter = std::make_shared<ASTParameter>();
85     bool inParameter = false;
86     bool outParameter = true;
87     ASTType *imageASTType = new ASTVoidType();
88     String name = "test";
89     imageASTParameter->SetInParameter(inParameter);
90     imageASTParameter->SetOutParameter(outParameter);
91     imageASTParameter->SetType(imageASTType);
92     imageASTParameter->SetName(name);
93     String prefix = "abctest";
94     String result = imageASTParameter->Dump(prefix);
95     String typeString = imageASTParameter->GetType()->ToString();
96     String expectString = prefix + "[out] " + typeString + " " + name;
97     ASSERT_STREQ(result, expectString);
98 }
99