IODA Bundle
errors.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <memory>
12 
13 #include "eckit/utils/StringTools.h"
14 #include "eckit/testing/Test.h"
15 
16 #include "odc/api/odc.h"
17 
18 using namespace eckit::testing;
19 
20 // Specialise custom deletion for odc_reader_t
21 
22 namespace std {
23 template <> struct default_delete<odc_reader_t> {
24  void operator() (const odc_reader_t* r) { EXPECT(ODC_SUCCESS == odc_close(r)); }
25 };
26 
27 template <> struct default_delete<odc_frame_t> {
28  void operator() (const odc_frame_t* t) { EXPECT(ODC_SUCCESS == odc_free_frame(t)); }
29 };
30 
31 }
32 
33 // ------------------------------------------------------------------------------------------------------
34 
35 CASE("By default we throw on error") {
36 //
37 // // Don't explicitly set handler. Test default in first case.
38 //
39 // EXPECT_THROWS_AS(odc_open_path("../does-not-exist.odb"), eckit::CantOpenFile);
40 // }
41 //
42 // CASE("Correctly open an odb file") {
43 //
44 // SetErrorHandling e(ODC_THROW);
45 //
46 // std::unique_ptr<odc_reader_t> o(odc_open_path("../2000010106.odb"));
47 //
48 // odc_frame_t* t = odc_alloc_next_frame(o.get());
49 // EXPECT(t != 0);
50 // EXPECT(odc_success());
51 // odc_free_frame(t);
52 // }
53 //
54 // CASE("We can report errors through the API") {
55 //
56 // SetErrorHandling e(ODC_ERRORS_REPORT);
57 //
58 // std::unique_ptr<odc_reader_t> o(odc_open_path("../does-not-exist.odb"));
59 //
60 // std::string expected = "Cannot open ../does-not-exist.odb"; // test start since strerror_r() message isn't portable
61 //
62 // EXPECT(!o);
63 // EXPECT(!odc_success());
64 // EXPECT(odc_error_string() != 0);
65 //
66 // EXPECT(eckit::StringTools::startsWith(odc_error_string(), expected));
67 //
68 // o.reset(odc_open_path("../does-not-exist.odb"));
69 //
70 // EXPECT(!o);
71 // EXPECT(!odc_success());
72 // EXPECT(odc_error_string() != 0);
73 // EXPECT(eckit::StringTools::startsWith(odc_error_string(), expected));
74 // }
75 //
76 // CASE("Don't continue unless error has been reset") {
77 //
78 // SetErrorHandling e(ODC_ERRORS_CHECKED);
79 //
80 // std::unique_ptr<odc_reader_t> o(odc_open_path("../does-not-exist.odb"));
81 //
82 // std::string expected = "Cannot open ../does-not-exist.odb"; // test start since strerror_r() message isn't portable
83 //
84 // EXPECT(!o);
85 // EXPECT(!odc_success());
86 // EXPECT(odc_error_string() != 0);
87 // EXPECT(eckit::StringTools::startsWith(odc_error_string(), expected));
88 //
89 // // Reset error condition (in principle handle it) then try again
90 // odc_reset_error();
91 //
92 // o.reset(odc_open_path("../does-not-exist.odb"));
93 //
94 // EXPECT(!o);
95 // EXPECT(!odc_success());
96 // EXPECT(odc_error_string() != 0);
97 // EXPECT(eckit::StringTools::startsWith(odc_error_string(), expected));
98 //
99 // // We haven't handled the previous error, so the API will barf
100 //
101 // EXPECT_THROWS_AS(odc_open_path("../does-not-exist.odb"), eckit::SeriousBug);
102 //
103 // // Reset error before cleanup
104 // odc_reset_error();
105 }
106 
107 
108 // ------------------------------------------------------------------------------------------------------
109 
110 int main(int argc, char* argv[]) {
111  return run_tests(argc, argv);
112 }
int odc_free_frame(const odc_frame_t *frame)
Definition: api/odc.cc:352
int odc_close(const odc_reader_t *reader)
Definition: api/odc.cc:332
int main(int argc, char *argv[])
Definition: errors.cc:110
CASE("By default we throw on error")
Definition: errors.cc:35
Definition: encode.cc:30
@ ODC_SUCCESS