Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / shape_infer / input_controller_test.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <gtest/gtest.h>
6 #include <gmock/gmock-matchers.h>
7
8 #include <shape_infer/mock_ishape_infer_impl.hpp>
9 #include <shape_infer/ie_reshape_io_controllers.hpp>
10
11 using namespace InferenceEngine;
12 using namespace InferenceEngine::details;
13 using namespace ShapeInfer;
14 using namespace ::testing;
15
16 class InputControllerTest : public ::testing::Test {
17 public:
18     static const std::string TEST_NAME;
19     DataPtr notEmptyData = std::make_shared<Data>(TEST_NAME, Precision::UNSPECIFIED, Layout::C);
20     SizeVector inDims{1};
21 };
22
23 const std::string InputControllerTest::TEST_NAME = "TEST_NAME";
24
25 TEST_F(InputControllerTest, failedToCreateWithEmptyInsData) {
26     EXPECT_THROW(InputController({}, TEST_NAME), InferenceEngineException);
27 }
28
29 TEST_F(InputControllerTest, failedToCreateWithNullData) {
30     EXPECT_THROW(InputController({nullptr}, TEST_NAME), InferenceEngineException);
31 }
32
33 TEST_F(InputControllerTest, canCreateInputController) {
34     ASSERT_NO_THROW(InputController({notEmptyData}, TEST_NAME));
35 }
36
37 TEST_F(InputControllerTest, canPushShapes) {
38     InputController controller({notEmptyData}, TEST_NAME);
39     ASSERT_NO_THROW(controller.setShapeByName(inDims, TEST_NAME));
40 }
41
42 TEST_F(InputControllerTest, DISABLED_throwOnGetWithNotEnoughShapes) {
43     InputController controller({notEmptyData, notEmptyData}, TEST_NAME);
44     controller.setShapeByName(inDims, TEST_NAME);
45     ASSERT_THROW(controller.getShapes(true), InferenceEngineException);
46 }
47
48 TEST_F(InputControllerTest, canGetWithNotEnoughShapes) {
49     InputController controller({notEmptyData, notEmptyData}, TEST_NAME);
50     controller.setShapeByName(inDims, TEST_NAME);
51     controller.getShapes(false);
52 }
53
54 TEST_F(InputControllerTest, canGetChanges) {
55     InputController controller({notEmptyData}, TEST_NAME);
56     controller.setShapeByName(inDims, TEST_NAME);
57     ASSERT_NO_THROW(controller.getShapes(true));
58 }
59
60 TEST_F(InputControllerTest, DISABLED_throwOnApplyWithNotEnoughShapes) {
61     InputController controller({notEmptyData, notEmptyData}, TEST_NAME);
62     controller.setShapeByName(inDims, TEST_NAME);
63     ASSERT_THROW(controller.applyChanges(), InferenceEngineException);
64 }
65
66 TEST_F(InputControllerTest, canApplyChanges) {
67     InputController controller({notEmptyData}, TEST_NAME);
68     controller.setShapeByName(inDims, TEST_NAME);
69     ASSERT_NO_THROW(controller.applyChanges());
70 }
71
72 TEST_F(InputControllerTest, canResetShapes) {
73     InputController controller({notEmptyData}, TEST_NAME);
74     controller.setShapeByName(inDims, TEST_NAME);
75     ASSERT_EQ(controller.getShapes(true)[0], inDims);
76     ASSERT_NO_THROW(controller.reset());
77     ASSERT_NE(controller.getShapes(true)[0], inDims);
78 }