API
 
Loading...
Searching...
No Matches
stdSubDir_test.cpp
Go to the documentation of this file.
1/** \file stdSubDir_test.hpp
2 * \brief Tests for the stdSubDir class
3 * \ingroup file_files
4 */
5
6#include "../../../tests/testXWC.hpp"
7
8#include "../stdSubDir.hpp"
9
10#undef file_stdSubDir_hpp
11#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_CTORSYSDAYS_BAD_ALLOC_ns
12#define XWCTEST_STDSUBDIR_CTORSYSDAYS_BAD_ALLOC
13#include "../stdSubDir.hpp"
14#undef XWCTEST_NAMESPACE
15#undef XWCTEST_STDSUBDIR_CTORSYSDAYS_BAD_ALLOC
16
17#undef file_stdSubDir_hpp
18#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_CTORSYSDAYS_EXCEPTION_ns
19#define XWCTEST_STDSUBDIR_CTORSYSDAYS_EXCEPTION
20#include "../stdSubDir.hpp"
21#undef XWCTEST_NAMESPACE
22#undef XWCTEST_STDSUBDIR_CTORSYSDAYS_EXCEPTION
23
24#undef file_stdSubDir_hpp
25#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_YMD_BAD_ALLOC_ns
26#define XWCTEST_STDSUBDIR_YMD_BAD_ALLOC
27#include "../stdSubDir.hpp"
28#undef XWCTEST_NAMESPACE
29#undef XWCTEST_STDSUBDIR_YMD_BAD_ALLOC
30
31#undef file_stdSubDir_hpp
32#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_YMD_EXCEPTION_ns
33#define XWCTEST_STDSUBDIR_YMD_EXCEPTION
34#include "../stdSubDir.hpp"
35#undef XWCTEST_NAMESPACE
36#undef XWCTEST_STDSUBDIR_YMD_EXCEPTION
37
38#undef file_stdSubDir_hpp
39#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC_ns
40#define XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC
41#include "../stdSubDir.hpp"
42#undef XWCTEST_NAMESPACE
43#undef XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC
44
45#undef file_stdSubDir_hpp
46#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_SETPATH_OUT_OF_RANGE_ns
47#define XWCTEST_STDSUBDIR_SETPATH_OUT_OF_RANGE
48#include "../stdSubDir.hpp"
49#undef XWCTEST_NAMESPACE
50#undef XWCTEST_STDSUBDIR_SETPATH_OUT_OF_RANGE
51
52#undef file_stdSubDir_hpp
53#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_SETPATH_EXCEPTION_ns
54#define XWCTEST_STDSUBDIR_SETPATH_EXCEPTION
55#include "../stdSubDir.hpp"
56#undef XWCTEST_NAMESPACE
57#undef XWCTEST_STDSUBDIR_SETPATH_EXCEPTION
58
59#undef file_stdSubDir_hpp
60#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC2_ns
61#define XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC2
62#include "../stdSubDir.hpp"
63#undef XWCTEST_NAMESPACE
64#undef XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC2
65
66#undef file_stdSubDir_hpp
67#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_SETPATH_EXCEPTION2_ns
68#define XWCTEST_STDSUBDIR_SETPATH_EXCEPTION2
69#include "../stdSubDir.hpp"
70#undef XWCTEST_NAMESPACE
71#undef XWCTEST_STDSUBDIR_SETPATH_EXCEPTION2
72
73#undef file_stdSubDir_hpp
74#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_MAKEPATH_BAD_ALLOC_ns
75#define XWCTEST_STDSUBDIR_MAKEPATH_BAD_ALLOC
76#include "../stdSubDir.hpp"
77#undef XWCTEST_NAMESPACE
78#undef XWCTEST_STDSUBDIR_MAKEPATH_BAD_ALLOC
79
80#undef file_stdSubDir_hpp
81#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_MAKEPATH_FORMAT_ERROR_ns
82#define XWCTEST_STDSUBDIR_MAKEPATH_FORMAT_ERROR
83#include "../stdSubDir.hpp"
84#undef XWCTEST_NAMESPACE
85#undef XWCTEST_STDSUBDIR_MAKEPATH_FORMAT_ERROR
86
87#undef file_stdSubDir_hpp
88#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_MAKEPATH_EXCEPTION_ns
89#define XWCTEST_STDSUBDIR_MAKEPATH_EXCEPTION
90#include "../stdSubDir.hpp"
91#undef XWCTEST_NAMESPACE
92#undef XWCTEST_STDSUBDIR_MAKEPATH_EXCEPTION
93
94#undef file_stdSubDir_hpp
95#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC_ns
96#define XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC
97#include "../stdSubDir.hpp"
98#undef XWCTEST_NAMESPACE
99#undef XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC
100
101#undef file_stdSubDir_hpp
102#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_GYMD_EXCEPTION_ns
103#define XWCTEST_STDSUBDIR_GYMD_EXCEPTION
104#include "../stdSubDir.hpp"
105#undef XWCTEST_NAMESPACE
106#undef XWCTEST_STDSUBDIR_GYMD_EXCEPTION
107
108#undef file_stdSubDir_hpp
109#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_INC_BAD_ALLOC_ns
110#define XWCTEST_STDSUBDIR_INC_BAD_ALLOC
111#include "../stdSubDir.hpp"
112#undef XWCTEST_NAMESPACE
113#undef XWCTEST_STDSUBDIR_INC_BAD_ALLOC
114
115#undef file_stdSubDir_hpp
116#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_INC_EXCEPTION_ns
117#define XWCTEST_STDSUBDIR_INC_EXCEPTION
118#include "../stdSubDir.hpp"
119#undef XWCTEST_NAMESPACE
120#undef XWCTEST_STDSUBDIR_INC_EXCEPTION
121
122#undef file_stdSubDir_hpp
123#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_PREVFOLL_BAD_ALLOC_ns
124#define XWCTEST_STDSUBDIR_PREVFOLL_BAD_ALLOC
125#include "../stdSubDir.hpp"
126#undef XWCTEST_NAMESPACE
127#undef XWCTEST_STDSUBDIR_PREVFOLL_BAD_ALLOC
128
129#undef file_stdSubDir_hpp
130#define XWCTEST_NAMESPACE XWCTEST_STDSUBDIR_PREV_INVAL_ns
131#define XWCTEST_STDSUBDIR_PREV_INVAL
132#include "../stdSubDir.hpp"
133#undef XWCTEST_NAMESPACE
134#undef XWCTEST_STDSUBDIR_PREV_INVAL
135
136namespace libXWCTest
137{
138namespace fileTest
139{
140
141/** \defgroup stdSubDir_unit_test stdSubDir Unit Tests
142 * \ingroup file_unit_test
143 */
144
145/// Namespace for XWC::file::stdSubDir tests
146/** \ingroup stdSubDir_unit_test
147 *
148 */
149namespace stdSubDirTest
150{
151/// Initializing stdSubDir
152/**
153 * \ingroup stdSubDir_unit_test
154 */
155TEST_CASE( "Initializing stdSubDir", "[libMagAOX::file::stdSubDir]" )
156{
157 SECTION( "default construction" )
158 {
160 mx::error_t errc;
161
162 REQUIRE_FALSE( ssd.valid() );
163
164 std::string path = ssd.path();
165
166 REQUIRE( path == "" );
167
168 errc = mx::error_t::noerror;
169 path = ssd.path( &errc );
170
171 REQUIRE( errc == mx::error_t::invalidconfig );
172 REQUIRE( path == "" );
173
174 int year = ssd.year();
175
176 REQUIRE( year == std::numeric_limits<int>::max() );
177
178 errc = mx::error_t::noerror;
179 year = ssd.year( &errc );
180
181 REQUIRE( errc == mx::error_t::invalidconfig );
182 REQUIRE( year == std::numeric_limits<int>::max() );
183
184 unsigned int month = ssd.month();
185
186 REQUIRE( month == std::numeric_limits<unsigned int>::max() );
187
188 errc = mx::error_t::noerror;
189 month = ssd.month( &errc );
190
191 REQUIRE( errc == mx::error_t::invalidconfig );
192 REQUIRE( month == std::numeric_limits<unsigned int>::max() );
193
194 unsigned int day = ssd.day();
195 REQUIRE( day == std::numeric_limits<unsigned int>::max() );
196
197 errc = mx::error_t::noerror;
198 day = ssd.day( &errc );
199
200 REQUIRE( errc == mx::error_t::invalidconfig );
201 REQUIRE( day == std::numeric_limits<unsigned int>::max() );
202 }
203
204 SECTION( "default construction, then setting subdir" )
205 {
207
208 REQUIRE_FALSE( ssd.valid() );
209
210 ssd.path( "2024_11_21" );
211
212 REQUIRE( ssd.valid() );
213 REQUIRE( ssd.path() == "2024_11_21" );
214 REQUIRE( ssd.year() == 2024 );
215 REQUIRE( ssd.month() == 11 );
216 REQUIRE( ssd.day() == 21 );
217
218 mx::error_t errc = mx::error_t::error;
219 REQUIRE( ssd.year( &errc ) == 2024 );
220 REQUIRE( errc == mx::error_t::noerror );
221
222 errc = mx::error_t::error;
223 REQUIRE( ssd.month( &errc ) == 11 );
224 REQUIRE( errc == mx::error_t::noerror );
225
226 errc = mx::error_t::error;
227 REQUIRE( ssd.day( &errc ) == 21 );
228 REQUIRE( errc == mx::error_t::noerror );
229 }
230
231 SECTION( "construction by chrono::sys_days" )
232 {
233 std::chrono::year_month_day ymd{ std::chrono::year( 2024 ), std::chrono::month( 11 ), std::chrono::day( 21 ) };
234
235 std::chrono::sys_days sysday = ymd;
236
237 MagAOX::file::stdSubDir ssd( sysday );
238
239 REQUIRE( ssd.valid() );
240
241 REQUIRE( ssd.path() == "2024_11_21" );
242 REQUIRE( ssd.year() == 2024 );
243 REQUIRE( ssd.month() == 11 );
244 REQUIRE( ssd.day() == 21 );
245
246 mx::error_t errc = mx::error_t::error;
247 REQUIRE( ssd.year( &errc ) == 2024 );
248 REQUIRE( errc == mx::error_t::noerror );
249
250 errc = mx::error_t::error;
251 REQUIRE( ssd.month( &errc ) == 11 );
252 REQUIRE( errc == mx::error_t::noerror );
253
254 errc = mx::error_t::error;
255 REQUIRE( ssd.day( &errc ) == 21 );
256 REQUIRE( errc == mx::error_t::noerror );
257 }
258
259 SECTION( "construction by YMD" )
260 {
261 MagAOX::file::stdSubDir ssd( 2024, 11, 21 );
262
263 REQUIRE( ssd.valid() );
264
265 REQUIRE( ssd.path() == "2024_11_21" );
266 REQUIRE( ssd.year() == 2024 );
267 REQUIRE( ssd.month() == 11 );
268 REQUIRE( ssd.day() == 21 );
269
270 mx::error_t errc = mx::error_t::error;
271 REQUIRE( ssd.year( &errc ) == 2024 );
272 REQUIRE( errc == mx::error_t::noerror );
273
274 errc = mx::error_t::error;
275 REQUIRE( ssd.month( &errc ) == 11 );
276 REQUIRE( errc == mx::error_t::noerror );
277
278 errc = mx::error_t::error;
279 REQUIRE( ssd.day( &errc ) == 21 );
280 REQUIRE( errc == mx::error_t::noerror );
281 }
282
283 SECTION( "construction by path" )
284 {
285 MagAOX::file::stdSubDir ssd( "2024_11_21" );
286
287 REQUIRE( ssd.valid() );
288
289 REQUIRE( ssd.path() == "2024_11_21" );
290 REQUIRE( ssd.year() == 2024 );
291 REQUIRE( ssd.month() == 11 );
292 REQUIRE( ssd.day() == 21 );
293
294 mx::error_t errc = mx::error_t::error;
295 REQUIRE( ssd.year( &errc ) == 2024 );
296 REQUIRE( errc == mx::error_t::noerror );
297
298 errc = mx::error_t::error;
299 REQUIRE( ssd.month( &errc ) == 11 );
300 REQUIRE( errc == mx::error_t::noerror );
301
302 errc = mx::error_t::error;
303 REQUIRE( ssd.day( &errc ) == 21 );
304 REQUIRE( errc == mx::error_t::noerror );
305 }
306}
307
308/// Construction with errors
309/**
310 * \ingroup stdSubDir_unit_test
311 */
312TEST_CASE( "Construction with errors", "[libMagAOX::file::stdSubDir]" )
313{
314 SECTION( "Construction from sys_days causes bad_alloc" )
315 {
316 std::chrono::year_month_day ymd{ std::chrono::year( 2024 ), std::chrono::month( 11 ), std::chrono::day( 21 ) };
317
318 std::chrono::sys_days sysday = ymd;
319
320 bool caught = false;
321
322 try
323 {
324 MagAOX::file::XWCTEST_STDSUBDIR_CTORSYSDAYS_BAD_ALLOC_ns::stdSubDir<mx::verbose::vv> ssd( sysday );
326 }
327 catch( const MagAOX::xwcException &e )
328 {
329 static_cast<void>( e );
330 caught = true;
331 }
332
333 REQUIRE( caught == true );
334 }
335
336 SECTION( "Construction from sys_days causes exception" )
337 {
338 std::chrono::year_month_day ymd{ std::chrono::year( 2024 ), std::chrono::month( 11 ), std::chrono::day( 21 ) };
339
340 std::chrono::sys_days sysday = ymd;
341
342 MagAOX::file::XWCTEST_STDSUBDIR_CTORSYSDAYS_EXCEPTION_ns::stdSubDir<mx::verbose::vv> ssd( sysday );
343
345
346 REQUIRE_FALSE( ssd.valid() );
347 }
348
349 SECTION( "Construction from ymd causes bad_alloc" )
350 {
351 bool caught = false;
352
353 try
354 {
355 MagAOX::file::XWCTEST_STDSUBDIR_YMD_BAD_ALLOC_ns::stdSubDir<mx::verbose::vv> ssd( 2024, 11, 21 );
356 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 21 ) );
357 }
358 catch( const MagAOX::xwcException &e )
359 {
360 static_cast<void>( e );
361 caught = true;
362 }
363
364 REQUIRE( caught == true );
365 }
366
367 SECTION( "Construction from ymd causes exception" )
368 {
369 MagAOX::file::XWCTEST_STDSUBDIR_YMD_EXCEPTION_ns::stdSubDir<mx::verbose::vv> ssd( 2024, 11, 21 );
370 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 21 ) );
371
372 REQUIRE_FALSE( ssd.valid() );
373 }
374
375 SECTION( "Construction from path throws bad_alloc in stoT" )
376 {
377 bool caught = false;
378
379 try
380 {
381 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC_ns::stdSubDir<mx::verbose::vv> ssd( "2024_11_20" );
382 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( "2024_11_20" ) );
383 }
384 catch( const MagAOX::xwcException &e )
385 {
386 static_cast<void>( e );
387 caught = true;
388 }
389
390 REQUIRE( caught == true );
391 }
392
393 SECTION( "Constructing from path throws out_of_range in stoT" )
394 {
395 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_OUT_OF_RANGE_ns::stdSubDir<mx::verbose::vv> ssd( "2024_11_20" );
396 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( "2024_11_20" ) );
397
398 REQUIRE_FALSE( ssd.valid() );
399 }
400
401 SECTION( "Construction from path throws exception in stoT" )
402 {
403 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_EXCEPTION_ns::stdSubDir<mx::verbose::vv> ssd( "2024_11_20" );
404 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( "2024_11_20" ) );
405
406 REQUIRE_FALSE( ssd.valid() );
407 }
408
409 SECTION( "Construction from path throws bad_alloc setting ymd" )
410 {
411
412 bool caught = false;
413
414 try
415 {
416 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC2_ns::stdSubDir<mx::verbose::vv> ssd( "2024_11_20" );
417 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( "2024_11_20" ) );
418 }
419 catch( const MagAOX::xwcException &e )
420 {
421 static_cast<void>( e );
422 caught = true;
423 }
424
425 REQUIRE( caught == true );
426 }
427
428 SECTION( "Construction from path throws exception setting ymd" )
429 {
430 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_EXCEPTION2_ns::stdSubDir<mx::verbose::vv> ssd( "2024_11_20" );
431 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( "2024_11_20" ); ssd.valid() );
432
433 REQUIRE_FALSE( ssd.valid() );
434 }
435}
436
437/// Setting path with errors
438/**
439 * \ingroup stdSubDir_unit_test
440 */
441TEST_CASE( "Setting path with errors", "[libMagAOX::file::stdSubDir]" )
442{
443 SECTION( "Setting path from string giving errors" )
444 {
446
447 REQUIRE_FALSE( ssd.valid() );
448 mx::error_t errc;
449
450 errc = ssd.path( "2024_11_2" );
451 REQUIRE( errc == mx::error_t::invalidarg );
452 REQUIRE_FALSE( ssd.valid() );
453
454 errc = ssd.path( "2024x11_21" );
455 REQUIRE( errc == mx::error_t::invalidarg );
456 REQUIRE_FALSE( ssd.valid() );
457
458 errc = ssd.path( "2024_11x21" );
459 REQUIRE( errc == mx::error_t::invalidarg );
460 REQUIRE_FALSE( ssd.valid() );
461
462 errc = ssd.path( "Y024_11_24" );
463 REQUIRE( errc == mx::error_t::invalidarg );
464 REQUIRE_FALSE( ssd.valid() );
465
466 errc = ssd.path( "2Y24_11_24" );
467 REQUIRE( errc == mx::error_t::invalidarg );
468 REQUIRE_FALSE( ssd.valid() );
469
470 errc = ssd.path( "20Y4_11_24" );
471 REQUIRE( errc == mx::error_t::invalidarg );
472 REQUIRE_FALSE( ssd.valid() );
473
474 errc = ssd.path( "202Y_11_24" );
475 REQUIRE( errc == mx::error_t::invalidarg );
476 REQUIRE_FALSE( ssd.valid() );
477
478 errc = ssd.path( "2024_M1_24" );
479 REQUIRE( errc == mx::error_t::invalidarg );
480 REQUIRE_FALSE( ssd.valid() );
481
482 errc = ssd.path( "2024_2M_24" );
483 REQUIRE( errc == mx::error_t::invalidarg );
484 REQUIRE_FALSE( ssd.valid() );
485
486 errc = ssd.path( "2024_21_D4" );
487 REQUIRE( errc == mx::error_t::invalidarg );
488 REQUIRE_FALSE( ssd.valid() );
489
490 errc = ssd.path( "2024_21_2D" );
491 REQUIRE( errc == mx::error_t::invalidarg );
492 REQUIRE_FALSE( ssd.valid() );
493 }
494
495 SECTION( "Setting path throws bad_alloc in stoT" )
496 {
497 // This is slightly different than the construction test b/c we can test valid()
498 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC_ns::stdSubDir<mx::verbose::vv> ssd;
499 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd; ssd.valid(); ssd.path( "" ) );
500
501 REQUIRE_FALSE( ssd.valid() );
502
503 bool caught = false;
504
505 try
506 {
507 ssd.path( "2024_11_20" );
508 }
509 catch( const MagAOX::xwcException &e )
510 {
511 static_cast<void>( e );
512 caught = true;
513 }
514
515 REQUIRE( caught == true );
516 REQUIRE_FALSE( ssd.valid() );
517 }
518
519 SECTION( "Setting path throws out_of_range in stoT" )
520 {
521 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_OUT_OF_RANGE_ns::stdSubDir<mx::verbose::vv> ssd;
522 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd; ssd.valid(); ssd.path( "" ) );
523
524 REQUIRE_FALSE( ssd.valid() );
525
526 mx::error_t errc = ssd.path( "2024_11_20" );
527
528 REQUIRE( errc == mx::error_t::std_out_of_range );
529 REQUIRE_FALSE( ssd.valid() );
530 }
531
532 SECTION( "Setting path throws exception in stoT" )
533 {
534 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_EXCEPTION_ns::stdSubDir<mx::verbose::vv> ssd;
535 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd; ssd.valid(); ssd.path( "" ) );
536
537 REQUIRE_FALSE( ssd.valid() );
538
539 mx::error_t errc = ssd.path( "2024_11_20" );
540
541 REQUIRE( errc == mx::error_t::std_exception );
542 REQUIRE_FALSE( ssd.valid() );
543 }
544
545 SECTION( "Setting path throws bad_alloc setting ymd" )
546 {
547 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_BAD_ALLOC2_ns::stdSubDir<mx::verbose::vv> ssd;
548 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd; ssd.valid(); ssd.path( "" ); );
549
550 REQUIRE_FALSE( ssd.valid() );
551
552 bool caught = false;
553
554 try
555 {
556 ssd.path( "2024_11_20" );
557 }
558 catch( const MagAOX::xwcException &e )
559 {
560 static_cast<void>( e );
561 caught = true;
562 }
563
564 REQUIRE( caught == true );
565 REQUIRE_FALSE( ssd.valid() );
566 }
567
568 SECTION( "Setting path throws exception setting ymd" )
569 {
570 MagAOX::file::XWCTEST_STDSUBDIR_SETPATH_EXCEPTION2_ns::stdSubDir<mx::verbose::vv> ssd;
571 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd; ssd.valid(); ssd.path( "" ) );
572
573 REQUIRE_FALSE( ssd.valid() );
574
575 mx::error_t errc = ssd.path( "2024_11_20" );
576
577 REQUIRE( errc == mx::error_t::std_exception );
578 REQUIRE_FALSE( ssd.valid() );
579 }
580}
581
582/// Getting path with errors
583/**
584 * \ingroup stdSubDir_unit_test
585 */
586TEST_CASE( "Getting path with errors", "[libMagAOX::file::stdSubDir]" )
587{
588 SECTION( "Getting path throws bad_alloc making path" )
589 {
590 MagAOX::file::XWCTEST_STDSUBDIR_MAKEPATH_BAD_ALLOC_ns::stdSubDir<mx::verbose::vv> ssd( 2024, 11, 20 );
591 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.valid(); ssd.path() );
592
593 REQUIRE( ssd.valid() );
594
595 bool caught = false;
596
597 try
598 {
599 ssd.path();
600 }
601 catch( const MagAOX::xwcException &e )
602 {
603 static_cast<void>( e );
604 caught = true;
605 }
606
607 REQUIRE( caught == true );
608 }
609
610 SECTION( "Getting path throws format_error making path" )
611 {
612 MagAOX::file::XWCTEST_STDSUBDIR_MAKEPATH_FORMAT_ERROR_ns::stdSubDir<mx::verbose::vv> ssd( 2024, 11, 20 );
613 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.valid(); ssd.path() );
614
615 REQUIRE( ssd.valid() );
616
617 mx::error_t errc;
618 std::string p = ssd.path( &errc );
619
620 REQUIRE( errc == mx::error_t::std_format_error );
621 REQUIRE( p == "" );
622 }
623
624 SECTION( "Getting path throws exception making path" )
625 {
626 MagAOX::file::XWCTEST_STDSUBDIR_MAKEPATH_EXCEPTION_ns::stdSubDir<mx::verbose::vv> ssd( 2024, 11, 20 );
627 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.valid(); ssd.path() );
628
629 REQUIRE( ssd.valid() );
630
631 mx::error_t errc;
632 std::string p = ssd.path( &errc );
633
634 REQUIRE( errc == mx::error_t::std_exception );
635 REQUIRE( p == "" );
636 }
637}
638
639/// Setting from YMD
640/**
641 * \ingroup stdSubDir_unit_test
642 */
643TEST_CASE( "Setting from YMD", "[libMagAOX::file::stdSubDir]" )
644{
645 SECTION( "default construction, setting from Y/M/D" )
646 {
648
649 std::string p = ssd.path();
650 REQUIRE( p == "" );
651
652 ssd.ymd( 2024, 11, 21 );
653
654 REQUIRE( ssd.valid() );
655 REQUIRE( ssd.path() == "2024_11_21" );
656 REQUIRE( ssd.year() == 2024 );
657 REQUIRE( ssd.month() == 11 );
658 REQUIRE( ssd.day() == 21 );
659 }
660
661 SECTION( "construction from Y/M/D" )
662 {
663 MagAOX::file::stdSubDir ssd( 2024, 11, 21 );
664
665 REQUIRE( ssd.valid() );
666 REQUIRE( ssd.path() == "2024_11_21" );
667 REQUIRE( ssd.year() == 2024 );
668 REQUIRE( ssd.month() == 11 );
669 REQUIRE( ssd.day() == 21 );
670 }
671
672 SECTION( "construction from Y/M/D, single digit M and D" )
673 {
674 MagAOX::file::stdSubDir ssd( 2024, 1, 1 );
675
676 REQUIRE( ssd.valid() );
677 REQUIRE( ssd.path() == "2024_01_01" );
678 REQUIRE( ssd.year() == 2024 );
679 REQUIRE( ssd.month() == 1 );
680 REQUIRE( ssd.day() == 1 );
681 }
682
683 SECTION( "construction from YYYY_MM_DD" )
684 {
685 MagAOX::file::stdSubDir ssd( "2024_11_21" );
686
687 REQUIRE( ssd.valid() );
688 REQUIRE( ssd.path() == "2024_11_21" );
689 REQUIRE( ssd.year() == 2024 );
690 REQUIRE( ssd.month() == 11 );
691 REQUIRE( ssd.day() == 21 );
692 }
693
694 SECTION( "construction from YYYY_MM_DD, single digit M and D" )
695 {
696 MagAOX::file::stdSubDir ssd( "2024_01_01" );
697
698 REQUIRE( ssd.valid() );
699 REQUIRE( ssd.path() == "2024_01_01" );
700 REQUIRE( ssd.year() == 2024 );
701 REQUIRE( ssd.month() == 1 );
702 REQUIRE( ssd.day() == 1 );
703 }
704}
705
706/// Getting YMD with errors
707/** \ingroup stdSubDir_unit_test
708 */
709TEST_CASE( "Getting YMD with errors", "[libMagAOX::file::stdSubDir]" )
710{
711 SECTION( "Getting year while invalid" )
712 {
714
715 mx::error_t errc;
716 int y = ssd.year( &errc );
717 REQUIRE( y == std::numeric_limits<int>::max() );
718 REQUIRE( errc == mx::error_t::invalidconfig );
719 }
720
721 SECTION( "Getting year causes bad_alloc" )
722 {
723 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
724 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.year() );
725
726 mx::error_t errc;
727 bool caught = false;
728 try
729 {
730 int y = ssd.year( &errc );
731 static_cast<void>( y );
732 }
733 catch( const MagAOX::xwcException &e )
734 {
735 caught = true;
736 }
737
738 REQUIRE( caught == true );
739 REQUIRE( errc == mx::error_t::std_bad_alloc );
740 }
741
742 SECTION( "Getting year causes exception" )
743 {
744 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
745 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.year() );
746
747 mx::error_t errc;
748 int y = ssd.year( &errc );
749 REQUIRE( y == std::numeric_limits<int>::max() );
750 REQUIRE( errc == mx::error_t::std_exception );
751 }
752
753 SECTION( "Getting month while invalid" )
754 {
756
757 mx::error_t errc;
758 unsigned int m = ssd.month( &errc );
759 REQUIRE( m == std::numeric_limits<unsigned int>::max() );
760 REQUIRE( errc == mx::error_t::invalidconfig );
761 }
762
763 SECTION( "Getting month causes bad_alloc" )
764 {
765 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
766 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.month() );
767 mx::error_t errc;
768 bool caught = false;
769 try
770 {
771 unsigned int m = ssd.month( &errc );
772 static_cast<void>( m );
773 }
774 catch( const MagAOX::xwcException &e )
775 {
776 caught = true;
777 }
778
779 REQUIRE( caught == true );
780 REQUIRE( errc == mx::error_t::std_bad_alloc );
781 }
782
783 SECTION( "Getting month causes exception" )
784 {
785 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
786 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.month() );
787
788 mx::error_t errc;
789 unsigned int m = ssd.month( &errc );
790 REQUIRE( m == std::numeric_limits<unsigned int>::max() );
791 REQUIRE( errc == mx::error_t::std_exception );
792 }
793
794 SECTION( "Getting day while invalid" )
795 {
797
798 mx::error_t errc;
799 unsigned int d = ssd.day( &errc );
800 REQUIRE( d == std::numeric_limits<unsigned int>::max() );
801 REQUIRE( errc == mx::error_t::invalidconfig );
802 }
803
804 SECTION( "Getting day causes bad_alloc" )
805 {
806 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
807 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.day() );
808
809 mx::error_t errc;
810 bool caught = false;
811 try
812 {
813 unsigned int d = ssd.day( &errc );
814 static_cast<void>( d );
815 }
816 catch( const MagAOX::xwcException &e )
817 {
818 caught = true;
819 }
820
821 REQUIRE( caught == true );
822 REQUIRE( errc == mx::error_t::std_bad_alloc );
823 }
824
825 SECTION( "Getting day causes exception" )
826 {
827 MagAOX::file::XWCTEST_STDSUBDIR_GYMD_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
828 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.day() );
829
830 mx::error_t errc;
831 unsigned int d = ssd.day( &errc );
832 REQUIRE( d == std::numeric_limits<unsigned int>::max() );
833 REQUIRE( errc == mx::error_t::std_exception );
834 }
835}
836
837/// Incrementing and decrementing stdSubDirs
838/** \ingroup stdSubDir_unit_test
839 */
840TEST_CASE( "Incrementing and decrementing stdSubDirs", "[libMagAOX::file::stdSubDir]" )
841{
842 SECTION( "decrementing subdir by days" )
843 {
844 MagAOX::file::stdSubDir ssd( "2024_11_21" );
845
846 REQUIRE( ssd.valid() );
847
848 ssd.subDay();
849
850 REQUIRE( ssd.valid() );
851 REQUIRE( ssd.path() == "2024_11_20" );
852 REQUIRE( ssd.year() == 2024 );
853 REQUIRE( ssd.month() == 11 );
854 REQUIRE( ssd.day() == 20 );
855
856 ssd.subDay();
857
858 REQUIRE( ssd.valid() );
859 REQUIRE( ssd.path() == "2024_11_19" );
860 REQUIRE( ssd.year() == 2024 );
861 REQUIRE( ssd.month() == 11 );
862 REQUIRE( ssd.day() == 19 );
863 }
864
865 SECTION( "incrementing subdir by days" )
866 {
867 MagAOX::file::stdSubDir ssd( "2024_11_21" );
868
869 REQUIRE( ssd.valid() );
870
871 ssd.addDay();
872
873 REQUIRE( ssd.valid() );
874 REQUIRE( ssd.path() == "2024_11_22" );
875 REQUIRE( ssd.year() == 2024 );
876 REQUIRE( ssd.month() == 11 );
877 REQUIRE( ssd.day() == 22 );
878
879 ssd.addDay();
880
881 REQUIRE( ssd.valid() );
882 REQUIRE( ssd.path() == "2024_11_23" );
883 REQUIRE( ssd.year() == 2024 );
884 REQUIRE( ssd.month() == 11 );
885 REQUIRE( ssd.day() == 23 );
886 }
887
888 SECTION( "incrementing then decrementing subdir by days" )
889 {
890 MagAOX::file::stdSubDir ssd( "2024_11_21" );
891
892 REQUIRE( ssd.valid() );
893
894 ssd.addDay();
895
896 REQUIRE( ssd.valid() );
897 REQUIRE( ssd.path() == "2024_11_22" );
898 REQUIRE( ssd.year() == 2024 );
899 REQUIRE( ssd.month() == 11 );
900 REQUIRE( ssd.day() == 22 );
901
902 ssd.subDay();
903
904 REQUIRE( ssd.valid() );
905 REQUIRE( ssd.path() == "2024_11_21" );
906 REQUIRE( ssd.year() == 2024 );
907 REQUIRE( ssd.month() == 11 );
908 REQUIRE( ssd.day() == 21 );
909 }
910}
911
912/// Incrementing and decrementing stdSubDirs with errors
913/** \ingroup stdSubDir_unit_test
914 */
915TEST_CASE( "Incrementing and decrementing stdSubDirs with errors", "[libMagAOX::file::stdSubDir]" )
916{
917 SECTION( "decrementing while invalid" )
918 {
920
921 mx::error_t errc = ssd.subDay();
922
923 REQUIRE_FALSE( ssd.valid() );
924 REQUIRE( errc == mx::error_t::invalidconfig );
925 }
926
927 SECTION( "decrementing causes bad_alloc" )
928 {
929 bool caught = false;
930
931 try
932 {
933 MagAOX::file::XWCTEST_STDSUBDIR_INC_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
934 ssd.subDay();
935
936 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.subDay() );
937 }
938 catch( const MagAOX::xwcException &e )
939 {
940 caught = true;
941 }
942
943 REQUIRE( caught == true );
944 }
945
946 SECTION( "decrementing causes exception" )
947 {
948 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
949
950 mx::error_t errc = ssd.subDay();
951
952 REQUIRE_FALSE( ssd.valid() );
953 REQUIRE( errc == mx::error_t::std_exception );
954
955 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.subDay() );
956 }
957
958 SECTION( "incrementing while invalid" )
959 {
961
962 mx::error_t errc = ssd.addDay();
963
964 REQUIRE_FALSE( ssd.valid() );
965 REQUIRE( errc == mx::error_t::invalidconfig );
966 }
967
968 SECTION( "incrementing causes bad_alloc" )
969 {
970 bool caught = false;
971
972 try
973 {
974 MagAOX::file::XWCTEST_STDSUBDIR_INC_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
975 ssd.addDay();
976 }
977 catch( const MagAOX::xwcException &e )
978 {
979 caught = true;
980 }
981
982 REQUIRE( caught == true );
983
984 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.addDay() );
985 }
986
987 SECTION( "incrementing causes exception" )
988 {
989 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
990
991 mx::error_t errc = ssd.addDay();
992
993 REQUIRE_FALSE( ssd.valid() );
994 REQUIRE( errc == mx::error_t::std_exception );
995
996 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.valid(); ssd.subDay() );
997 }
998}
999
1000/// Getting previous and following stdSubDirs
1001/**
1002 * \ingroup stdSubDir_unit_test
1003 */
1004TEST_CASE( "Getting previous and following stdSubDirs", "[libMagAOX::file::stdSubDir]" )
1005{
1006 SECTION( "getting previous subdir" )
1007 {
1008 MagAOX::file::stdSubDir ssd( "2024_11_21" );
1009
1010 REQUIRE( ssd.valid() );
1011
1013
1014 REQUIRE( (psd.valid() == true) );
1015 REQUIRE( psd.path() == "2024_11_20" );
1016 REQUIRE( psd.year() == 2024 );
1017 REQUIRE( psd.month() == 11 );
1018 REQUIRE( psd.day() == 20 );
1019 }
1020
1021 SECTION( "getting previous subdir, month changes" )
1022 {
1023 MagAOX::file::stdSubDir ssd( "2024_11_01" );
1024
1025 REQUIRE( ssd.valid() );
1026
1028
1029 REQUIRE( psd.valid() == true );
1030 REQUIRE( psd.path() == "2024_10_31" );
1031 REQUIRE( psd.year() == 2024 );
1032 REQUIRE( psd.month() == 10 );
1033 REQUIRE( psd.day() == 31 );
1034 }
1035
1036 SECTION( "getting previous subdir, month changes to feb, leap year" )
1037 {
1038 MagAOX::file::stdSubDir ssd( "2024_03_01" );
1039
1040 REQUIRE( ssd.valid() );
1041
1043
1044 REQUIRE( psd.valid() == true );
1045 REQUIRE( psd.path() == "2024_02_29" );
1046 REQUIRE( psd.year() == 2024 );
1047 REQUIRE( psd.month() == 02 );
1048 REQUIRE( psd.day() == 29 );
1049 }
1050
1051 SECTION( "getting previous subdir, month changes to feb, not a leap year" )
1052 {
1053 MagAOX::file::stdSubDir ssd( "2025_03_01" );
1054
1055 REQUIRE( ssd.valid() );
1056
1058
1059 REQUIRE( psd.valid() == true );
1060 REQUIRE( psd.path() == "2025_02_28" );
1061 REQUIRE( psd.year() == 2025 );
1062 REQUIRE( psd.month() == 02 );
1063 REQUIRE( psd.day() == 28 );
1064 }
1065
1066 SECTION( "getting previous subdir, year changes" )
1067 {
1068 MagAOX::file::stdSubDir ssd( "2024_01_01" );
1069
1070 REQUIRE( ssd.valid() );
1071
1073
1074 REQUIRE( psd.valid() == true );
1075 REQUIRE( psd.path() == "2023_12_31" );
1076 REQUIRE( psd.year() == 2023 );
1077 REQUIRE( psd.month() == 12 );
1078 REQUIRE( psd.day() == 31 );
1079 }
1080
1081 SECTION( "getting following subdir" )
1082 {
1083 MagAOX::file::stdSubDir ssd( "2024_11_21" );
1084
1085 REQUIRE( ssd.valid() );
1086
1088
1089 REQUIRE( psd.valid() == true );
1090 REQUIRE( psd.path() == "2024_11_22" );
1091 REQUIRE( psd.year() == 2024 );
1092 REQUIRE( psd.month() == 11 );
1093 REQUIRE( psd.day() == 22 );
1094 }
1095
1096 SECTION( "getting following subdir, month changes" )
1097 {
1098 MagAOX::file::stdSubDir ssd( "2024_11_30" );
1099
1100 REQUIRE( ssd.valid() );
1101
1103
1104 REQUIRE( psd.valid() == true );
1105 REQUIRE( psd.path() == "2024_12_01" );
1106 REQUIRE( psd.year() == 2024 );
1107 REQUIRE( psd.month() == 12 );
1108 REQUIRE( psd.day() == 1 );
1109 }
1110
1111 SECTION( "getting following subdir, month changes to March, leap year" )
1112 {
1113 MagAOX::file::stdSubDir ssd( "2024_02_29" );
1114
1115 REQUIRE( ssd.valid() );
1116
1118
1119 REQUIRE( psd.valid() == true );
1120 REQUIRE( psd.path() == "2024_03_01" );
1121 REQUIRE( psd.year() == 2024 );
1122 REQUIRE( psd.month() == 03 );
1123 REQUIRE( psd.day() == 1 );
1124 }
1125
1126 SECTION( "getting following subdir, month changes to March, not a leap year" )
1127 {
1128 MagAOX::file::stdSubDir ssd( "2025_02_28" );
1129
1130 REQUIRE( ssd.valid() );
1131
1133
1134 REQUIRE( psd.valid() == true );
1135 REQUIRE( psd.path() == "2025_03_01" );
1136 REQUIRE( psd.year() == 2025 );
1137 REQUIRE( psd.month() == 03 );
1138 REQUIRE( psd.day() == 1 );
1139 }
1140}
1141
1142/// Getting previous and following stdSubDirs with errors
1143/**
1144 * \ingroup stdSubDir_unit_test
1145 */
1146TEST_CASE( "Getting previous and following stdSubDirs with errors", "[libMagAOX::file::stdSubDir]" )
1147{
1148 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 );
1150 psd = ssd.followingSubdir();
1151 static_cast<void>( psd ) );
1152
1153 SECTION( "getting previous subdir while invalid" )
1154 {
1156
1157 REQUIRE_FALSE( ssd.valid() );
1158
1159 mx::error_t errc;
1160 MagAOX::file::stdSubDir psd = ssd.previousSubdir( &errc );
1161
1162 REQUIRE( psd.valid() == false );
1163 REQUIRE( errc == mx::error_t::invalidconfig );
1164 }
1165
1166 SECTION( "getting previous subdir error creating new subdir" )
1167 {
1168 MagAOX::file::XWCTEST_STDSUBDIR_PREV_INVAL_ns::stdSubDir ssd( 2024, 11, 20 );
1169
1170 REQUIRE( ssd.valid() );
1171
1172 mx::error_t errc;
1173
1174 MagAOX::file::XWCTEST_STDSUBDIR_PREV_INVAL_ns::stdSubDir psd = ssd.previousSubdir( &errc );
1175
1176 REQUIRE( psd.valid() == false );
1177 REQUIRE( errc == mx::error_t::error );
1178
1179 }
1180
1181 SECTION( "getting previous subdir causes bad_alloc in subDay" )
1182 {
1183 MagAOX::file::XWCTEST_STDSUBDIR_INC_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
1184
1185 REQUIRE( ssd.valid() );
1186
1187 bool caught = false;
1188
1189 try
1190 {
1191 mx::error_t errc;
1192 ssd.previousSubdir( &errc );
1193
1194 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.previousSubdir() );
1195 }
1196 catch( const MagAOX::xwcException &e )
1197 {
1198 caught = true;
1199 }
1200
1201 REQUIRE( caught == true );
1202 }
1203
1204 SECTION( "getting previous subdir causes bad_alloc" )
1205 {
1206 MagAOX::file::XWCTEST_STDSUBDIR_PREVFOLL_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
1207
1208 REQUIRE( ssd.valid() );
1209
1210 bool caught = false;
1211
1212 try
1213 {
1214 mx::error_t errc;
1215 ssd.previousSubdir( &errc );
1216
1217 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.previousSubdir() );
1218 }
1219 catch( const MagAOX::xwcException &e )
1220 {
1221 caught = true;
1222 }
1223
1224 REQUIRE( caught == true );
1225 }
1226
1227 SECTION( "getting previous subdir causes exception" )
1228 {
1229 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
1230
1231 REQUIRE( ssd.valid() );
1232
1233 mx::error_t errc;
1234
1235 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir pssd = ssd.previousSubdir( &errc );
1236
1237 REQUIRE_FALSE( pssd.valid() );
1238 REQUIRE( errc == mx::error_t::std_exception );
1239 }
1240
1241 SECTION( "getting following subdir while invalid" )
1242 {
1244
1245 REQUIRE_FALSE( ssd.valid() );
1246
1247 mx::error_t errc;
1248 MagAOX::file::stdSubDir psd = ssd.followingSubdir( &errc );
1249
1250 REQUIRE( psd.valid() == false );
1251 REQUIRE( errc == mx::error_t::invalidconfig );
1252 }
1253
1254 SECTION( "getting following subdir error creating new subdir" )
1255 {
1256 MagAOX::file::XWCTEST_STDSUBDIR_PREV_INVAL_ns::stdSubDir ssd( 2024, 11, 20 );
1257
1258 REQUIRE( ssd.valid() );
1259
1260 mx::error_t errc;
1261
1262 MagAOX::file::XWCTEST_STDSUBDIR_PREV_INVAL_ns::stdSubDir psd = ssd.followingSubdir( &errc );
1263
1264 REQUIRE( psd.valid() == false );
1265 REQUIRE( errc == mx::error_t::error );
1266
1267 }
1268
1269 SECTION( "getting following subdir causes bad_alloc in add day" )
1270 {
1271 MagAOX::file::XWCTEST_STDSUBDIR_INC_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
1272
1273 REQUIRE( ssd.valid() );
1274
1275 bool caught = false;
1276
1277 try
1278 {
1279 mx::error_t errc;
1280 ssd.followingSubdir( &errc );
1281 }
1282 catch( const MagAOX::xwcException &e )
1283 {
1284 caught = true;
1285 }
1286
1287 REQUIRE( caught == true );
1288
1289 }
1290
1291 SECTION( "getting following subdir causes bad_alloc" )
1292 {
1293 MagAOX::file::XWCTEST_STDSUBDIR_PREVFOLL_BAD_ALLOC_ns::stdSubDir ssd( 2024, 11, 20 );
1294
1295 REQUIRE( ssd.valid() );
1296
1297 bool caught = false;
1298
1299 try
1300 {
1301 mx::error_t errc;
1302 ssd.followingSubdir( &errc );
1303
1304 XWCTEST_DOXYGEN_REF( MagAOX::file::stdSubDir ssd( 2024, 11, 20 ); ssd.followingSubdir() );
1305 }
1306 catch( const MagAOX::xwcException &e )
1307 {
1308 caught = true;
1309 }
1310
1311 REQUIRE( caught == true );
1312 }
1313
1314 SECTION( "getting following subdir causes exception" )
1315 {
1316 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir ssd( 2024, 11, 20 );
1317
1318 REQUIRE( ssd.valid() );
1319
1320 mx::error_t errc;
1321
1322 MagAOX::file::XWCTEST_STDSUBDIR_INC_EXCEPTION_ns::stdSubDir pssd = ssd.followingSubdir( &errc );
1323
1324 REQUIRE_FALSE( pssd.valid() );
1325 REQUIRE( errc == mx::error_t::std_exception );
1326
1327 }
1328}
1329
1330/// Using comparison operators
1331/**
1332 * \ingroup stdSubDir_unit_test
1333 */
1334TEST_CASE( "Using comparison operators", "[libMagAOX::file::stdSubDir]" )
1335{
1336 SECTION( "testing equality while equal" )
1337 {
1338 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1339 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1340
1341 REQUIRE( ssd1 == ssd2 );
1342 }
1343
1344 SECTION( "testing equality while not equal" )
1345 {
1346 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1347 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1348
1349 REQUIRE_FALSE( ( ssd1 == ssd2 ) );
1350 }
1351
1352 SECTION( "testing inequality while equal" )
1353 {
1354 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1355 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1356
1357 REQUIRE_FALSE( ( ssd1 != ssd2 ) );
1358 }
1359
1360 SECTION( "testing inequality while not equal" )
1361 {
1362 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1363 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1364
1365 REQUIRE( ssd1 != ssd2 );
1366 }
1367
1368 SECTION( "testing less-than while equal" )
1369 {
1370 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1371 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1372
1373 REQUIRE_FALSE( ( ssd1 < ssd2 ) );
1374 }
1375
1376 SECTION( "testing less-than while less-than" )
1377 {
1378 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1379 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1380
1381 REQUIRE( ssd1 < ssd2 );
1382 }
1383
1384 SECTION( "testing less-than while greater-than" )
1385 {
1386 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1387 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1388
1389 REQUIRE_FALSE( ( ssd2 < ssd2 ) );
1390 }
1391
1392 SECTION( "testing less-than-or-equal while equal" )
1393 {
1394 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1395 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1396
1397 REQUIRE( ( ssd1 <= ssd2 ) );
1398 }
1399
1400 SECTION( "testing less-than-or-equal while less-than" )
1401 {
1402 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1403 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1404
1405 REQUIRE( ssd1 <= ssd2 );
1406 }
1407
1408 SECTION( "testing less-than-or-equal while greater-than" )
1409 {
1410 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1411 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1412
1413 REQUIRE_FALSE( ( ssd2 <= ssd1 ) );
1414 }
1415
1416 SECTION( "testing greater-than while equal" )
1417 {
1418 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1419 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1420
1421 REQUIRE_FALSE( ( ssd1 > ssd2 ) );
1422 }
1423
1424 SECTION( "testing greater-than while greater-than" )
1425 {
1426 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1427 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1428
1429 REQUIRE( ssd2 > ssd1 );
1430 }
1431
1432 SECTION( "testing greater-than while less-than" )
1433 {
1434 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1435 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1436
1437 REQUIRE_FALSE( ( ssd1 > ssd2 ) );
1438 }
1439
1440 SECTION( "testing greater-than-or-equal while equal" )
1441 {
1442 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1443 MagAOX::file::stdSubDir ssd2( 2024, 11, 20 );
1444
1445 REQUIRE( ssd1 >= ssd2 );
1446 }
1447
1448 SECTION( "testing greater-than-or-equal while greater-than" )
1449 {
1450 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1451 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1452
1453 REQUIRE( ssd2 >= ssd1 );
1454 }
1455
1456 SECTION( "testing greater-than-or-equal while less-than" )
1457 {
1458 MagAOX::file::stdSubDir ssd1( 2024, 11, 20 );
1459 MagAOX::file::stdSubDir ssd2( 2024, 11, 21 );
1460
1461 REQUIRE_FALSE( ( ssd1 >= ssd2 ) );
1462 }
1463}
1464
1465} // namespace stdSubDirTest
1466} // namespace fileTest
1467} // namespace libXWCTest
Manage a standard subdirectory.
Definition stdSubDir.hpp:36
mx::error_t ymd(int year, unsigned month, unsigned day)
Setup from components.
unsigned int day(mx::error_t *errc=nullptr) const
Get the current value of m_day.
mx::error_t path(const std::string &subdir)
Set the subdirectory.
unsigned int month(mx::error_t *errc=nullptr) const
Get the current value of m_month.
stdSubDir followingSubdir(mx::error_t *errc=nullptr)
Get the following day's subdirectory.
bool valid() const
Get the current value of m_valid.
int year(mx::error_t *errc=nullptr) const
Get the current value of m_year.
mx::error_t subDay()
Subtract a day from this subdirectory.
stdSubDir previousSubdir(mx::error_t *errc=nullptr)
Get the previous day's subdirectory.
mx::error_t addDay()
Add a day to this subdirectory.
Augments an exception with the source file and line.
TEST_CASE("Initializing stdSubDir", "[libMagAOX::file::stdSubDir]")
Initializing stdSubDir.
#define XWCTEST_DOXYGEN_REF(fxn)
This inserts an unused call to a function signature to make doxygen make the link.
Definition testXWC.hpp:18
Namespace for all libXWC tests.
Definition MagAOXApp.hpp:49