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