xref: /oneTBB/test/tbb/test_handle_perror.cpp (revision d86ed7fb)
1 /*
2     Copyright (c) 2005-2020 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 //! \file test_handle_perror.cpp
18 //! \brief Test for [internal] functionality
19 
20 #include "common/test.h"
21 #include "oneapi/tbb/detail/_exception.h"
22 #include "../../src/tbb/exception.cpp"
23 #include <stdexcept>
24 #include <cerrno>
25 #include <iostream>
26 
27 namespace tbb {
28 namespace detail {
29 namespace r1 {
30 bool terminate_on_exception() {
31     return false;
32 }
33 }
34 }
35 }
36 
37 #if TBB_USE_EXCEPTIONS
38 
39 //! \brief \ref error_guessing
40 TEST_CASE("test tbb::detail::r1::handle_perror") {
41     bool caught = false;
42 
43     try {
44         tbb::detail::r1::handle_perror(EAGAIN, "apple");
45     } catch( std::runtime_error& e ) {
46         REQUIRE(std::memcmp(e.what(), "apple: ", 7) == 0);
47         REQUIRE_MESSAGE(std::strlen(std::strstr(e.what(), std::strerror(EAGAIN))), "Bad error message");
48         caught = true;
49     }
50     REQUIRE(caught);
51 }
52 
53 #endif // TBB_USE_EXCEPTIONS
54