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_v1_0.h"
22 #include "memory_manager.h"
23 #include "transform.h"
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace Nnrt {
28 namespace V1_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_METHOD2(AllocateBuffer, int32_t(uint32_t, SharedBuffer&));
45     MOCK_METHOD1(ReleaseBuffer, int32_t(const SharedBuffer&));
46     MOCK_METHOD2(GetVersion, int32_t(uint32_t&, uint32_t&));
47 };
48 
49 class MockIPreparedModel : public IPreparedModel {
50 public:
51     MOCK_METHOD1(ExportModelCache, int32_t(std::vector<SharedBuffer>&));
52     MOCK_METHOD4(Run, int32_t(const std::vector<IOTensor>&, const std::vector<IOTensor>&,
53         std::vector<std::vector<int32_t>>&, std::vector<bool>&));
54     MOCK_METHOD2(GetVersion, int32_t(uint32_t&, uint32_t&));
55 
56     static OH_NN_ReturnCode m_ExpectRetCode;
57 };
58 } // V1_0
59 } // Nnrt
60 } // HDI
61 } // OHOS
62 #endif // NEURAL_NETWORK_RUNTIME_MOCK_IDEVICE_H
63