8#include "../namespaces.h"
11#include "../utilities/semantics/move_into_vector.h"
12#include "../utilities/semantics/generator_handler.h"
14#if defined(Q_OS_WINDOWS)
16 #include "combinators/cycle_generator.h"
20#include <catch/catch.hpp>
27#include <QRegularExpression>
29#if defined(Q_OS_WINDOWS)
31 #include <QStorageInfo>
78
79
80
81
84
85
86
87
88
89
90
91
92
93
96
97
98
99
100
101
102
103
104
107
108
109
110
111
112
113
114
115
116
119
120
121
122
123
124
125
126
127
128
131
132
133
134
135
136
137
138
139
140
143
144
145
146
147
148
149
150
151
159 Catch::Generators::GeneratorWrapper<QString>&& device_component_generator,
160 Catch::Generators::GeneratorWrapper<QString>&& root_component_generator,
161 Catch::Generators::GeneratorWrapper<QString>&& directory_component_generator,
162 Catch::Generators::GeneratorWrapper<QString>&& filename_component_generator,
163 Catch::Generators::GeneratorWrapper<QString>&& separator_component_generator,
170 random_engine{
std::random_device{}()},
182 Catch::throw_exception(
"Not enough values to initialize the first string");
188 std::size_t components_amount{components_amount_distribution(random_engine)};
257 if (is_multi_device_distribution(random_engine)) {
258 if (!device_component_generator.next())
return false;
259 current_path += device_component_generator.get();
281 if (is_absolute_path_distribution(random_engine)) {
282 if (!root_component_generator.next())
return false;
284 current_path += root_component_generator.get();
287 std::size_t prefix_components_amount{
std::max(
std::size_t{1}, components_amount) - 1};
288 while (prefix_components_amount > 0) {
289 if (!directory_component_generator.next())
return false;
290 if (!separator_component_generator.next())
return false;
292 current_path += directory_component_generator.get() + separator_component_generator.get();
293 --prefix_components_amount;
296 if (is_directory_path_distribution(random_engine)) {
297 if (!directory_component_generator.next())
return false;
298 current_path += directory_component_generator.get();
300 if (has_trailing_separator(random_engine)) {
301 if (!separator_component_generator.next())
return false;
302 current_path += separator_component_generator.get();
305 if (!filename_component_generator.next())
return false;
306 current_path += filename_component_generator.get();
313 Catch::Generators::GeneratorWrapper<QString> device_component_generator;
314 Catch::Generators::GeneratorWrapper<QString> root_component_generator;
315 Catch::Generators::GeneratorWrapper<QString> directory_component_generator;
316 Catch::Generators::GeneratorWrapper<QString> filename_component_generator;
317 Catch::Generators::GeneratorWrapper<QString> separator_component_generator;
319 std::mt19937 random_engine;
320 std::uniform_int_distribution<
std::size_t> components_amount_distribution;
321 std::bernoulli_distribution is_multi_device_distribution;
322 std::bernoulli_distribution is_absolute_path_distribution;
323 std::bernoulli_distribution is_directory_path_distribution;
324 std::bernoulli_distribution has_trailing_separator;
326 QString current_path;
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
470 Catch::Generators::GeneratorWrapper<QString>&& device_generator,
471 Catch::Generators::GeneratorWrapper<QString>&& root_component_generator,
472 Catch::Generators::GeneratorWrapper<QString>&& directory_generator,
473 Catch::Generators::GeneratorWrapper<QString>&& filename_generator,
474 Catch::Generators::GeneratorWrapper<QString>&& separator_generator,
477 return Catch::Generators::GeneratorWrapper<QString>(
478 std::unique_ptr<Catch::Generators::IGenerator<QString>>(
479 new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::PathGenerator(std::move(device_generator), std::move(root_component_generator), std::move(directory_generator), std::move(filename_generator), std::move(separator_generator), configuration)
508
509
510
511
512
513
514
515
517 return uniformly_valued_oneof(
519 string(character(
'/',
'/'), 1, 1),
520 string(character(
'/',
'/'), 3, maximum_component_length)
522 std::vector{1, maximum_component_length - 3}
527
528
529
530
531
532
533
534
538 minimum_component_length, maximum_component_length
543
544
545
546
547
548
549
550
555 return filter([](
auto& filename) {
return filename !=
"." && filename !=
".."; }, portable_posix_directory_name());
559
560
561
562
563
564
565
567 return string(character(
'/',
'/'), minimum_component_length, maximum_component_length);
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
598#if defined(Q_OS_WINDOWS)
600 auto root_device{QStorageInfo{QDir()}.rootPath().first(1) +
":"};
602 return cycle(Catch::Generators::value(std::move(root_device)));
606 return Catch::Generators::map(
607 [](QString letter){
return letter +
':';},
615
616
617
618
619
620
621
622
623
625 return uniform_oneof(
627 string(character(
'\\',
'\\'), minimum_component_length, maximum_component_length),
628 string(character(
'/',
'/'), minimum_component_length, maximum_component_length)
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
657 string(character(), 0, 0),
662 PathGeneratorConfiguration{}
663 .set_multi_device_path_probability(0.0)
664 .set_absolute_path_probability(absolute_path_probability)
665 .set_directory_path_probability(directory_path_probability)
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
687 double absolute_path_probability = 0.5,
688 double directory_path_probability = 0.5,
689 double multi_device_path_probability = 0.5
704 Catch::Generators::filter(
705 [](
auto& path){
return !(path.endsWith(
".") && path.contains(QRegularExpression(
"[^.]"))) ; },
710 PathGeneratorConfiguration{}
711 .set_multi_device_path_probability(multi_device_path_probability)
712 .set_absolute_path_probability(absolute_path_probability)
713 .set_directory_path_probability(directory_path_probability)
728
729
730
731
732
733
734
735
736
737
738
740#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
742 return relaxed_portable_posix_path(absolute_path_probability, directory_path_probability);
744#elif defined(Q_OS_WINDOWS)
755 return traditional_dos_path(absolute_path_probability, directory_path_probability, 0.0);
761
762
763
764
765
766
767
768
769
811 return Catch::Generators::filter(
813 QStringList components{path.split(QRegularExpression{R"((\\|\/)+)"}, Qt::SkipEmptyParts)};
816 for (
auto& component : components) {
817 if (component ==
"..")
819 else if (component !=
".")
822 if (depth < 0)
return false;
827 native_path(0.0, directory_path_probability)
832
833
834
835
836
837
839 return native_relative_path(0.0);
843
844
845
846
847
848
850 return native_relative_path(1.0);
QString const & get() const override
PathGenerator(Catch::Generators::GeneratorWrapper< QString > &&device_component_generator, Catch::Generators::GeneratorWrapper< QString > &&root_component_generator, Catch::Generators::GeneratorWrapper< QString > &&directory_component_generator, Catch::Generators::GeneratorWrapper< QString > &&filename_component_generator, Catch::Generators::GeneratorWrapper< QString > &&separator_component_generator, PathGeneratorConfiguration configuration=PathGeneratorConfiguration{})
Catch::Generators::GeneratorWrapper< QString > posix_root()
Returns a generator that generates strings that are suitable to be used as a root component in POSIX ...
Catch::Generators::GeneratorWrapper< QString > windows_logical_drives()
Returns a generator that generates strings that can be suitably used as logical drive names in Window...
Catch::Generators::GeneratorWrapper< QString > windows_separator()
Returns a generator that generate strings that can be used as separators in Windows based paths.
Catch::Generators::GeneratorWrapper< QString > portable_posix_directory_name()
Returns a generator that generates strings that are suitable to be used as directory components in PO...
static constexpr std::size_t maximum_component_length
Catch::Generators::GeneratorWrapper< QString > portable_posix_filename()
Returns a generator that generates strings that are suitable to be used as filenames in POSIX paths a...
Catch::Generators::GeneratorWrapper< QString > posix_separator()
Returns a generator that generates strings that can be used as POSIX compliant separators.
static constexpr std::size_t minimum_component_length
Catch::Generators::GeneratorWrapper< QString > traditional_dos_path(double absolute_path_probability=0.5, double directory_path_probability=0.5, double multi_device_path_probability=0.5)
Returns a generator that produces strings that represents traditional DOS paths as defined in \l {htt...
Catch::Generators::GeneratorWrapper< QString > path(Catch::Generators::GeneratorWrapper< QString > &&device_generator, Catch::Generators::GeneratorWrapper< QString > &&root_component_generator, Catch::Generators::GeneratorWrapper< QString > &&directory_generator, Catch::Generators::GeneratorWrapper< QString > &&filename_generator, Catch::Generators::GeneratorWrapper< QString > &&separator_generator, PathGeneratorConfiguration configuration=PathGeneratorConfiguration{})
Returns a generator that produces QStrings that represent a path in a filesystem.
Catch::Generators::GeneratorWrapper< QString > native_relative_path(double directory_path_probability=0.5)
Returns a generator that generates QStrings that represents paths native to the underlying OS and tha...
Catch::Generators::GeneratorWrapper< QString > native_relative_file_path()
Returns a generator that generates QStrings that represents paths native to the underlying OS and tha...
Catch::Generators::GeneratorWrapper< QString > native_relative_directory_path()
Returns a generator that generates QStrings that represents paths native to the underlying OS and tha...
Catch::Generators::GeneratorWrapper< QString > native_path(double absolute_path_probability=0.5, double directory_path_probability=0.5)
Returns a generator that generates QStrings that represents paths native to the underlying OS.
Catch::Generators::GeneratorWrapper< QString > relaxed_portable_posix_path(double absolute_path_probability=0.5, double directory_path_probability=0.5)
Returns a generator that generates strings representing POSIX compatible paths.
#define QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE
#define QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE
#define QDOC_CATCH_GENERATORS_QCHAR_ALPHABETS_NAMESPACE
#define QDOC_CATCH_GENERATORS_ROOT_NAMESPACE
Defines some parameters to customize the generation of paths by a PathGenerator.
PathGeneratorConfiguration & set_absolute_path_probability(double amount)
std::size_t minimum_components_amount
double absolute_path_probability
PathGeneratorConfiguration & set_multi_device_path_probability(double amount)
PathGeneratorConfiguration & set_minimum_components_amount(std::size_t amount)
PathGeneratorConfiguration & set_directory_path_probability(double amount)
double multi_device_path_probability
PathGeneratorConfiguration & set_has_trailing_separator_probability(double amount)
double directory_path_probability
std::size_t maximum_components_amount
PathGeneratorConfiguration & set_maximum_components_amount(std::size_t amount)
double has_trailing_separator_probability