1 /*
2  * Copyright (c) 2023 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 
18 #define protected public
19 #include "native_args_child_process.h"
20 #undef protected
21 #include "hilog_tag_wrapper.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 class NativeArgsChildProcessTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 };
35 
SetUpTestCase()36 void NativeArgsChildProcessTest::SetUpTestCase()
37 {}
38 
TearDownTestCase()39 void NativeArgsChildProcessTest::TearDownTestCase()
40 {}
41 
SetUp()42 void NativeArgsChildProcessTest::SetUp()
43 {}
44 
TearDown()45 void NativeArgsChildProcessTest::TearDown()
46 {}
47 
48 /**
49  * @tc.number: NativeArgsChildProcess_0100
50  * @tc.desc: Test NativeArgsChildProcess Create works
51  * @tc.type: FUNC
52  */
53 HWTEST_F(NativeArgsChildProcessTest, NativeArgsChildProcess_0100, TestSize.Level0)
54 {
55     TAG_LOGD(AAFwkTag::TEST, "NativeArgsChildProcess_0100 called.");
56     auto process = NativeArgsChildProcess::Create();
57     EXPECT_TRUE(process != nullptr);
58 }
59 
60 /**
61  * @tc.number: NativeArgsChildProcess_0200
62  * @tc.desc: Test NativeArgsChildProcess Init works
63  * @tc.type: FUNC
64  */
65 HWTEST_F(NativeArgsChildProcessTest, NativeArgsChildProcess_0200, TestSize.Level0)
66 {
67     TAG_LOGD(AAFwkTag::TEST, "NativeArgsChildProcess_0200 called.");
68     auto process = NativeArgsChildProcess::Create();
69     EXPECT_TRUE(process != nullptr);
70 
71     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
72     info->name = "AProcess";
73     info->srcEntry = "libentry.so:Main";
74     info->moduleName = "entry";
75 
76     process->Init(info);
77     EXPECT_TRUE(process->processStartInfo_ != nullptr);
78 }
79 
80 /**
81  * @tc.number: NativeArgsChildProcess_0300
82  * @tc.desc: Test NativeArgsChildProcess Init works
83  * @tc.type: FUNC
84  */
85 HWTEST_F(NativeArgsChildProcessTest, NativeArgsChildProcess_0300, TestSize.Level0)
86 {
87     TAG_LOGD(AAFwkTag::TEST, "NativeArgsChildProcess_0300 called.");
88     auto process = NativeArgsChildProcess::Create();
89     EXPECT_TRUE(process != nullptr);
90 
91     auto ret = process->Init(nullptr);
92     EXPECT_FALSE(ret);
93 }
94 
95 /**
96  * @tc.number: NativeArgsChildProcess_0400
97  * @tc.desc: Test NativeArgsChildProcess OnStart works
98  * @tc.type: FUNC
99  */
100 HWTEST_F(NativeArgsChildProcessTest, NativeArgsChildProcess_0400, TestSize.Level0)
101 {
102     TAG_LOGD(AAFwkTag::TEST, "NativeArgsChildProcess_0400 called.");
103     auto process = NativeArgsChildProcess::Create();
104     EXPECT_TRUE(process != nullptr);
105 
106     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
107     info->name = "AProcess";
108     info->srcEntry = "entry/./ets/process/AProcess.ts";
109     info->moduleName = "entry";
110 
111     process->Init(info);
112     process->OnStart();
113     EXPECT_TRUE(process->processStartInfo_ != nullptr);
114 }
115 }  // namespace AbilityRuntime
116 }  // namespace OHOS