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 "ops_registry.h"
20 #include "ops/add_builder.h"
21 #include "ops/div_builder.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace OHOS::NeuralNetworkRuntime;
26 using namespace OHOS::NeuralNetworkRuntime::Validation;
27 using namespace OHOS::NeuralNetworkRuntime::Ops;
28 
29 namespace NNRT {
30 namespace UnitTest {
31 class OpsRegistryTest : public testing::Test {
32 };
33 
34 /**
35  * @tc.name: registry_001
36  * @tc.desc: Verify the registry success the registar function
37  * @tc.type: FUNC
38  */
39 HWTEST_F(OpsRegistryTest, registry_001, TestSize.Level1)
40 {
41     const int newRegistryOperationType = 100;
42     REGISTER_OPS(AddBuilder, OH_NN_OperationType(newRegistryOperationType));
43 
44     OpsRegistry& opsregistry = OpsRegistry::GetSingleton();
45     EXPECT_NE(nullptr, opsregistry.GetOpsBuilder(OH_NN_OperationType(newRegistryOperationType)));
46 }
47 
48 /**
49  * @tc.name: registry_002
50  * @tc.desc: Verify the registry twice the registar function
51  * @tc.type: FUNC
52  */
53 HWTEST_F(OpsRegistryTest, registry_002, TestSize.Level1)
54 {
55     const int newRegistryOperationType = 1000;
56     REGISTER_OPS(AddBuilder, OH_NN_OperationType(newRegistryOperationType));
57 
58     OpsRegistry& opsregistry = OpsRegistry::GetSingleton();
59     EXPECT_NE(nullptr, opsregistry.GetOpsBuilder(OH_NN_OperationType(newRegistryOperationType)));
60 
61     REGISTER_OPS(DivBuilder, OH_NN_OperationType(newRegistryOperationType));
62 }
63 } // namespace UnitTest
64 } // namespace NNRT
65