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 #include <gtest/gtest.h>
16 #include "idl_common.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20 using namespace OHOS::Idl::TestCommon;
21
22 namespace OHOS {
23 namespace Idl {
24 namespace UnitTest {
25 class RustCodeEmitterTest : public testing::Test, public IdlCommon {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase()33 void RustCodeEmitterTest::SetUpTestCase()
34 {}
35
TearDownTestCase()36 void RustCodeEmitterTest::TearDownTestCase()
37 {}
38
SetUp()39 void RustCodeEmitterTest::SetUp()
40 {}
41
TearDown()42 void RustCodeEmitterTest::TearDown()
43 {}
44
45 /*
46 * Feature: idl
47 * Function: RustCodeEmitter
48 * SubFunction: NA
49 * FunctionPoints: Check whether the emitter is existed.
50 * EnvConditions: NA
51 * CaseDescription: RustCodeEmitter is existed.
52 */
53 HWTEST_F(RustCodeEmitterTest, IDLRust_Generator_0100, TestSize.Level1)
54 {
55 EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE1_IDL_CONTENT.c_str()), ERR_OK);
56 int argc = 6;
57 const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-rust", "-d", "."};
58 ParameterArgv parameters(argvArray, argc);
59 EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
60 EXPECT_NE(rustCodeGen_, nullptr);
61 StringBuilder sb;
62 rustCodeGen_->EmitInterface(sb);
63 EXPECT_FALSE(sb.ToString().IsEmpty());
64 EXPECT_NE(sb.ToString().IndexOf("Copyright"), ERR_FAIL);
65 EXPECT_NE(sb.ToString().IndexOf("use ipc_rust::"), ERR_FAIL);
66 EXPECT_NE(sb.ToString().IndexOf("FIRST_CALL_TRANSACTION"), ERR_FAIL);
67 EXPECT_NE(sb.ToString().IndexOf("define_remote_object"), ERR_FAIL);
68 EXPECT_NE(sb.ToString().IndexOf("IRemoteBroker"), ERR_FAIL);
69 EXPECT_NE(sb.ToString().IndexOf("on_remote_request"), ERR_FAIL);
70 EXPECT_NE(sb.ToString().IndexOf("IdlTestStub"), ERR_FAIL);
71 EXPECT_NE(sb.ToString().IndexOf("IdlTestProxy"), ERR_FAIL);
72 }
73 } // namespace UnitTest
74 } // namespace Idl
75 } // namespace OHOS
76