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 
16 #include "image_chain_unittest.h"
17 #include "image_chain.h"
18 #include "input.h"
19 #include "output.h"
20 #include "filter_factory.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 /**
28  * @tc.name: Render001
29  * @tc.desc: Render according to the input used for initialization
30  * @tc.type: FUNC
31  * @tc.require:
32  * @tc.author:
33  */
34 HWTEST_F(ImageChainUnittest, Render001, TestSize.Level1)
35 {
36     GTEST_LOG_(INFO) << "ImageChainUnittest Render001 start";
37     /**
38      * @tc.steps: step1. Create a ImageChain pointer
39      */
40     std::vector<std::shared_ptr<Rosen::Input>> inputs;
41     auto imageChain = std::make_shared<ImageChain>(inputs);
42     bool testResult1 = imageChain != nullptr;
43     EXPECT_TRUE(testResult1);
44     /**
45      * @tc.steps: step2. Call Render to render the resource
46      */
47 
48     auto testResult2 = imageChain->Render();
49     EXPECT_FALSE(testResult2);
50 }
51 
52 /**
53  * @tc.name: Render002
54  * @tc.desc: Render according to the input used for initialization
55  * @tc.type: FUNC
56  * @tc.require:
57  * @tc.author:
58  */
59 HWTEST_F(ImageChainUnittest, Render002, TestSize.Level1)
60 {
61     GTEST_LOG_(INFO) << "ImageChainUnittest Render002 start";
62     /**
63      * @tc.steps: step1. Create a ImageChain pointer
64      */
65     auto input = std::make_shared<Input>();
66     std::vector<std::shared_ptr<Rosen::Input>> inputs;
67     inputs.push_back(input);
68     auto imageChain = std::make_shared<ImageChain>(inputs);
69     bool testResult1 = imageChain != nullptr;
70     EXPECT_TRUE(testResult1);
71     /**
72      * @tc.steps: step2. Call Render to render the resource
73      */
74 
75     auto testResult2 = imageChain->Render();
76     EXPECT_FALSE(testResult2);
77 }
78 
79 /**
80  * @tc.name: Render003
81  * @tc.desc: Render according to the input used for initialization
82  * @tc.type: FUNC
83  * @tc.require:
84  * @tc.author:
85  */
86 HWTEST_F(ImageChainUnittest, Render003, TestSize.Level1)
87 {
88     GTEST_LOG_(INFO) << "ImageChainUnittest Render003 start";
89     /**
90      * @tc.steps: step1. Create a ImageChain pointer
91      */
92     FilterFactory filterFactory;
93     auto input = filterFactory.GetFilter("Input");
94     auto inputFormat = std::make_shared<std::string>("pixelMap");
95     std::weak_ptr<void> vInputFormat = inputFormat;
96     input->SetValue("format", vInputFormat.lock(), 1);
97     Media::InitializationOptions opts;
98     opts.size.width = 512;
99     opts.size.height = 512;
100     opts.editable = true;
101     auto pixelMap = Media::PixelMap::Create(opts);
102     auto shpPixelMap =  std::shared_ptr<Media::PixelMap>(pixelMap.release());
103     std::weak_ptr<void> vPixelMap = shpPixelMap;
104     input->SetValue("src", vPixelMap.lock(), 1);
105     auto output = std::make_shared<Output>();
106     auto outputFormat = std::make_shared<std::string>("pixelMap");
107     std::weak_ptr<void> vOutputFormat = outputFormat;
108     output->SetValue("format", vOutputFormat.lock(), 1);
109     auto castOutput = std::static_pointer_cast<Rosen::Filter>(output);
110     input->AddNextFilter(castOutput);
111     std::vector<std::shared_ptr<Rosen::Input>> inputs;
112     auto castInput = std::static_pointer_cast<Rosen::Input>(input);
113     inputs.push_back(castInput);
114     auto imageChain = std::make_shared<ImageChain>(inputs);
115     /**
116      * @tc.steps: step2. Call Render to render the resource
117      */
118     auto testResult2 = imageChain->Render();
119     EXPECT_TRUE(testResult2);
120 }
121 } // namespace Rosen
122 } // namespace OHOS
123