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 "cj_ability_delegator.h"
19 #include "cj_application_context.h"
20 #include "ability_delegator_registry.h"
21 #include "application_context.h"
22 #include "cj_utils_ffi.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS::FFI;
27 using namespace OHOS::AbilityRuntime;
28 using namespace OHOS::AppExecFwk;
29
30 namespace OHOS {
31 namespace ApplicationContextCJ {
32
33 class CjApplicationContextTest : public testing::Test {
34 public:
CjApplicationContextTest()35 CjApplicationContextTest()
36 {}
~CjApplicationContextTest()37 ~CjApplicationContextTest()
38 {}
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp() override;
42 void TearDown() override;
43 protected:
44 std::shared_ptr<AbilityRuntime::ApplicationContext> appContext_;
45 std::shared_ptr<CJApplicationContext> cjAppContext_;
46 };
47
SetUpTestCase()48 void CjApplicationContextTest::SetUpTestCase()
49 {}
50
TearDownTestCase()51 void CjApplicationContextTest::TearDownTestCase()
52 {}
53
SetUp()54 void CjApplicationContextTest::SetUp()
55 {
56 }
57
TearDown()58 void CjApplicationContextTest::TearDown()
59 {}
60
61 /**
62 * @tc.name: CJApplicationContextTestGetArea_001
63 * @tc.desc: CjApplicationContextTest test for GetArea.
64 * @tc.type: FUNC
65 */
66 HWTEST_F(CjApplicationContextTest, CJApplicationContextTestGetArea_001, TestSize.Level1)
67 {
68 // 创建一个 ApplicationContext 对象
69 auto appInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
70 appInfo->name = "TestApp";
71 appInfo->bundleName = "com.example.testapp";
72 appContext_ = std::make_shared<AbilityRuntime::ApplicationContext>();
73 appContext_->SetApplicationInfo(appInfo);
74
75 // 创建一个 CJApplicationContext 对象
76 cjAppContext_ = std::make_shared<CJApplicationContext>(appContext_);
77 // 测试 GetArea 函数
78 int area = cjAppContext_->GetArea();
79 EXPECT_EQ(area, 1);
80 }
81
82 /**
83 * @tc.name: CJApplicationContextTestGetApplicationInfo_001
84 * @tc.desc: CjApplicationContextTest test for GetApplicationInfo.
85 * @tc.type: FUNC
86 */
87 HWTEST_F(CjApplicationContextTest, CJApplicationContextTestGetApplicationInfo_001, TestSize.Level1)
88 {
89 // 创建一个 ApplicationContext 对象
90 auto appInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
91 appInfo->name = "TestApp";
92 appInfo->bundleName = "com.example.testapp";
93 appContext_ = std::make_shared<AbilityRuntime::ApplicationContext>();
94 appContext_->SetApplicationInfo(appInfo);
95
96 // 创建一个 CJApplicationContext 对象
97 cjAppContext_ = std::make_shared<CJApplicationContext>(appContext_);
98
99 // 测试 GetApplicationInfo 函数
100 auto appInfoResult = cjAppContext_->GetApplicationInfo();
101 }
102
103 } // namespace AbilityRuntime
104 } // namespace OHOS