• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "effect_chain_unittest.h"
17 
18 #include <iostream>
19 #include <fstream>
20 
21 #include "builder.h"
22 #include "image_chain.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 
30 /**
31  * @tc.name: BuilderCreateFromConfigTest001
32  * @tc.desc: Ensure the ability of creating effect chain from config file.
33  * @tc.type: FUNC
34  * @tc.require:
35  * @tc.author:
36  */
37 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest001, TestSize.Level1)
38 {
39     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest001 start";
40     /**
41      * @tc.steps: step1. Create a builder pointer
42      */
43     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
44     /**
45      * @tc.steps: step2. Call createFromConfig to load file
46      */
47     ImageChain* imageChain = builder->CreateFromConfig("/cannot/find/config.json");
48     EXPECT_EQ(imageChain, nullptr);
49 }
50 
51 /**
52  * @tc.name: BuilderCreateFromConfigTest002
53  * @tc.desc: Ensure the ability of creating effect chain from config file.
54  * @tc.type: FUNC
55  * @tc.require:
56  * @tc.author:
57  */
58 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest002, TestSize.Level1)
59 {
60     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest002 start";
61     /**
62      * @tc.steps: step1. Create a builder pointer
63      */
64     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
65     /**
66      * @tc.steps: step2. Call createFromConfig to load file
67      */
68     ImageChain* imageChain = builder->CreateFromConfig("config.json");
69     EXPECT_EQ(imageChain, nullptr);
70 }
71 
72 /**
73  * @tc.name: BuilderCreateFromConfigTest003
74  * @tc.desc: Ensure the ability of creating effect chain from config file.
75  * @tc.type: FUNC
76  * @tc.require:
77  * @tc.author:
78  */
79 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest003, TestSize.Level1)
80 {
81     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest003 start";
82     /**
83      * @tc.steps: step1. Create a builder pointer
84      */
85     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
86     /**
87      * @tc.steps: step2. Call createFromConfig to load file
88      */
89     ImageChain* imageChain = builder->CreateFromConfig("");
90     EXPECT_EQ(imageChain, nullptr);
91 }
92 
93 /**
94  * @tc.name: BuilderCreateFromConfigTest004
95  * @tc.desc: Ensure the ability of creating effect chain from config file.
96  * @tc.type: FUNC
97  * @tc.require:
98  * @tc.author:
99  */
100 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest004, TestSize.Level1)
101 {
102     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest004 start";
103     /**
104      * @tc.steps: step1. Create a builder pointer
105      */
106     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
107     /**
108      * @tc.steps: step2. Call createFromConfig to load file
109      */
110     const std::string jsonStr_ = R"({ "filters": [ { "type" : "Input", "name" : "myJPGInput", "params":
111         { "format": "png", "src": "/data/accounts/account_0/appdata/com.example.myapplication/files/
112         milk.png" } } ], "connections" : [ { "from" : "myJPGInput", "to" : "myJPGOutput" } ] })";
113     std::ofstream outFile;
114     outFile.open("test.json");
115     outFile << jsonStr_.c_str() << std::endl;
116     outFile.close();
117 
118     ImageChain* imageChain = builder->CreateFromConfig("test.json");
119     EXPECT_TRUE(imageChain != nullptr);
120     system("rm -rf test.json");
121 }
122 
123 /**
124  * @tc.name: BuilderCreateFromConfigTest005
125  * @tc.desc: Ensure the ability of creating effect chain from config file.
126  * @tc.type: FUNC
127  * @tc.require:
128  * @tc.author:
129  */
130 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest005, TestSize.Level1)
131 {
132     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest005 start";
133     /**
134      * @tc.steps: step1. Create a builder pointer
135      */
136     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
137     /**
138      * @tc.steps: step2. Call createFromConfig to load file
139      */
140     const std::string jsonStr_ = R"({"connections" : [ { "from" : "myJPGInput", "to" : "myJPGOutput" } ] })";
141     std::ofstream outFile;
142     outFile.open("test.json");
143     outFile << jsonStr_.c_str() << std::endl;
144     outFile.close();
145 
146     ImageChain* imageChain = builder->CreateFromConfig("test.json");
147     EXPECT_EQ(imageChain, nullptr);
148     system("rm -rf test.json");
149 }
150 
151 /**
152  * @tc.name: BuilderCreateFromConfigTest006
153  * @tc.desc: Ensure the ability of creating effect chain from config file.
154  * @tc.type: FUNC
155  * @tc.require:
156  * @tc.author:
157  */
158 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest006, TestSize.Level1)
159 {
160     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest006 start";
161     /**
162      * @tc.steps: step1. Create a builder pointer
163      */
164     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
165     /**
166      * @tc.steps: step2. Call createFromConfig to load file
167      */
168     const std::string jsonStr_ = R"({ "filters": [ { "type" : "Input", "name" : "myJPGInput", "params":
169         { "format": "png", "src": "/data/accounts/account_0/appdata/com.example.myapplication/files/
170         milk.png" } } ] })";
171     std::ofstream outFile;
172     outFile.open("test.json");
173     outFile << jsonStr_.c_str() << std::endl;
174     outFile.close();
175 
176     ImageChain* imageChain = builder->CreateFromConfig("test.json");
177     EXPECT_EQ(imageChain, nullptr);
178     system("rm -rf test.json");
179 }
180 
181 /**
182  * @tc.name: BuilderCreateFromConfigTest007
183  * @tc.desc: Ensure the ability of creating effect chain from config file.
184  * @tc.type: FUNC
185  * @tc.require:
186  * @tc.author:
187  */
188 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest007, TestSize.Level1)
189 {
190     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest007 start";
191     /**
192      * @tc.steps: step1. Create a builder pointer
193      */
194     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
195     /**
196      * @tc.steps: step2. Call createFromConfig to load file
197      */
198     const std::string jsonStr_ = R"({ "filters": [ { "type" : "Input", "name" : "myJPGInput"
199         } ], "connections" : [ { "from" : "myJPGInput", "to" : "myJPGOutput" } ] })";
200     std::ofstream outFile;
201     outFile.open("test.json");
202     outFile << jsonStr_.c_str() << std::endl;
203     outFile.close();
204 
205     ImageChain* imageChain = builder->CreateFromConfig("test.json");
206     EXPECT_TRUE(imageChain != nullptr);
207     system("rm -rf test.json");
208 }
209 
210 /**
211  * @tc.name: BuilderCreateFromConfigTest008
212  * @tc.desc: Ensure the ability of creating effect chain from config file.
213  * @tc.type: FUNC
214  * @tc.require:
215  * @tc.author:
216  */
217 HWTEST_F(EffectChainUnittest, BuilderCreateFromConfigTest008, TestSize.Level1)
218 {
219     GTEST_LOG_(INFO) << "EffectChainUnittest BuilderCreateFromConfigTest008 start";
220     /**
221      * @tc.steps: step1. Create a builder pointer
222      */
223     std::unique_ptr<Builder> builder = std::make_unique<Builder>();
224     /**
225      * @tc.steps: step2. Call createFromConfig to load file
226      */
227     const std::string jsonStr_ = R"({ "filters": [ { "type" : "Input", "name" : "myJPGInput", "params":
228         { "format": "png", "src": "/data/accounts/account_0/appdata/com.example.myapplication/files/
229         milk.png" } } ], "connections" : [ {} ] })";
230     std::ofstream outFile;
231     outFile.open("test.json");
232     outFile << jsonStr_.c_str() << std::endl;
233     outFile.close();
234 
235     ImageChain* imageChain = builder->CreateFromConfig("test.json");
236     EXPECT_TRUE(imageChain == nullptr);
237     system("rm -rf test.json");
238 }
239 } // namespace Rosen
240 } // namespace OHOS
241