1 /*
2 * Copyright (c) 2024 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 #include "ability.h"
19 #include "cj_ability_object.h"
20 #include "cj_runtime.h"
21 #include "configuration.h"
22 #include "window_stage_impl.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::AbilityRuntime;
28
29 class CjAbilityObjectTest : public testing::Test {
30 };
31
ProxyCall()32 bool ProxyCall()
33 {
34 CJAbilityObject::LoadModule("0");
35 CJAbilityObject::LoadModule("1");
36 Want want;
37 auto proxy = CJAbilityObject(0);
38 proxy.Init(nullptr);
39 proxy.OnStart(want, AAFwk::LaunchParam());
40 auto win = std::make_shared<Rosen::WindowScene>();
41 auto winStage = new Rosen::CJWindowStageImpl(win);
42 proxy.OnSceneCreated(winStage);
43 proxy.OnSceneRestored(winStage);
44 proxy.OnForeground(want);
45 proxy.OnBackground();
46 auto config = std::make_shared<AppExecFwk::Configuration>();
47 proxy.OnConfigurationUpdated(config);
48 proxy.OnNewWant(want, AAFwk::LaunchParam());
49 std::vector<std::string> params = {"123"};
50 std::vector<std::string> infos = {"123"};
51 AAFwk::WantParams wantParams = AAFwk::WantParams();
52 proxy.OnContinue(wantParams);
53 proxy.Dump(params, infos);
54 proxy.OnSceneDestroyed();
55 proxy.OnStop();
56 return true;
57 }
58
59 HWTEST_F(CjAbilityObjectTest, CJAbilityObject001, TestSize.Level1)
60 {
61 auto result = ProxyCall();
62 EXPECT_TRUE(result);
63 }
64
65 HWTEST_F(CjAbilityObjectTest, CJAbilityObject002, TestSize.Level1)
66 {
__anon039eb82a0102(CJAbilityFuncs* funcs) 67 auto registerFunc = [](CJAbilityFuncs* funcs) {
68 funcs->cjAbilityCreate = [](const char* name) -> int64_t { return name[0] == '0' ? 0 : 1; };
69 funcs->cjAbilityRelease = [](int64_t id) {};
70 funcs->cjAbilityOnStart = [](int64_t id, WantHandle want, CJLaunchParam launchParam) {};
71 funcs->cjAbilityOnStop = [](int64_t id) {};
72 funcs->cjAbilityOnSceneCreated = [](int64_t id, WindowStagePtr cjWindowStage) {};
73 funcs->cjAbilityOnSceneRestored = [](int64_t id, WindowStagePtr cjWindowStage) {};
74 funcs->cjAbilityOnSceneDestroyed = [](int64_t id) {};
75 funcs->cjAbilityOnForeground = [](int64_t id, WantHandle want) {};
76 funcs->cjAbilityOnBackground = [](int64_t id) {};
77 funcs->cjAbilityOnConfigurationUpdated = [](int64_t id, CJConfiguration configuration) {};
78 funcs->cjAbilityOnNewWant = [](int64_t id, WantHandle want, CJLaunchParam launchParam) {};
79 funcs->cjAbilityDump = [](int64_t id, VectorStringHandle params) { return VectorStringHandle(); };
80 funcs->cjAbilityOnContinue = [](int64_t id, const char* params) { return 0; };
81 funcs->cjAbilityInit = [](int64_t id, void* ability) {};
82 };
83 RegisterCJAbilityFuncs(registerFunc);
84 ProxyCall();
85 RegisterCJAbilityFuncs(nullptr);
86 EXPECT_NE(registerFunc, nullptr);
87 }
88