GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestExceptions.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 20 20 100.0%
Branches: 28 84 33.3%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Exceptions.h>
5
6 #include <gtest/gtest.h>
7
8 10 class TestExceptions : public ::testing::Test
9 {
10 protected:
11 template<typename ExceptionT> void testException();
12 };
13
14
15 template<typename ExceptionT> struct ExceptionTraits
16 { static std::string name() { return ""; } };
17 template<> struct ExceptionTraits<openvdb::ArithmeticError>
18
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "ArithmeticError"; } };
19 template<> struct ExceptionTraits<openvdb::IndexError>
20
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "IndexError"; } };
21 template<> struct ExceptionTraits<openvdb::IoError>
22
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "IoError"; } };
23 template<> struct ExceptionTraits<openvdb::KeyError>
24
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "KeyError"; } };
25 template<> struct ExceptionTraits<openvdb::LookupError>
26
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "LookupError"; } };
27 template<> struct ExceptionTraits<openvdb::NotImplementedError>
28
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "NotImplementedError"; } };
29 template<> struct ExceptionTraits<openvdb::ReferenceError>
30
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "ReferenceError"; } };
31 template<> struct ExceptionTraits<openvdb::RuntimeError>
32
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "RuntimeError"; } };
33 template<> struct ExceptionTraits<openvdb::TypeError>
34
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "TypeError"; } };
35 template<> struct ExceptionTraits<openvdb::ValueError>
36
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { static std::string name() { return "ValueError"; } };
37
38
39 template<typename ExceptionT>
40 void
41 20 TestExceptions::testException()
42 {
43
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 std::string ErrorMsg("Error message");
44
45
3/20
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
100 EXPECT_THROW(OPENVDB_THROW(ExceptionT, ErrorMsg), ExceptionT);
46
47 try {
48
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
80 OPENVDB_THROW(ExceptionT, ErrorMsg);
49 40 } catch (openvdb::Exception& e) {
50
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
40 const std::string expectedMsg = ExceptionTraits<ExceptionT>::name() + ": " + ErrorMsg;
51
2/16
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
40 EXPECT_EQ(expectedMsg, std::string(e.what()));
52 }
53 20 }
54
55
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testArithmeticError) { testException<openvdb::ArithmeticError>(); }
56
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testIndexError) { testException<openvdb::IndexError>(); }
57
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testIoError) { testException<openvdb::IoError>(); }
58
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testKeyError) { testException<openvdb::KeyError>(); }
59
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testLookupError) { testException<openvdb::LookupError>(); }
60
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testNotImplementedError) { testException<openvdb::NotImplementedError>(); }
61
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testReferenceError) { testException<openvdb::ReferenceError>(); }
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testRuntimeError) { testException<openvdb::RuntimeError>(); }
63
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testTypeError) { testException<openvdb::TypeError>(); }
64
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestExceptions, testValueError) { testException<openvdb::ValueError>(); }
65