148TEST_CASE( 
"Getting timestamp string and broken-down time for a given time", 
"[libMagAOX::file::fileTimes]" )
 
  150    SECTION( 
"A time with 0 sec and 0 nsec" )
 
  152        time_t        ts_sec  = 1732170780;
 
  153        unsigned long ts_nsec = 0;
 
  160        REQUIRE( errc == mx::error_t::noerror );
 
  161        REQUIRE( tstamp == 
"20241121063300000000000" );
 
  162        REQUIRE( uttime.tm_year == 124 );
 
  163        REQUIRE( uttime.tm_mon == 10 );
 
  164        REQUIRE( uttime.tm_mday == 21 );
 
  165        REQUIRE( uttime.tm_hour == 6 );
 
  166        REQUIRE( uttime.tm_min == 33 );
 
  167        REQUIRE( uttime.tm_sec == 0 );
 
  170    SECTION( 
"A time with non-0 sec and 0 nsec" )
 
  172        time_t        ts_sec  = 1732170781;
 
  173        unsigned long ts_nsec = 0;
 
  180        REQUIRE( errc == mx::error_t::noerror );
 
  181        REQUIRE( tstamp == 
"20241121063301000000000" );
 
  182        REQUIRE( uttime.tm_year == 124 );
 
  183        REQUIRE( uttime.tm_mon == 10 );
 
  184        REQUIRE( uttime.tm_mday == 21 );
 
  185        REQUIRE( uttime.tm_hour == 6 );
 
  186        REQUIRE( uttime.tm_min == 33 );
 
  187        REQUIRE( uttime.tm_sec == 1 );
 
  190    SECTION( 
"A time with non-0 sec and 9-digit nsec" )
 
  192        time_t        ts_sec  = 1732170785;
 
  193        unsigned long ts_nsec = 434878292;
 
  200        REQUIRE( errc == mx::error_t::noerror );
 
  201        REQUIRE( tstamp == 
"20241121063305434878292" );
 
  202        REQUIRE( uttime.tm_year == 124 );
 
  203        REQUIRE( uttime.tm_mon == 10 );
 
  204        REQUIRE( uttime.tm_mday == 21 );
 
  205        REQUIRE( uttime.tm_hour == 6 );
 
  206        REQUIRE( uttime.tm_min == 33 );
 
  207        REQUIRE( uttime.tm_sec == 5 );
 
  210    SECTION( 
"A time with non-0 sec and 3-digit nsec" )
 
  212        time_t        ts_sec  = 1732170785;
 
  213        unsigned long ts_nsec = 292;
 
  220        REQUIRE( errc == mx::error_t::noerror );
 
  221        REQUIRE( tstamp == 
"20241121063305000000292" );
 
  222        REQUIRE( uttime.tm_year == 124 );
 
  223        REQUIRE( uttime.tm_mon == 10 );
 
  224        REQUIRE( uttime.tm_mday == 21 );
 
  225        REQUIRE( uttime.tm_hour == 6 );
 
  226        REQUIRE( uttime.tm_min == 33 );
 
  227        REQUIRE( uttime.tm_sec == 5 );
 
 
  696TEST_CASE( 
"Parsing filenames, paths and timestamps, with no errors", 
"[libMagAOX::file::fileTimes]" )
 
  698    SECTION( 
"A valid MagAO-X filename" )
 
  700        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  705        REQUIRE( errc == mx::error_t::noerror );
 
  706        REQUIRE( devName == 
"device" );
 
  707        REQUIRE( YYYY == 
"2024" );
 
  708        REQUIRE( MM == 
"11" );
 
  709        REQUIRE( DD == 
"21" );
 
  710        REQUIRE( hh == 
"06" );
 
  711        REQUIRE( mm == 
"33" );
 
  712        REQUIRE( ss == 
"00" );
 
  713        REQUIRE( nn == 
"000000000" );
 
  716    SECTION( 
"A valid MagAO-X filepath" )
 
  718        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  721            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
  723        REQUIRE( errc == mx::error_t::noerror );
 
  724        REQUIRE( devName == 
"device" );
 
  725        REQUIRE( YYYY == 
"2024" );
 
  726        REQUIRE( MM == 
"11" );
 
  727        REQUIRE( DD == 
"21" );
 
  728        REQUIRE( hh == 
"06" );
 
  729        REQUIRE( mm == 
"33" );
 
  730        REQUIRE( ss == 
"00" );
 
  731        REQUIRE( nn == 
"000000000" );
 
  734    SECTION( 
"A valid MagAO-X filename without extension" )
 
  736        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  741        REQUIRE( errc == mx::error_t::noerror );
 
  742        REQUIRE( devName == 
"device" );
 
  743        REQUIRE( YYYY == 
"2024" );
 
  744        REQUIRE( MM == 
"11" );
 
  745        REQUIRE( DD == 
"21" );
 
  746        REQUIRE( hh == 
"06" );
 
  747        REQUIRE( mm == 
"33" );
 
  748        REQUIRE( ss == 
"00" );
 
  749        REQUIRE( nn == 
"000000000" );
 
  752    SECTION( 
"A valid MagAO-X filepath without extension" )
 
  754        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  757            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000" );
 
  759        REQUIRE( errc == mx::error_t::noerror );
 
  760        REQUIRE( devName == 
"device" );
 
  761        REQUIRE( YYYY == 
"2024" );
 
  762        REQUIRE( MM == 
"11" );
 
  763        REQUIRE( DD == 
"21" );
 
  764        REQUIRE( hh == 
"06" );
 
  765        REQUIRE( mm == 
"33" );
 
  766        REQUIRE( ss == 
"00" );
 
  767        REQUIRE( nn == 
"000000000" );
 
  770    SECTION( 
"A valid MagAO-X filename without device, no _" )
 
  772        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  777        REQUIRE( errc == mx::error_t::noerror );
 
  778        REQUIRE( devName == 
"" );
 
  779        REQUIRE( YYYY == 
"2024" );
 
  780        REQUIRE( MM == 
"11" );
 
  781        REQUIRE( DD == 
"21" );
 
  782        REQUIRE( hh == 
"06" );
 
  783        REQUIRE( mm == 
"33" );
 
  784        REQUIRE( ss == 
"00" );
 
  785        REQUIRE( nn == 
"000000000" );
 
  788    SECTION( 
"A valid MagAO-X filepath without device, no _" )
 
  790        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  793            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/20241121063300000000000.txt" );
 
  795        REQUIRE( errc == mx::error_t::noerror );
 
  796        REQUIRE( devName == 
"" );
 
  797        REQUIRE( YYYY == 
"2024" );
 
  798        REQUIRE( MM == 
"11" );
 
  799        REQUIRE( DD == 
"21" );
 
  800        REQUIRE( hh == 
"06" );
 
  801        REQUIRE( mm == 
"33" );
 
  802        REQUIRE( ss == 
"00" );
 
  803        REQUIRE( nn == 
"000000000" );
 
  806    SECTION( 
"A valid MagAO-X filename without device or extension, no _" )
 
  808        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  813        REQUIRE( errc == mx::error_t::noerror );
 
  814        REQUIRE( devName == 
"" );
 
  815        REQUIRE( YYYY == 
"2024" );
 
  816        REQUIRE( MM == 
"11" );
 
  817        REQUIRE( DD == 
"21" );
 
  818        REQUIRE( hh == 
"06" );
 
  819        REQUIRE( mm == 
"33" );
 
  820        REQUIRE( ss == 
"00" );
 
  821        REQUIRE( nn == 
"000000000" );
 
  824    SECTION( 
"A valid MagAO-X filepath without device or extension, no _" )
 
  826        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  831        REQUIRE( errc == mx::error_t::noerror );
 
  832        REQUIRE( devName == 
"" );
 
  833        REQUIRE( YYYY == 
"2024" );
 
  834        REQUIRE( MM == 
"11" );
 
  835        REQUIRE( DD == 
"21" );
 
  836        REQUIRE( hh == 
"06" );
 
  837        REQUIRE( mm == 
"33" );
 
  838        REQUIRE( ss == 
"00" );
 
  839        REQUIRE( nn == 
"000000000" );
 
  842    SECTION( 
"A valid MagAO-X filename without device, with _" )
 
  844        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  849        REQUIRE( errc == mx::error_t::noerror );
 
  850        REQUIRE( devName == 
"" );
 
  851        REQUIRE( YYYY == 
"2024" );
 
  852        REQUIRE( MM == 
"11" );
 
  853        REQUIRE( DD == 
"21" );
 
  854        REQUIRE( hh == 
"06" );
 
  855        REQUIRE( mm == 
"33" );
 
  856        REQUIRE( ss == 
"00" );
 
  857        REQUIRE( nn == 
"000000000" );
 
  860    SECTION( 
"A valid MagAO-X filepath without device, with _" )
 
  862        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  865            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/_20241121063300000000000.txt" );
 
  867        REQUIRE( errc == mx::error_t::noerror );
 
  868        REQUIRE( devName == 
"" );
 
  869        REQUIRE( YYYY == 
"2024" );
 
  870        REQUIRE( MM == 
"11" );
 
  871        REQUIRE( DD == 
"21" );
 
  872        REQUIRE( hh == 
"06" );
 
  873        REQUIRE( mm == 
"33" );
 
  874        REQUIRE( ss == 
"00" );
 
  875        REQUIRE( nn == 
"000000000" );
 
  878    SECTION( 
"A valid MagAO-X filename without device or extension, with _" )
 
  880        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  885        REQUIRE( errc == mx::error_t::noerror );
 
  886        REQUIRE( devName == 
"" );
 
  887        REQUIRE( YYYY == 
"2024" );
 
  888        REQUIRE( MM == 
"11" );
 
  889        REQUIRE( DD == 
"21" );
 
  890        REQUIRE( hh == 
"06" );
 
  891        REQUIRE( mm == 
"33" );
 
  892        REQUIRE( ss == 
"00" );
 
  893        REQUIRE( nn == 
"000000000" );
 
  896    SECTION( 
"A valid MagAO-X filepath without device or extension, with _" )
 
  898        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  903        REQUIRE( errc == mx::error_t::noerror );
 
  904        REQUIRE( devName == 
"" );
 
  905        REQUIRE( YYYY == 
"2024" );
 
  906        REQUIRE( MM == 
"11" );
 
  907        REQUIRE( DD == 
"21" );
 
  908        REQUIRE( hh == 
"06" );
 
  909        REQUIRE( mm == 
"33" );
 
  910        REQUIRE( ss == 
"00" );
 
  911        REQUIRE( nn == 
"000000000" );
 
 
  919TEST_CASE( 
"Parsing filenames and paths with errors", 
"[libMagAOX::file::fileTimes]" )
 
  921    SECTION( 
"An invalid MagAO-X filepath with too short timestamp" )
 
  923        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  926            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_2024112106330000000000.txt" );
 
  928        REQUIRE( errc == mx::error_t::invalidarg );
 
  931    SECTION( 
"An invalid MagAO-X filepath with too long timestamp" )
 
  933        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  936            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_202411210633000000000001.txt" );
 
  937        REQUIRE( errc == mx::error_t::invalidarg );
 
  940    SECTION( 
"An valid MagAO-X filepath but bad_alloc is thrown in parseTimeStamp" )
 
  946            std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  948            MagAOX::file::XWCTEST_PARSETIMESTAMP_THROW_BAD_ALLOC_ns::parseFilePath(
 
  949                devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
  952                devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
  954        catch( 
const mx::exception<XWC_DEFAULT_VERBOSITY> & e )
 
  959        REQUIRE( caught == 
true );
 
  962    SECTION( 
"An valid MagAO-X filepath but out_of_range is thrown in parseTimeStamp" )
 
  964        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  966        mx::error_t errc = MagAOX::file::XWCTEST_PARSETIMESTAMP_THROW_OUT_OF_RANGE_ns::parseFilePath(
 
  967            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
  970            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
  972        REQUIRE( errc == mx::error_t::std_out_of_range );
 
  975    SECTION( 
"An valid MagAO-X filepath but exception is thrown in parseTimeStamp" )
 
  977        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  979        mx::error_t errc = MagAOX::file::XWCTEST_PARSETIMESTAMP_THROW_EXCEPTION_ns::parseFilePath(
 
  980            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
  983            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
  985        REQUIRE( errc == mx::error_t::std_exception );
 
  988    SECTION( 
"An valid MagAO-X filepath but bad_alloc is thrown in parseFilePath" )
 
  990        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
  995            MagAOX::file::XWCTEST_PARSEFILEPATH_THROW_BAD_ALLOC_ns::parseFilePath(
 
  996                devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
  999                devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
 1001        catch( 
const mx::exception<XWC_DEFAULT_VERBOSITY>  &e )
 
 1005        REQUIRE( caught == 
true );
 
 1008    SECTION( 
"An valid MagAO-X filepath but out_of_range is thrown in parseFilePAth" )
 
 1010        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
 1012        mx::error_t errc = MagAOX::file::XWCTEST_PARSEFILEPATH_THROW_OUT_OF_RANGE_ns::parseFilePath(
 
 1013            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
 1016            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
 1018        REQUIRE( errc == mx::error_t::std_out_of_range );
 
 1021    SECTION( 
"An valid MagAO-X filepath but exception is thrown in parseFilePAth" )
 
 1023        std::string devName, YYYY, MM, DD, hh, mm, ss, nn;
 
 1025        mx::error_t errc = MagAOX::file::XWCTEST_PARSEFILEPATH_THROW_EXCEPTION_ns::parseFilePath(
 
 1026            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" );
 
 1029            devName, YYYY, MM, DD, hh, mm, ss, nn, 
"/path/to/device_20241121063300000000000.txt" ));
 
 1031        REQUIRE( errc == mx::error_t::std_exception );