diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index 8ade963b5f5d73..6de781d11e62ec 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -12,7 +12,7 @@ namespace InferenceEngine { #define EXEC_NET_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ + if (_impl == nullptr) IE_THROW(NotAllocated) << "ExecutableNetwork was not initialized."; \ try { \ __VA_ARGS__; \ } catch(...) {details::Rethrow();} @@ -27,10 +27,14 @@ IE_SUPPRESS_DEPRECATED_START ExecutableNetwork::ExecutableNetwork(IExecutableNetwork::Ptr exec, std::shared_ptr splg) - : _so(*splg), _impl(), actual(exec) { + : _so(), _impl(), actual(exec) { + if (splg) { + _so = *splg; + } + // plg can be null, but not the actual if (actual == nullptr) - IE_THROW() << "ExecutableNetwork was not initialized."; + IE_THROW(NotAllocated) << "ExecutableNetwork was not initialized."; } ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index 3e096f9820f79b..97fba9af7f924f 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -16,7 +16,7 @@ namespace InferenceEngine { #define INFER_REQ_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \ + if (_impl == nullptr) IE_THROW(NotAllocated) << "Inference Request is not initialized"; \ try { \ __VA_ARGS__ \ } catch(...) {details::Rethrow();} @@ -31,10 +31,14 @@ IE_SUPPRESS_DEPRECATED_START InferRequest::InferRequest(IInferRequest::Ptr request, std::shared_ptr splg) - : _so(*splg), _impl(), actual(request) { + : _so(), _impl(), actual(request) { + if (splg) { + _so = *splg; + } + // plg can be null, but not the actual if (actual == nullptr) - IE_THROW() << "InferRequest was not initialized."; + IE_THROW(NotAllocated) << "InferRequest was not initialized."; } void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) { diff --git a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp index 26e338739257ad..4f0866be7a04ad 100644 --- a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp @@ -9,7 +9,7 @@ #include "exception2status.hpp" #define VARIABLE_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \ + if (_impl == nullptr) IE_THROW(NotAllocated) << "VariableState was not initialized."; \ try { \ __VA_ARGS__; \ } catch(...) {details::Rethrow();} @@ -26,10 +26,14 @@ IE_SUPPRESS_DEPRECATED_START VariableState::VariableState(std::shared_ptr state, std::shared_ptr splg) - : _so(*splg), _impl(), actual(state) { + : _so(), _impl(), actual(state) { + if (splg) { + _so = *splg; + } + // plg can be null, but not the actual if (actual == nullptr) - IE_THROW() << "VariableState was not initialized."; + IE_THROW(NotAllocated) << "VariableState was not initialized."; } Blob::CPtr VariableState::GetLastState() const { diff --git a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp index 8e8a23176afb18..cc5cc1fe4eb826 100644 --- a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp +++ b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp @@ -5,84 +5,98 @@ #include #include +#include "unit_test_utils/mocks/mock_iinfer_request.hpp" using namespace ::testing; using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; +IE_SUPPRESS_DEPRECATED_START + +TEST(InferRequestCPPTests, throwsOnUninitialized) { + std::shared_ptr ptr; + ASSERT_THROW(InferRequest req(ptr), InferenceEngine::NotAllocated); +} + +TEST(InferRequestCPPTests, nothrowOnInitialized) { + std::shared_ptr ptr = std::make_shared(); + ASSERT_NO_THROW(InferRequest req(ptr)); +} + +IE_SUPPRESS_DEPRECATED_END TEST(InferRequestCPPTests, throwsOnUninitializedSetBlob) { InferRequest req; - ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::Exception); + ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedGetBlob) { InferRequest req; - ASSERT_THROW(req.GetBlob({}), InferenceEngine::Exception); + ASSERT_THROW(req.GetBlob({}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedSetBlobPreproc) { InferRequest req; - ASSERT_THROW(req.SetBlob({}, {}, {}), InferenceEngine::Exception); + ASSERT_THROW(req.SetBlob({}, {}, {}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedGetPreProcess) { InferRequest req; - ASSERT_THROW(req.GetPreProcess({}), InferenceEngine::Exception); + ASSERT_THROW(req.GetPreProcess({}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedInfer) { InferRequest req; - ASSERT_THROW(req.Infer(), InferenceEngine::Exception); + ASSERT_THROW(req.Infer(), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedGetPerformanceCounts) { InferRequest req; - ASSERT_THROW(req.GetPerformanceCounts(), InferenceEngine::Exception); + ASSERT_THROW(req.GetPerformanceCounts(), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedSetInput) { InferRequest req; - ASSERT_THROW(req.SetInput({{}}), InferenceEngine::Exception); + ASSERT_THROW(req.SetInput({{}}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedSetOutput) { InferRequest req; - ASSERT_THROW(req.SetOutput({{}}), InferenceEngine::Exception); + ASSERT_THROW(req.SetOutput({{}}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedSetBatch) { InferRequest req; - ASSERT_THROW(req.SetBatch({}), InferenceEngine::Exception); + ASSERT_THROW(req.SetBatch({}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedStartAsync) { InferRequest req; - ASSERT_THROW(req.StartAsync(), InferenceEngine::Exception); + ASSERT_THROW(req.StartAsync(), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedWait) { InferRequest req; - ASSERT_THROW(req.Wait({}), InferenceEngine::Exception); + ASSERT_THROW(req.Wait({}), InferenceEngine::NotAllocated); } TEST(InferRequestCPPTests, throwsOnUninitializedSetCompletionCallback) { InferRequest req; std::function f; - ASSERT_THROW(req.SetCompletionCallback(f), InferenceEngine::Exception); + ASSERT_THROW(req.SetCompletionCallback(f), InferenceEngine::NotAllocated); } IE_SUPPRESS_DEPRECATED_START TEST(InferRequestCPPTests, throwsOnUninitializedCast) { InferRequest req; - ASSERT_THROW((void)static_cast(req), InferenceEngine::Exception); + ASSERT_THROW((void)static_cast(req), InferenceEngine::NotAllocated); } IE_SUPPRESS_DEPRECATED_END TEST(InferRequestCPPTests, throwsOnUninitializedQueryState) { InferRequest req; - ASSERT_THROW(req.QueryState(), InferenceEngine::Exception); + ASSERT_THROW(req.QueryState(), InferenceEngine::NotAllocated); } diff --git a/inference-engine/tests/functional/inference_engine/executable_network.cpp b/inference-engine/tests/functional/inference_engine/executable_network.cpp index ea8af6c1d210a1..8db2bf40ed2402 100644 --- a/inference-engine/tests/functional/inference_engine/executable_network.cpp +++ b/inference-engine/tests/functional/inference_engine/executable_network.cpp @@ -4,12 +4,27 @@ #include #include +#include "unit_test_utils/mocks/mock_iexecutable_network.hpp" using namespace ::testing; using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; +IE_SUPPRESS_DEPRECATED_START + +TEST(ExecutableNetworkTests, throwsOnUninitialized) { + std::shared_ptr ptr; + ASSERT_THROW(ExecutableNetwork req(ptr), InferenceEngine::NotAllocated); +} + +TEST(ExecutableNetworkTests, nothrowOnInitialized) { + std::shared_ptr ptr = std::make_shared(); + ASSERT_NO_THROW(ExecutableNetwork req(ptr)); +} + +IE_SUPPRESS_DEPRECATED_END + TEST(ExecutableNetworkTests, throwsOnUninitializedGetOutputsInfo) { ExecutableNetwork exec; ASSERT_THROW(exec.GetOutputsInfo(), InferenceEngine::Exception); diff --git a/inference-engine/tests/functional/inference_engine/variable_state.cpp b/inference-engine/tests/functional/inference_engine/variable_state.cpp new file mode 100644 index 00000000000000..5073a155fca2e9 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/variable_state.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include "unit_test_utils/mocks/mock_ie_ivariable_state.hpp" + +using namespace ::testing; +using namespace std; +using namespace InferenceEngine; +using namespace InferenceEngine::details; + +IE_SUPPRESS_DEPRECATED_START + +TEST(VariableStateCPPTests, throwsOnUninitialized) { + std::shared_ptr ptr; + ASSERT_THROW(VariableState var(ptr), InferenceEngine::NotAllocated); +} + +TEST(VariableStateCPPTests, nothrowOnInitialized) { + std::shared_ptr ptr = std::make_shared(); + ASSERT_NO_THROW(VariableState var(ptr)); +} + +TEST(VariableStateCPPTests, throwsOnUninitializedGetLastState) { + VariableState req; + ASSERT_THROW(req.GetLastState(), InferenceEngine::NotAllocated); +} + +IE_SUPPRESS_DEPRECATED_END + +TEST(VariableStateCPPTests, throwsOnUninitializedReset) { + VariableState req; + ASSERT_THROW(req.Reset(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateCPPTests, throwsOnUninitializedGetname) { + VariableState req; + ASSERT_THROW(req.GetName(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateCPPTests, throwsOnUninitializedGetState) { + VariableState req; + ASSERT_THROW(req.GetState(), InferenceEngine::NotAllocated); +} + +TEST(VariableStateCPPTests, throwsOnUninitializedSetState) { + VariableState req; + Blob::Ptr blob; + ASSERT_THROW(req.SetState(blob), InferenceEngine::NotAllocated); +}