Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qchar_generator.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#pragma once
5
6#include "../namespaces.h"
7#include "../utilities/semantics/move_into_vector.h"
8#include "combinators/oneof_generator.h"
9
10#include <catch/catch.hpp>
11
12#include <random>
13
14#include <QChar>
15
18
20 public:
22 char16_t lower_bound = std::numeric_limits<char16_t>::min(),
23 char16_t upper_bound = std::numeric_limits<char16_t>::max()
24 ) : random_engine{std::random_device{}()},
25 distribution{static_cast<unsigned int>(lower_bound), static_cast<unsigned int>(upper_bound)}
26 {
27 assert(lower_bound <= upper_bound);
28 static_cast<void>(next());
29 }
30
31 QChar const& get() const override { return current_character; }
32
33 bool next() override {
34 current_character = QChar(static_cast<char16_t>(distribution(random_engine)));
35
36 return true;
37 }
38
39 private:
40 QChar current_character;
41
42 std::mt19937 random_engine;
43 std::uniform_int_distribution<unsigned int> distribution;
44 };
45
46 } // end QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE
47
48
49 /*!
50 * Returns a generator of that generates elements of QChar whose
51 * ucs value is in the range [\a lower_bound, \a upper_bound].
52 *
53 * When \a lower_bound = \a upper_bound, the generator infinitely
54 * generates the same character.
55 */
56 inline Catch::Generators::GeneratorWrapper<QChar> character(char16_t lower_bound = std::numeric_limits<char16_t>::min(), char16_t upper_bound = std::numeric_limits<char16_t>::max()) {
57 return Catch::Generators::GeneratorWrapper<QChar>(std::unique_ptr<Catch::Generators::IGenerator<QChar>>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator(lower_bound, upper_bound)));
58 }
59
60
62
64
66
67 template<Alphabets alphabet>
68 struct sizeof_alphabet;
69
70 template<Alphabets alphabet>
72
73 template <> struct sizeof_alphabet<Alphabets::digit> { static constexpr std::size_t value{'9' - '0'}; };
74 template <> struct sizeof_alphabet<Alphabets::ascii_lowercase> { static constexpr std::size_t value{'z' - 'a'}; };
75 template<> struct sizeof_alphabet<Alphabets::ascii_uppercase> { static constexpr std::size_t value{'Z' - 'A'}; };
76 template<> struct sizeof_alphabet<Alphabets::ascii_alpha> { static constexpr std::size_t value{sizeof_alphabet_v<Alphabets::ascii_lowercase> + sizeof_alphabet_v<Alphabets::ascii_uppercase>}; };
77 template<> struct sizeof_alphabet<Alphabets::ascii_alphanumeric>{ static constexpr std::size_t value{sizeof_alphabet_v<Alphabets::ascii_alpha> + sizeof_alphabet_v<Alphabets::digit>}; };
78
79 } // end QDOC_CATCH_GENERATORS_TRAITS_NAMESPACE
80
81
83 return Catch::Generators::GeneratorWrapper<QChar>(std::unique_ptr<Catch::Generators::IGenerator<QChar>>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('0', '9')));
84 }
85
87 return Catch::Generators::GeneratorWrapper<QChar>(std::unique_ptr<Catch::Generators::IGenerator<QChar>>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('a', 'z')));
88 }
89
91 return Catch::Generators::GeneratorWrapper<QChar>(std::unique_ptr<Catch::Generators::IGenerator<QChar>>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('A', 'Z')));
92 }
93
95 return uniform_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_lowercase(), ascii_uppercase()));
96 }
97
99 return uniformly_valued_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_alpha(), digit()), std::vector{traits::sizeof_alphabet_v<traits::Alphabets::ascii_alpha> , traits::sizeof_alphabet_v<traits::Alphabets::digit>});
100 }
101
103 return uniformly_valued_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_alphanumeric(), character('.', '.'), character('-', '-'), character('_', '_')),
104 std::vector{traits::sizeof_alphabet_v<traits::Alphabets::ascii_alphanumeric>, std::size_t{1}, std::size_t{1}, std::size_t{1}});
105 }
106
107 } // end QDOC_CATCH_GENERATORS_QCHAR_ALPHABETS_NAMESPACE
108
109
110} // end QDOC_CATCH_GENERATORS_ROOT_NAMESPACE
QCharGenerator(char16_t lower_bound=std::numeric_limits< char16_t >::min(), char16_t upper_bound=std::numeric_limits< char16_t >::max())
Catch::Generators::GeneratorWrapper< QChar > character(char16_t lower_bound=std::numeric_limits< char16_t >::min(), char16_t upper_bound=std::numeric_limits< char16_t >::max())
Returns a generator of that generates elements of QChar whose ucs value is in the range [lower_bound,...
#define QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE
Definition namespaces.h:8
#define QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE
Definition namespaces.h:14
#define QDOC_CATCH_GENERATORS_QCHAR_ALPHABETS_NAMESPACE
Definition namespaces.h:12
#define QDOC_CATCH_GENERATORS_TRAITS_NAMESPACE
Definition namespaces.h:10
#define QDOC_CATCH_GENERATORS_ROOT_NAMESPACE
Definition namespaces.h:6
#define assert