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 #ifndef NEURAL_NETWORK_RUNTIME_MOCK_IDEVICE_H
17 #define NEURAL_NETWORK_RUNTIME_MOCK_IDEVICE_H
18 
19 #include <gmock/gmock.h>
20 
21 #include "hdi_prepared_model_v2_0.h"
22 #include "memory_manager.h"
23 #include "transform.h"
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace Nnrt {
28 namespace V2_0 {
29 class MockIDevice : public INnrtDevice {
30 public:
31     MOCK_METHOD1(GetDeviceName, int32_t(std::string&));
32     MOCK_METHOD1(GetVendorName, int32_t(std::string&));
33     MOCK_METHOD1(GetDeviceType, int32_t(DeviceType&));
34     MOCK_METHOD1(GetDeviceStatus, int32_t(DeviceStatus&));
35     MOCK_METHOD2(GetSupportedOperation, int32_t(const Model&, std::vector<bool>&));
36     MOCK_METHOD1(IsFloat16PrecisionSupported, int32_t(bool&));
37     MOCK_METHOD1(IsPerformanceModeSupported, int32_t(bool&));
38     MOCK_METHOD1(IsPrioritySupported, int32_t(bool&));
39     MOCK_METHOD1(IsDynamicInputSupported, int32_t(bool&));
40     MOCK_METHOD3(PrepareModel, int32_t(const Model&, const ModelConfig&, OHOS::sptr<IPreparedModel>&));
41     MOCK_METHOD1(IsModelCacheSupported, int32_t(bool&));
42     MOCK_METHOD3(PrepareModelFromModelCache, int32_t(const std::vector<SharedBuffer>&, const ModelConfig&,
43         OHOS::sptr<IPreparedModel>&));
44     MOCK_METHOD3(PrepareOfflineModel, int32_t(const std::vector<SharedBuffer>&, const ModelConfig&,
45         sptr<OHOS::HDI::Nnrt::V2_0::IPreparedModel>&));
46     MOCK_METHOD2(AllocateBuffer, int32_t(uint32_t, SharedBuffer&));
47     MOCK_METHOD1(ReleaseBuffer, int32_t(const SharedBuffer&));
48     MOCK_METHOD2(GetVersion, int32_t(uint32_t&, uint32_t&));
49 };
50 
51 class MockIPreparedModel : public IPreparedModel {
52 public:
53     MOCK_METHOD1(ExportModelCache, int32_t(std::vector<SharedBuffer>&));
54     MOCK_METHOD3(Run, int32_t(const std::vector<IOTensor>&, const std::vector<IOTensor>&,
55         std::vector<std::vector<int32_t>>&));
56     MOCK_METHOD2(GetInputDimRanges, int32_t(std::vector<std::vector<uint32_t>>&, std::vector<std::vector<uint32_t>>&));
57     MOCK_METHOD2(GetVersion, int32_t(uint32_t&, uint32_t&));
58 
59     static OH_NN_ReturnCode m_ExpectRetCode;
60 };
61 } // V2_0
62 } // Nnrt
63 } // HDI
64 } // OHOS
65 #endif // NEURAL_NETWORK_RUNTIME_MOCK_IDEVICE_H
66