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 <gtest/gtest.h>
17 
18 #include "validation.h"
19 #include "nn_tensor.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 using namespace OHOS::NeuralNetworkRuntime;
24 using namespace OHOS::NeuralNetworkRuntime::Validation;
25 
26 namespace NNRT {
27 namespace UnitTest {
28 class NnValidationTest : public testing::Test {
29 };
30 
31 /**
32  * @tc.name: nn_validation_validate_tensor_datatype_001
33  * @tc.desc: Verify the success of the validate_tensor_datatype function
34  * @tc.type: FUNC
35  */
36 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_001, TestSize.Level1)
37 {
38     int dataTypeTest = 12;
39     OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest;
40     EXPECT_EQ(true, ValidateTensorDataType(dataType));
41 }
42 
43 /**
44  * @tc.name: nn_validation_validate_tensor_datatype_002
45  * @tc.desc: Verify the gt bounds of the validate_tensor_datatype function
46  * @tc.type: FUNC
47  */
48 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_002, TestSize.Level1)
49 {
50     int dataTypeTest = 13;
51     OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest;
52     EXPECT_EQ(false, ValidateTensorDataType(dataType));
53 }
54 
55 /**
56  * @tc.name: nn_validation_validate_tensor_datatype_003
57  * @tc.desc: Verify the lt bounds of the validate_tensor_datatype function
58  * @tc.type: FUNC
59  */
60 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_003, TestSize.Level1)
61 {
62     int dataTypeTest = -1;
63     OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest;
64     EXPECT_EQ(false, ValidateTensorDataType(dataType));
65 }
66 
67 /**
68  * @tc.name: nn_validation_validate_tensor_Format_001
69  * @tc.desc: Verify the success of the validate_tensor_datatype function
70  * @tc.type: FUNC
71  */
72 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_Format_001, TestSize.Level1)
73 {
74     int forMatTest = 2;
75     OH_NN_Format forMat = (OH_NN_Format)forMatTest;
76     EXPECT_EQ(true, ValidateTensorFormat(forMat));
77 }
78 
79 /**
80  * @tc.name: nn_validation_validate_preformance_mode_001
81  * @tc.desc: Verify the success of the validate_preformance_mode function
82  * @tc.type: FUNC
83  */
84 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_001, TestSize.Level1)
85 {
86     int performanceModeTest = 4;
87     OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest;
88     EXPECT_EQ(true, ValidatePerformanceMode(performanceMode));
89 }
90 
91 /**
92  * @tc.name: nn_validation_validate_preformance_mode_002
93  * @tc.desc: Verify the gt bounds of the validate_preformance_mode function
94  * @tc.type: FUNC
95  */
96 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_002, TestSize.Level1)
97 {
98     int performanceModeTest = 5;
99     OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest;
100     EXPECT_EQ(false, ValidatePerformanceMode(performanceMode));
101 }
102 
103 /**
104  * @tc.name: nn_validation_validate_preformance_mode_003
105  * @tc.desc: Verify the lt bounds of the validate_preformance_mode function
106  * @tc.type: FUNC
107  */
108 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_003, TestSize.Level1)
109 {
110     int performanceModeTest = -1;
111     OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest;
112     EXPECT_EQ(false, ValidatePerformanceMode(performanceMode));
113 }
114 
115 /**
116  * @tc.name: nn_validation_validate_priority_001
117  * @tc.desc: Verify the success of the validate_priority function
118  * @tc.type: FUNC
119  */
120 HWTEST_F(NnValidationTest, nn_validation_validate_priority_001, TestSize.Level1)
121 {
122     int priorityTest = 2;
123     OH_NN_Priority priority = (OH_NN_Priority)priorityTest;
124     EXPECT_EQ(true, ValidatePriority(priority));
125 }
126 
127 /**
128  * @tc.name: nn_validation_validate_priority_002
129  * @tc.desc: Verify the gt bounds of the validate_priority function
130  * @tc.type: FUNC
131  */
132 HWTEST_F(NnValidationTest, nn_validation_validate_priority_002, TestSize.Level1)
133 {
134     int priorityTest = 4;
135     OH_NN_Priority priority = (OH_NN_Priority)priorityTest;
136     EXPECT_EQ(false, ValidatePriority(priority));
137 }
138 
139 /**
140  * @tc.name: nn_validation_validate_priority_003
141  * @tc.desc: Verify the lt bounds of the validate_priority function
142  * @tc.type: FUNC
143  */
144 HWTEST_F(NnValidationTest, nn_validation_validate_priority_003, TestSize.Level1)
145 {
146     int priorityTest = -1;
147     OH_NN_Priority priority = (OH_NN_Priority)priorityTest;
148     EXPECT_EQ(false, ValidatePriority(priority));
149 }
150 
151 /**
152  * @tc.name: nn_validation_fusetype_001
153  * @tc.desc: Verify the success of the validate_fusetype function
154  * @tc.type: FUNC
155  */
156 HWTEST_F(NnValidationTest, nn_validation_fusetype_001, TestSize.Level1)
157 {
158     int fuseTypeTest = 2;
159     OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest;
160     EXPECT_EQ(true, ValidateFuseType(fuseType));
161 }
162 
163 /**
164  * @tc.name: nn_validation_fusetype_002
165  * @tc.desc: Verify the gt bounds of the validate_fusetype function
166  * @tc.type: FUNC
167  */
168 HWTEST_F(NnValidationTest, nn_validation_fusetype_002, TestSize.Level1)
169 {
170     int fuseTypeTest = 3;
171     OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest;
172     EXPECT_EQ(false, ValidateFuseType(fuseType));
173 }
174 
175 /**
176  * @tc.name: nn_validation_fusetype_003
177  * @tc.desc: Verify the lt bounds of the validate_fusetype function
178  * @tc.type: FUNC
179  */
180 HWTEST_F(NnValidationTest, nn_validation_fusetype_003, TestSize.Level1)
181 {
182     int fuseTypeTest = -1;
183     OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest;
184     EXPECT_EQ(false, ValidateFuseType(fuseType));
185 }
186 
187 /**
188  * @tc.name: nn_validation_tensortype_001
189  * @tc.desc: Verify the success of the validate_fusetype function
190  * @tc.type: FUNC
191  */
192 HWTEST_F(NnValidationTest, nn_validation_tensortype_001, TestSize.Level1)
193 {
194     int tensorTyepTest = 1;
195     OH_NN_TensorType tensorTyep = (OH_NN_TensorType)tensorTyepTest;
196     EXPECT_EQ(true, ValidateTensorType(tensorTyep));
197 }
198 
199 /**
200  * @tc.name: nn_validation_tensortype_002
201  * @tc.desc: Verify the success of the validate_fusetype function
202  * @tc.type: FUNC
203  */
204 HWTEST_F(NnValidationTest, nn_validation_tensortype_002, TestSize.Level1)
205 {
206     int tensorTyepTest = 163;
207     OH_NN_TensorType tensorTyep = (OH_NN_TensorType)tensorTyepTest;
208     EXPECT_EQ(false, ValidateTensorType(tensorTyep));
209 }
210 } // namespace UnitTest
211 } // namespace NNRT
212