117TEST_CASE(
"Construction and Initializing stdFileName",
"[libMagAOX::file::stdFileName]" )
119 SECTION(
"default construction and parsing and member access" )
121 std::string fullName =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
127 REQUIRE( sfn.
fullName() == fullName );
128 REQUIRE( sfn.
baseName() ==
"bamm_20241121063321000000001.binlog" );
129 REQUIRE( sfn.
appName() ==
"bamm" );
131 REQUIRE( sfn.
subDir().path() ==
"2024_11_21" );
132 REQUIRE( sfn.
year() == 2024 );
133 REQUIRE( sfn.
month() == 11 );
134 REQUIRE( sfn.
day() == 21 );
135 REQUIRE( sfn.
hour() == 6 );
136 REQUIRE( sfn.
minute() == 33 );
137 REQUIRE( sfn.
second() == 21 );
138 REQUIRE( sfn.
nsec() == 1 );
142 REQUIRE( ts.
time_s == 1732170801 );
145 REQUIRE( sfn.
valid() );
148 SECTION(
"default construction, assignment and member access" )
150 std::string fullName =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
156 REQUIRE( sfn.
fullName() == fullName );
157 REQUIRE( sfn.
baseName() ==
"bamm_20241121063321000000001.binlog" );
158 REQUIRE( sfn.
appName() ==
"bamm" );
160 REQUIRE( sfn.
subDir().path() ==
"2024_11_21" );
161 REQUIRE( sfn.
year() == 2024 );
162 REQUIRE( sfn.
month() == 11 );
163 REQUIRE( sfn.
day() == 21 );
164 REQUIRE( sfn.
hour() == 6 );
165 REQUIRE( sfn.
minute() == 33 );
166 REQUIRE( sfn.
second() == 21 );
167 REQUIRE( sfn.
nsec() == 1 );
171 REQUIRE( ts.
time_s == 1732170801 );
174 REQUIRE( sfn.
valid() );
177 SECTION(
"construction by parsing and member access" )
179 std::string fullName =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
183 mx::error_t errc = mx::error_t::error;
184 REQUIRE( sfn.
fullName( &errc ) == fullName );
185 REQUIRE( errc == mx::error_t::noerror );
187 errc = mx::error_t::error;
188 REQUIRE( sfn.
baseName( &errc ) ==
"bamm_20241121063321000000001.binlog" );
189 REQUIRE( errc == mx::error_t::noerror );
191 errc = mx::error_t::error;
192 REQUIRE( sfn.
appName( &errc ) ==
"bamm" );
193 REQUIRE( errc == mx::error_t::noerror );
195 errc = mx::error_t::error;
196 REQUIRE( sfn.
extension( &errc ) ==
".binlog" );
197 REQUIRE( errc == mx::error_t::noerror );
199 errc = mx::error_t::error;
200 mx::error_t errc2 = mx::error_t::error;
201 REQUIRE( sfn.
subDir( &errc ).path( &errc2 ) ==
"2024_11_21" );
202 REQUIRE( errc == mx::error_t::noerror );
203 REQUIRE( errc2 == mx::error_t::noerror );
205 errc = mx::error_t::error;
206 REQUIRE( sfn.
year( &errc ) == 2024 );
207 REQUIRE( errc == mx::error_t::noerror );
209 errc = mx::error_t::error;
210 REQUIRE( sfn.
month( &errc ) == 11 );
211 REQUIRE( errc == mx::error_t::noerror );
213 errc = mx::error_t::error;
214 REQUIRE( sfn.
day( &errc ) == 21 );
215 REQUIRE( errc == mx::error_t::noerror );
217 errc = mx::error_t::error;
218 REQUIRE( sfn.
hour( &errc ) == 6 );
219 REQUIRE( errc == mx::error_t::noerror );
221 errc = mx::error_t::error;
222 REQUIRE( sfn.
minute( &errc ) == 33 );
223 REQUIRE( errc == mx::error_t::noerror );
225 errc = mx::error_t::error;
226 REQUIRE( sfn.
second( &errc ) == 21 );
227 REQUIRE( errc == mx::error_t::noerror );
229 errc = mx::error_t::error;
230 REQUIRE( sfn.
nsec( &errc ) == 1 );
231 REQUIRE( errc == mx::error_t::noerror );
233 errc = mx::error_t::error;
235 REQUIRE( ts.
time_s == 1732170801 );
237 REQUIRE( errc == mx::error_t::noerror );
239 REQUIRE( sfn.
valid() );
247TEST_CASE(
"Member Access Errors",
"[libMagAOX::file::stdFileName]" )
249 SECTION(
"default construction, access while invalid" )
253 mx::error_t errc = mx::error_t::noerror;
254 REQUIRE( sfn.
fullName( &errc ) ==
"" );
255 REQUIRE( errc == mx::error_t::invalidconfig );
257 errc = mx::error_t::noerror;
258 REQUIRE( sfn.
baseName( &errc ) ==
"" );
259 REQUIRE( errc == mx::error_t::invalidconfig );
261 errc = mx::error_t::noerror;
262 REQUIRE( sfn.
appName( &errc ) ==
"" );
263 REQUIRE( errc == mx::error_t::invalidconfig );
265 errc = mx::error_t::noerror;
267 REQUIRE( errc == mx::error_t::invalidconfig );
269 errc = mx::error_t::noerror;
270 mx::error_t errc2 = mx::error_t::noerror;
271 REQUIRE( sfn.
subDir( &errc ).path( &errc2 ) ==
"" );
272 REQUIRE( errc == mx::error_t::invalidconfig );
273 REQUIRE( errc2 == mx::error_t::invalidconfig );
275 errc = mx::error_t::noerror;
276 REQUIRE( sfn.
year( &errc ) == std::numeric_limits<int>::max() );
277 REQUIRE( errc == mx::error_t::invalidconfig );
279 errc = mx::error_t::noerror;
280 REQUIRE( sfn.
month( &errc ) == std::numeric_limits<unsigned int>::max() );
281 REQUIRE( errc == mx::error_t::invalidconfig );
283 errc = mx::error_t::noerror;
284 REQUIRE( sfn.
day( &errc ) == std::numeric_limits<unsigned int>::max() );
285 REQUIRE( errc == mx::error_t::invalidconfig );
287 errc = mx::error_t::noerror;
288 REQUIRE( sfn.
hour( &errc ) == std::numeric_limits<int>::max() );
289 REQUIRE( errc == mx::error_t::invalidconfig );
291 errc = mx::error_t::noerror;
292 REQUIRE( sfn.
minute( &errc ) == std::numeric_limits<int>::max() );
293 REQUIRE( errc == mx::error_t::invalidconfig );
295 errc = mx::error_t::noerror;
296 REQUIRE( sfn.
second( &errc ) == std::numeric_limits<int>::max() );
297 REQUIRE( errc == mx::error_t::invalidconfig );
299 errc = mx::error_t::noerror;
300 REQUIRE( sfn.
nsec( &errc ) == std::numeric_limits<int>::max() );
301 REQUIRE( errc == mx::error_t::invalidconfig );
303 errc = mx::error_t::noerror;
305 REQUIRE( ts.
time_s == 0 );
307 REQUIRE( errc == mx::error_t::invalidconfig );
309 REQUIRE( !sfn.
valid() );
316TEST_CASE(
"Setting fullName Errors",
"[libMagAOX::file::stdFileName]" )
318 SECTION(
"Construction with fullname throws bad_alloc" )
324 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_BAD_ALLOC_ns::stdFileName sfn(
325 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
328 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" ) );
335 REQUIRE( caught ==
true );
338 SECTION(
"Construction with fullname throws exception" )
341 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_EXCEPTION_ns::stdFileName sfn(
342 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
344 REQUIRE( !sfn.valid() );
351 SECTION(
"Default Construction, setting fullname throws exception" )
354 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_EXCEPTION_ns::stdFileName sfn;
356 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
358 REQUIRE( !sfn.valid() );
359 REQUIRE( errc == mx::error_t::std_exception );
362 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" ) );
365 SECTION(
"Construction with fullname throws bad_alloc from fs" )
371 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_BAD_ALLOC_ns::stdFileName sfn(
372 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
379 REQUIRE( caught ==
true );
385 SECTION(
"Construction with fullname throws filesystem_error from fs" )
388 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_FILESYSTEM_ERROR_ns::stdFileName sfn(
389 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
391 REQUIRE( !sfn.valid() );
398 SECTION(
"Construction with fullname throws exception from fs" )
401 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_EXCEPTION_ns::stdFileName sfn(
402 "/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
404 REQUIRE( !sfn.valid() );
411 SECTION(
"Default Construction, setting fullname throws filesystem_error from fs" )
414 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_FILESYSTEM_ERROR_ns::stdFileName sfn;
416 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
418 REQUIRE( !sfn.valid() );
419 REQUIRE( errc == mx::error_t::std_filesystem_error );
422 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
426 SECTION(
"Default Construction, setting fullname throws exception from fs" )
429 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_EXCEPTION_ns::stdFileName sfn;
431 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
433 REQUIRE( !sfn.valid() );
434 REQUIRE( errc == mx::error_t::std_exception );
437 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
441 SECTION(
"Default Construction, setting fullname without extension" )
446 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001" );
448 REQUIRE( !sfn.
valid() );
449 REQUIRE( errc == mx::error_t::invalidarg );
452 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001" );
456 SECTION(
"Default Construction, setting fullname throws exception from parseFilePath" )
459 MagAOX::file::XWCTEST_PARSEFILEPATH_THROW_BAD_ALLOC_ns::stdFileName sfn;
465 sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
467 catch(
const mx::exception<XWC_DEFAULT_VERBOSITY> &e )
471 REQUIRE( caught ==
true );
474 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" ) );
477 SECTION(
"Default Construction, setting fullname causes error from parseFilePath" )
480 MagAOX::file::XWCTEST_PARSEFILEPATH_THROW_OUT_OF_RANGE_ns::stdFileName sfn;
482 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
484 REQUIRE( !sfn.valid() );
485 REQUIRE( errc == mx::error_t::std_out_of_range );
488 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
492 SECTION(
"Default Construction, setting fullname error in year" )
497 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_X0241121063321000000001.binlog" );
499 REQUIRE( !sfn.
valid() );
500 REQUIRE( errc == mx::error_t::invalidarg );
503 SECTION(
"Default Construction, setting fullname error in month" )
508 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_2024X121063321000000001.binlog" );
510 REQUIRE( !sfn.
valid() );
511 REQUIRE( errc == mx::error_t::invalidarg );
514 SECTION(
"Default Construction, setting fullname error in day" )
519 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_202411X1063321000000001.binlog" );
521 REQUIRE( !sfn.
valid() );
522 REQUIRE( errc == mx::error_t::invalidarg );
525 SECTION(
"Default Construction, setting fullname error in day" )
530 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_202411X1063321000000001.binlog" );
532 REQUIRE( !sfn.
valid() );
533 REQUIRE( errc == mx::error_t::invalidarg );
536 SECTION(
"Default Construction, setting fullname error in hour" )
541 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121H63321000000001.binlog" );
543 REQUIRE( !sfn.
valid() );
544 REQUIRE( errc == mx::error_t::invalidarg );
547 SECTION(
"Default Construction, setting fullname error in minute" )
552 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_2024112106M321000000001.binlog" );
554 REQUIRE( !sfn.
valid() );
555 REQUIRE( errc == mx::error_t::invalidarg );
558 SECTION(
"Default Construction, setting fullname error in second" )
563 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_202411210633S1000000001.binlog" );
565 REQUIRE( !sfn.
valid() );
566 REQUIRE( errc == mx::error_t::invalidarg );
569 SECTION(
"Default Construction, setting fullname error in nanosecond" )
574 mx::error_t errc = sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321N00000001.binlog" );
576 REQUIRE( !sfn.
valid() );
577 REQUIRE( errc == mx::error_t::invalidarg );
580 SECTION(
"Default Construction, setting fullname throws exception from stdSubDir.ymd" )
582 MagAOX::file::XWCTEST_STDSUBDIR_YMD_BAD_ALLOC_ns::stdFileName sfn;
588 sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
594 REQUIRE( caught ==
true );
597 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" ); );
600 SECTION(
"Default Construction, setting fullname causes error from stdSubDir.ymd" )
603 MagAOX::file::XWCTEST_STDSUBDIR_YMD_EXCEPTION_ns::stdFileName sfn;
605 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
607 REQUIRE( !sfn.valid() );
608 REQUIRE( errc == mx::error_t::std_exception );
611 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
615 SECTION(
"Default Construction, setting fullname causes error with errno from timegm" )
618 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_TIMEGM_ns::stdFileName sfn;
620 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
622 REQUIRE( !sfn.valid() );
623 REQUIRE( errc == mx::error_t::eoverflow );
626 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
630 SECTION(
"Default Construction, setting fullname causes other error from timegm" )
632 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_TIMEGM_OTHER_ns::stdFileName sfn;
634 mx::error_t errc = sfn.fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
636 REQUIRE( !sfn.valid() );
637 REQUIRE( errc == mx::error_t::error );
640 sfn.
fullName(
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog" );
644 SECTION(
"Default Construction, setting fullname via = throws exception from fs" )
646 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_EXCEPTION_ns::stdFileName sfn;
648 sfn =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
650 REQUIRE( !sfn.valid() );
653 sfn =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
657 SECTION(
"Default Construction, setting fullname via = throws bad_alloc from fs" )
661 MagAOX::file::XWCTEST_STDFILENAME_FULLNAME_FS_BAD_ALLOC_ns::stdFileName sfn;
665 sfn =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";
672 REQUIRE( caught ==
true );
673 REQUIRE( !sfn.valid() );
676 sfn =
"/opt/MagAOX/stds/bamm/2024_11_21/bamm_20241121063321000000001.binlog";