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 "program_unittest.h"
17 #include "program.h"
18 #include "horizontal_blur_filter.h"
19 #include "vertical_blur_filter.h"
20 #include "saturation_filter.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 /**
28  * @tc.name: Compile001
29  * @tc.desc: Compile the program based on the input string
30  * @tc.type: FUNC
31  * @tc.require:
32  * @tc.author:
33  */
34 HWTEST_F(ProgramUnittest, Compile001, TestSize.Level1)
35 {
36     GTEST_LOG_(INFO) << "ProgramUnittest Compile001 start";
37     /**
38      * @tc.steps: step1. Create a Program pointer
39      */
40     auto program = std::make_shared<Program>();
41     bool testResult = program != nullptr;
42     EXPECT_TRUE(testResult);
43     /**
44      * @tc.steps: step2. Call Compile to compile the program
45      */
46     auto horizon = std::make_shared<HorizontalBlurFilter>();
47     program->Compile(horizon->GetVertexShader(), horizon->GetFragmentShader());
48 }
49 
50 /**
51  * @tc.name: Compile002
52  * @tc.desc: Compile the program based on the input string
53  * @tc.type: FUNC
54  * @tc.require:
55  * @tc.author:
56  */
57 HWTEST_F(ProgramUnittest, Compile002, TestSize.Level1)
58 {
59     GTEST_LOG_(INFO) << "ProgramUnittest Compile002 start";
60     /**
61      * @tc.steps: step1. Create a Program pointer
62      */
63     auto program = std::make_shared<Program>();
64     bool testResult = program != nullptr;
65     EXPECT_TRUE(testResult);
66     /**
67      * @tc.steps: step2. Call Compile to compile the program
68      */
69     auto vertical = std::make_shared<VerticalBlurFilter>();
70     program->Compile(vertical->GetVertexShader(), vertical->GetFragmentShader());
71 }
72 
73 /**
74  * @tc.name: Compile003
75  * @tc.desc: Compile the program based on the input string
76  * @tc.type: FUNC
77  * @tc.require:
78  * @tc.author:
79  */
80 HWTEST_F(ProgramUnittest, Compile003, TestSize.Level1)
81 {
82     GTEST_LOG_(INFO) << "ProgramUnittest Compile003 start";
83     /**
84      * @tc.steps: step1. Create a Program pointer
85      */
86     auto program = std::make_shared<Program>();
87     bool testResult = program != nullptr;
88     EXPECT_TRUE(testResult);
89     /**
90      * @tc.steps: step2. Call Compile to compile the program
91      */
92     auto saturation = std::make_shared<SaturationFilter>();
93     program->Compile(saturation->GetVertexShader(), saturation->GetFragmentShader());
94 }
95 
96 /**
97  * @tc.name: UseProgram001
98  * @tc.desc: Use the compiled program
99  * @tc.type: FUNC
100  * @tc.require:
101  * @tc.author:
102  */
103 HWTEST_F(ProgramUnittest, UseProgram001, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "ProgramUnittest UseProgram001 start";
106     /**
107      * @tc.steps: step1. Create a Program pointer
108      */
109     auto program = std::make_shared<Program>();
110     bool testResult = program != nullptr;
111     EXPECT_TRUE(testResult);
112     /**
113      * @tc.steps: step2. Call UseProgram to use the program
114      */
115     auto saturation = std::make_shared<SaturationFilter>();
116     program->Compile(saturation->GetVertexShader(), saturation->GetFragmentShader());
117     EXPECT_TRUE(program->programID_ >= 0);
118     program->UseProgram();
119 }
120 } // namespace Rosen
121 } // namespace OHOS
122