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 <dlfcn.h>
17 #include <gtest/gtest.h>
18 #include "photo_editor_extension_module_loader.h"
19 
20 namespace OHOS {
21 namespace AbilityRuntime {
22 using namespace testing::ext;
23 
24 class PhotoEditorExtensionModuleLoaderTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     void SetUp();
29     void TearDown();
30 };
31 
SetUpTestCase(void)32 void PhotoEditorExtensionModuleLoaderTest::SetUpTestCase(void)
33 {}
34 
TearDownTestCase(void)35 void PhotoEditorExtensionModuleLoaderTest::TearDownTestCase(void)
36 {}
37 
SetUp(void)38 void PhotoEditorExtensionModuleLoaderTest::SetUp(void)
39 {}
40 
TearDown(void)41 void PhotoEditorExtensionModuleLoaderTest::TearDown(void)
42 {}
43 
44 /**
45  * @tc.number: PhotoEditorExtensionModuleLoader_0100
46  * @tc.name: OHOS_EXTENSION_GetExtensionModule
47  * @tc.desc: Verify OHOS_EXTENSION_GetExtensionModule succeeded.
48  */
49 HWTEST_F(PhotoEditorExtensionModuleLoaderTest, PhotoEditorExtensionModuleLoader_0100, Function | MediumTest | Level1)
50 {
51     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0100 start";
52     std::unique_ptr<Runtime> runtime;
53     auto extension = PhotoEditorExtensionModuleLoader::GetInstance().Create(runtime);
54     void *handle = dlopen("/system/lib/extensionability/libphoto_editor_extension_module.z.so", RTLD_LAZY);
55     dlclose(handle);
56     EXPECT_TRUE(extension != nullptr);
57     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0100 end";
58 }
59 
60 /**
61  * @tc.number: PhotoEditorExtensionModuleLoader_0200
62  * @tc.name: Create
63  * @tc.desc: Verify Create succeeded.
64  */
65 HWTEST_F(PhotoEditorExtensionModuleLoaderTest, PhotoEditorExtensionModuleLoader_0200, Function | MediumTest | Level1)
66 {
67     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0200 start";
68     std::unique_ptr<Runtime> runtime;
69     auto extension = PhotoEditorExtensionModuleLoader::GetInstance().Create(runtime);
70     EXPECT_TRUE(extension != nullptr);
71     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0200 end";
72 }
73 
74 /**
75  * @tc.number: PhotoEditorExtensionModuleLoader_0300
76  * @tc.name: GetParams
77  * @tc.desc: Verify GetParams succeeded.
78  */
79 HWTEST_F(PhotoEditorExtensionModuleLoaderTest, PhotoEditorExtensionModuleLoader_0300, Function | MediumTest | Level1)
80 {
81     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0300 start";
82     auto params = PhotoEditorExtensionModuleLoader::GetInstance().GetParams();
83 
84     std::string key = "type";
85     auto finder = params.find(key);
86     if (finder != params.end()) {
87         EXPECT_STREQ(finder->second.c_str(), "23");
88     }
89 
90     key = "name";
91     auto iter = params.find(key);
92     if (iter != params.end()) {
93         EXPECT_STREQ(iter->second.c_str(), "PhotoEditorExtensionAbility");
94     }
95     GTEST_LOG_(INFO) << "PhotoEditorExtensionModuleLoader_0300 end";
96 }
97 } // namespace AbilityRuntime
98 } // namespace OHOS
99