Coverage Report

Created: 2026-02-14 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Common++/header/AssertionUtils.h
Line
Count
Source
1
#pragma once
2
3
/// @file
4
/// @brief This file contains internal assertion utilities used in PcapPlusPlus for debugging.
5
6
#ifndef PCPP_ASSERT_USE_C_ASSERT
7
# define PCPP_ASSERT_USE_C_ASSERT 0
8
#endif  // !PCPP_ASSERT_USE_C_ASSERT
9
10
#include <stdexcept>
11
#if PCPP_ASSERT_USE_C_ASSERT
12
# include <cassert>
13
#else
14
# include <string>
15
# include <sstream>
16
#endif  // PCPP_ASSERT_USE_C_ASSERT
17
18
namespace pcpp
19
{
20
  namespace internal
21
  {
22
    /// @brief A custom assertion error class derived from std::logic_error to be used with PCPP_ASSERT.
23
    class AssertionError : public std::logic_error
24
    {
25
    public:
26
      using std::logic_error::logic_error;
27
    };
28
  }  // namespace internal
29
}  // namespace pcpp
30
31
#ifndef NDEBUG
32
# if PCPP_ASSERT_USE_C_ASSERT
33
#   define PCPP_ASSERT(condition, message) assert((condition) && (message))
34
# else  // !PCPP_ASSERT_USE_C_ASSERT
35
#   define PCPP_ASSERT(condition, message)                                                                        \
36
      do                                                                                                         \
37
      {                                                                                                          \
38
        if (!(condition))                                                                                      \
39
        {                                                                                                      \
40
          std::stringstream ss;                                                                              \
41
          ss << "[PCPP] Assertion failed on [" << __FILE__ << ":" << __LINE__ << "] with: " << (message);    \
42
          throw pcpp::internal::AssertionError(ss.str());                                                    \
43
        }                                                                                                      \
44
      } while (false)
45
# endif  // PCPP_ASSERT_USE_C_ASSERT
46
#else
47
19.7k
# define PCPP_ASSERT(condition, message) (void)0;
48
#endif  // !NDEBUG