Line data Source code
1 : /*
2 : * File:
3 : * tests/main.h
4 : *
5 : * License:
6 : * Copyright (c) 2006-2019 Made to Order Software Corp. All Rights Reserved
7 : *
8 : * https://snapwebsites.org/
9 : * contact@m2osw.com
10 : *
11 : * This program is free software; you can redistribute it and/or modify
12 : * it under the terms of the GNU General Public License as published by
13 : * the Free Software Foundation; either version 2 of the License, or
14 : * (at your option) any later version.
15 : *
16 : * This program is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU General Public License for more details.
20 : *
21 : * You should have received a copy of the GNU General Public License along
22 : * with this program; if not, write to the Free Software Foundation, Inc.,
23 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 : *
25 : * Authors:
26 : * Alexis Wilke alexis@m2osw.com
27 : */
28 : #ifndef UNIT_TEST_MAIN_H
29 : #define UNIT_TEST_MAIN_H
30 :
31 : // catch2 lib
32 : //
33 : #include <catch2/snapcatch2.hpp>
34 :
35 : // C++ lib
36 : //
37 : #include <string>
38 : #include <cstring>
39 : #include <cstdlib>
40 : #include <iostream>
41 :
42 :
43 :
44 : namespace SNAP_CATCH2_NAMESPACE
45 : {
46 :
47 :
48 :
49 :
50 2098472 : inline char32_t rand_char(bool full_range = false)
51 : {
52 2098472 : char32_t const max((full_range ? 0x0110000 : 0x0010000) - (0xE000 - 0xD800));
53 :
54 : char32_t wc;
55 26 : do
56 : {
57 2098498 : wc = ((rand() << 16) ^ rand()) % max;
58 : }
59 2098498 : while(wc == 0);
60 2098472 : if(wc >= 0xD800)
61 : {
62 : // skip the surrogates
63 : //
64 274300 : wc += 0xE000 - 0xD800;
65 : }
66 :
67 2098472 : return wc;
68 : }
69 :
70 :
71 :
72 : }
73 : // unittest namespace
74 : #endif
75 : // vim: ts=4 sw=4 et
|