summaryrefslogtreecommitdiff
path: root/test/test_common.hpp
blob: fd163640a48bffc288b2c351d2c89844cbb1011a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * libfud
 * Copyright 2024 Dominick Allen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FUD_TEST_COMMON_HPP
#define FUD_TEST_COMMON_HPP

#include "fud_status.hpp"

#include <cstddef>
#include <cstdlib>

extern "C" {
int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, struct FTW* ftwbuf);
}

namespace fud {

// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define MULTI_BYTE_LITERAL u8"test今日素敵はですねƩ®😀z"
static_assert(sizeof(MULTI_BYTE_LITERAL) == 38); // NOLINT(readability-magic-numbers)
#define TWO_BYTE u8"Ʃ"
static_assert(sizeof(TWO_BYTE) == 2 + 1);
#define THREE_BYTE u8"今"
static_assert(sizeof(THREE_BYTE) == 3 + 1);
#define FOUR_BYTE u8"😀"
static_assert(sizeof(FOUR_BYTE) == 4 + 1);

#define CHQUOTE u8"why waste time learning, when ignorance is instantaneous?"

#define LOWERCASE_CHARS u8"abcdefghijklmnopqrstuvwxyz"
#define UPPERCASE_CHARS u8"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define DECIMAL_CHARS u8"0123456789"
#define HEX_LOWER u8"abcdef"
#define HEX_UPPER u8"ABCDEF"
#define HEX_CHARS HEX_LOWER HEX_UPPER DECIMAL_CHARS
#define ALPHA_CHARS LOWERCASE_CHARS UPPERCASE_CHARS
#define ALPHA_NUMERIC_CHARS ALPHA_CHARS DECIMAL_CHARS
#define PUNCTUATION_CHARS u8"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
#define GRAPHICAL_CHARS ALPHA_NUMERIC_CHARS PUNCTUATION_CHARS
#define BLANK_CHARS u8" \t"
#define SPACE_CHARS BLANK_CHARS u8"\v\r\n"
#define PRINTABLE_CHARS u8" " LOWERCASE_CHARS UPPERCASE_CHARS DECIMAL_CHARS PUNCTUATION_CHARS
#define CHARACTER_SET LOWERCASE_CHARS u8" " UPPERCASE_CHARS

// NOLINTEND(cppcoreguidelines-macro-usage)
constexpr size_t charSetSize = sizeof(CHARACTER_SET) - 1;

struct MockFudAlloc {
    virtual void* operator()(size_t size);
};

extern MockFudAlloc globalDefaultMockAlloc;

struct MockFudDealloc {
    virtual void operator()(void* pointer);
};

extern MockFudDealloc globalDefaultMockDealloc;

struct MockFudAllocator {
    void* allocate(size_t size);
    void deallocate(void* pointer);

    MockFudAlloc* m_allocator{&globalDefaultMockAlloc};
    MockFudDealloc* m_deallocator{&globalDefaultMockDealloc};
};

extern MockFudAllocator globalMockFudAlloc;

class String;
FudStatus removeRecursive(const String& path);

} // namespace fud

#endif