1 #define CATCH_CONFIG_RUNNER
2 #include <catch/catch.hpp>
3 
4 #include <segyio/segy.h>
5 
6 #include "test-config.hpp"
7 
apply(const char * path)8 std::string testcfg::apply( const char* path ) {
9     std::string p(path);
10 
11     if (p.find("test-data/Format") != std::string::npos) {
12         if (this->lsbit) return p + "lsb.sgy";
13         else             return p + "msb.sgy";
14     }
15 
16     if( !this->lsbit ) return path;
17 
18     if( p == "test-data/small.sgy" )
19         return "test-data/small-lsb.sgy";
20 
21     if( p == "test-data/f3.sgy" )
22         return "test-data/f3-lsb.sgy";
23 
24     return path;
25 }
26 
mmap(segy_file * fp)27 void testcfg::mmap( segy_file* fp ) {
28     if( this->memmap ) {
29     #ifdef HAVE_MMAP
30         REQUIRE( segy_mmap( fp ) == SEGY_OK );
31     #endif //HAVE_MMAP
32     }
33 }
34 
lsb(segy_file * fp)35 void testcfg::lsb( segy_file* fp ) {
36     if( this->lsbit ) {
37         REQUIRE( segy_set_format( fp, SEGY_LSB ) == SEGY_OK );
38     }
39 }
40 
apply(segy_file * fp)41 void testcfg::apply( segy_file* fp ) {
42     this->mmap( fp );
43     this->lsb( fp );
44 }
45 
config()46 testcfg& testcfg::config() {
47     static testcfg s;
48     return s;
49 }
50 
main(int argc,char ** argv)51 int main( int argc, char** argv ) {
52       Catch::Session session;
53 
54       auto& cfg = testcfg::config();
55 
56       using namespace Catch::clara;
57       auto cli = session.cli()
58           | Opt( cfg.memmap ) ["--test-mmap"] ("run with memory mapped files")
59           | Opt( cfg.lsbit )  ["--test-lsb"]  ("run with LSB files")
60           ;
61       session.cli( cli );
62 
63       const int errc = session.applyCommandLine( argc, argv );
64       if( errc )
65           return errc;
66 
67       return session.run();
68 }
69