mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
error_t_test.cpp
Go to the documentation of this file.
1/** \file error_t_test.cpp
2 * \brief Tests error-code names, messages, and conversions.
3 */
4#include "../../catch2/catch.hpp"
5
7
8#define MXLIBTEST_ERROR_T_TESTS
9#include <error/error_t.hpp>
10
11namespace unitTest
12{
13namespace errorTest
14{
15namespace error_tTest
16{
17
18/// Test error_t code names
19/**
20 * \ingroup error_error_t_unit_tests
21 */
22TEST_CASE( "Test error_t code names", "[error::error_t]" )
23{
24 std::vector<mx::error_t> errcs;
25 mx::error_t_vector( errcs );
26
27 REQUIRE(errcs.size() > 0);
28
29 size_t fail = 0;
30 for(auto & errc : errcs)
31 {
32 std::string name = mx::errorName(errc);
33 if(name == "" || name == "unknown error_t (bug)")
34 {
35 ++fail;
36 }
37 }
38
39 REQUIRE(fail == 0);
40
41 int nv = static_cast<int>(*std::max_element(errcs.begin(), errcs.end()));
42
43 REQUIRE(nv != std::numeric_limits<int>::max()); //if this fails it means the following test is invalid
44
45 REQUIRE(mx::errorName(static_cast<mx::error_t>(std::numeric_limits<int>::max())) == "unknown error_t (bug)");
46
47
48}
49
50/// Test error_t messages
51/**
52 * \ingroup error_error_t_unit_tests
53 */
54TEST_CASE( "Test error_t messages", "[error::error_t]" )
55{
56 std::vector<mx::error_t> errcs;
57 mx::error_t_vector( errcs );
58
59 REQUIRE(errcs.size() > 0);
60
61 size_t fail = 0;
62 for(auto & errc : errcs)
63 {
64 std::string msg = mx::errorMessage(errc);
65 if(msg == "" || msg == "unknown error_t (bug)")
66 {
67 ++fail;
68 }
69 }
70
71 REQUIRE(fail == 0);
72
73 int nv = static_cast<int>(*std::max_element(errcs.begin(), errcs.end()));
74
75 REQUIRE(nv != std::numeric_limits<int>::max()); //if this fails it means the following test is invalid
76
77 REQUIRE(mx::errorMessage(static_cast<mx::error_t>(std::numeric_limits<int>::max())) == "unknown error_t (bug)");
78}
79
80/// Test errno conversions
81/**
82 * \ingroup error_error_t_unit_tests
83 */
84TEST_CASE( "Test errno conversions", "[error::error_t]" )
85{
86 std::vector<int> errnos;
87 mx::errno_vector( errnos );
88
89 REQUIRE(errnos.size() > 0);
90
91 size_t fail = 0;
92 for(auto & en : errnos)
93 {
95 if(errc == mx::error_t::error)
96 {
97 ++fail;
98 }
99 }
100
101 REQUIRE(fail == 0);
102
103 int nv = *std::max_element(errnos.begin(), errnos.end());
104
105 REQUIRE(nv != std::numeric_limits<int>::max()); //if this fails it means the following test is invalid
106
107 REQUIRE(mx::errno2error_t(std::numeric_limits<int>::max()) == mx::error_t::error);
108}
109
110/// Test FITS error conversions
111/**
112 * \ingroup error_error_t_unit_tests
113 */
114TEST_CASE( "Test FITS error conversions", "[error::error_t]" )
115{
116 std::vector<int> fitserrs;
117 mx::fitserr_vector( fitserrs );
118
119 REQUIRE(fitserrs.size() > 0);
120
121 size_t fail = 0;
122 for(auto & fe : fitserrs)
123 {
125 if(errc == mx::error_t::error)
126 {
127 ++fail;
128 }
129 }
130
131 REQUIRE(fail == 0);
132
133 int nv = *std::max_element(fitserrs.begin(), fitserrs.end());
134
135 REQUIRE(nv != std::numeric_limits<int>::max()); //if this fails it means the following test is invalid
136
137 REQUIRE(mx::fits_status2error_t(std::numeric_limits<int>::max()) == mx::error_t::error);
138}
139
140} // namespace error_tTest
141} // namespace errorTest
142} // namespace unitTest
The mxlib error reporting system.
The mxlib error_t type and utilities.
TEST_CASE("Test error_t code names", "[error::error_t]")
Test error_t code names.
error_t
The mxlib error codes.
Definition error_t.hpp:26
static constexpr const char * errorName(const error_t &errc)
Convert a error_t code to its name.
Definition error_t.hpp:434
static constexpr error_t errno2error_t(const int &err)
Convert an errno code to error_t.
Definition error_t.hpp:2056
static constexpr const char * errorMessage(const error_t &errc)
Get the descriptive message for a error_t code.
Definition error_t.hpp:1245
@ error
A general error has occurred.
Definition error_t.hpp:28
static constexpr error_t fits_status2error_t(const int &err)
Convert a FITS status code to error_t.
Definition error_t.hpp:2219