Publishing R3
[platform/upstream/dldt.git] / inference-engine / tests / helpers / test_assertions.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #include <gtest/gtest.h>
7 #include "inference_engine.hpp"
8
9 #define ASSERT_BLOB_EQ(lhs, rhs) \
10 compare_blob(lhs,rhs)
11
12 #define ASSERT_DIMS_EQ(lhs, rhs) \
13 compare_dims(lhs,rhs)
14
15 #define ASSERT_DATA_EQ(lhs, rhs) \
16 compare_data(lhs,rhs)
17
18 #define ASSERT_PREPROCESS_CHANNEL_EQ(lhs, rhs) \
19 compare_preprocess(lhs,rhs)
20
21 #define ASSERT_PREPROCESS_INFO_EQ(lhs, rhs) \
22 compare_preprocess_info(lhs,rhs)
23
24 #define ASSERT_OUTPUTS_INFO_EQ(lhs, rhs) \
25 compare_outputs_info(lhs,rhs)
26
27 #define ASSERT_INPUTS_INFO_EQ(lhs, rhs) \
28 compare_inputs_info(lhs,rhs)
29
30 #define ASSERT_STRINGEQ(lhs, rhs) \
31 compare_cpp_strings(lhs,rhs)
32
33
34
35 inline void compare_blob(InferenceEngine::Blob::Ptr lhs, InferenceEngine::Blob::Ptr rhs) {
36     ASSERT_EQ(lhs.get(), rhs.get());
37     //TODO: add blob specific comparison for general case
38 }
39
40 inline void compare_dims(const InferenceEngine::SizeVector & lhs, const InferenceEngine::SizeVector & rhs) {
41     ASSERT_EQ(lhs.size(), rhs.size());
42     for(int i=0;i<lhs.size();i++) {
43         ASSERT_EQ(lhs[i], rhs[i]);
44     }
45 }
46
47 inline void compare_data(const InferenceEngine::Data & lhs, const InferenceEngine::Data & rhs) {
48     ASSERT_DIMS_EQ(lhs.getDims(), rhs.getDims());
49     ASSERT_STREQ(lhs.getName().c_str(), rhs.getName().c_str());
50     ASSERT_EQ(lhs.getPrecision(), rhs.getPrecision());
51 }
52
53 inline void compare_preprocess(const InferenceEngine::PreProcessChannel & lhs, const InferenceEngine::PreProcessChannel & rhs) {
54     ASSERT_FLOAT_EQ(lhs.meanValue, rhs.meanValue);
55     ASSERT_FLOAT_EQ(lhs.stdScale, rhs.stdScale);
56     ASSERT_BLOB_EQ(lhs.meanData, rhs.meanData);
57 }
58
59 inline void compare_preprocess_info(const InferenceEngine::PreProcessInfo & lhs, const InferenceEngine::PreProcessInfo & rhs) {
60     ASSERT_EQ(lhs.getMeanVariant(), rhs.getMeanVariant());
61     ASSERT_EQ(lhs.getNumberOfChannels(), rhs.getNumberOfChannels());
62     for(int i=0; i < lhs.getNumberOfChannels(); i++) {
63         ASSERT_PREPROCESS_CHANNEL_EQ(*lhs[i].get(), *rhs[i].get());
64     }
65 }
66
67 inline void compare_outputs_info(const InferenceEngine::OutputsDataMap & lhs, const InferenceEngine::OutputsDataMap & rhs) {
68     ASSERT_EQ(lhs.size(), rhs.size());
69     auto i = lhs.begin();
70     auto j = rhs.begin();
71
72     for (int k =0; k != lhs.size(); k++, i++, j++) {
73         ASSERT_STREQ(i->first.c_str(), j->first.c_str());
74         ASSERT_DATA_EQ(*i->second.get(), *j->second.get());
75     }
76 }
77
78 inline void compare_inputs_info (const InferenceEngine::InputsDataMap & lhs, const InferenceEngine::InputsDataMap & rhs) {
79     ASSERT_EQ(lhs.size(), rhs.size());
80     auto i = lhs.begin();
81     auto j = rhs.begin();
82
83     for (int k =0; k != lhs.size(); k++, i++, j++) {
84         ASSERT_STREQ(i->first.c_str(), j->first.c_str());
85         ASSERT_DIMS_EQ(i->second->getDims(), j->second->getDims());
86         ASSERT_PREPROCESS_INFO_EQ(i->second->getPreProcess(), j->second->getPreProcess());
87         ASSERT_DATA_EQ(*i->second->getInputData().get(), *j->second->getInputData().get());
88     }
89 }
90
91 inline void compare_cpp_strings(const std::string & lhs, const std::string &rhs) {
92     ASSERT_STREQ(lhs.c_str(), rhs.c_str());
93 }