• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devmarkusb / util / 23673278306

28 Mar 2026 12:31AM UTC coverage: 92.232% (-0.02%) from 92.249%
23673278306

push

github

MarkusB
Remove `std::codecvt`-based string conversion functions and tests.

5877 of 6372 relevant lines covered (92.23%)

136.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.06
/src/mem/allocator.test.cpp
1
#include "mb/ul/mem/allocator.hpp"
2
#include "mb/ul/mem/alloc/default.hpp"
3
#include "mb/ul/mem/alloc/example.hpp"
4
#include "mb/ul/mem/alloc/linear.hpp"
5
#include "mb/ul/mem/alloc/onstack.hpp"
6
#include "mb/ul/mem/compiler-quirks.hpp"
7
#include "mb/ul/mem/types.hpp"
8
#include "gtest/gtest.h"
9
#include <functional>
10
#include <iostream>
11
#include <map>
12
#include <new>
13
#include <string>
14
#include <utility>
15
#include <vector>
16

17
namespace ul = mb::ul;
18
using Bytes = ul::mem::Bytes;
19

20
namespace {
21
constexpr auto mem100k{100'000};
22
} // namespace
23

24
template <typename Vector>
25
void common_vector_test(Vector& v) {
4✔
26
    // NOLINTBEGIN
27
    v.reserve(mem100k);
4✔
28
    EXPECT_TRUE(v.empty());
4✔
29
    v.resize(50'000);
4✔
30
    EXPECT_EQ(v.size(), 50'000);
4✔
31
    v.resize(mem100k);
4✔
32
    EXPECT_EQ(v.size(), mem100k);
4✔
33
    v[50'001] = 42;
4✔
34
    EXPECT_EQ(v[50'001], 42);
4✔
35
    v.pop_back();
4✔
36
    EXPECT_EQ(v.size(), 99'999);
4✔
37
    v.clear();
4✔
38
    EXPECT_TRUE(v.empty());
4✔
39
    v.shrink_to_fit();
4✔
40
    // implementation dependent according to doc., so can't test anything
41
    //EXPECT_EQ(v.capacity(), 0);
42
    v.push_back(42);
4✔
43
    EXPECT_EQ(v.size(), 1);
4✔
44
    EXPECT_GE(v.capacity(), 1);
4✔
45
    for (int i = 1; i <= 999; ++i) {
4,000✔
46
        v.push_back(42);
3,996✔
47
    }
48
    // NOLINTEND
49
    std::cout << "capacity: " << v.capacity() << "\n";
4✔
50
    EXPECT_EQ(v.size(), 1'000);
4✔
51
}
4✔
52

53
template <typename Map>
54
void common_map_test(Map& m) {
4✔
55
    EXPECT_TRUE(m.empty());
4✔
56
    m[0] = "0";
4✔
57
    EXPECT_EQ(m.size(), 1);
4✔
58
    for (int i = 1; i <= 999; ++i) // NOLINT
4,000✔
59
    {
60
        m[i] = std::to_string(i);
3,996✔
61
    }
62
    EXPECT_EQ(m.size(), 1'000);
4✔
63
}
4✔
64

65
TEST(allocator_example, vector) {
4✔
66
    using Arena = ul::mem::alloc::Example;
67
    using Allocator = ul::mem::Allocator<int, Arena>;
68
    Arena a;
69
    const Allocator al{a};
1✔
70
    std::vector<int, Allocator> v{al};
1✔
71

72
    common_vector_test(v);
1✔
73
}
1✔
74

75
TEST(allocator_example, map) {
4✔
76
    using Arena = ul::mem::alloc::Example;
77
    using MapPair = std::pair<const int, std::string>;
78
    using Allocator = ul::mem::Allocator<MapPair, Arena>;
79
    Arena a;
80
    const Allocator al{a};
1✔
81
    std::map<int, std::string, std::less<>, Allocator> m{al};
1✔
82

83
    common_map_test(m);
1✔
84
}
1✔
85

86
TEST(allocator_default, vector) {
4✔
87
    using Arena = ul::mem::alloc::DefaultNewDelete<>;
88
    using Allocator = ul::mem::Allocator<int, Arena>;
89
    Arena a;
90
    const Allocator al{a};
1✔
91
    std::vector<int, Allocator> v{al};
1✔
92

93
    common_vector_test(v);
1✔
94
}
1✔
95

96
TEST(allocator_default, map) {
4✔
97
    using Arena = ul::mem::alloc::DefaultNewDelete<>;
98
    using MapPair = std::pair<const int, std::string>;
99
    using Allocator = ul::mem::Allocator<MapPair, Arena>;
100
    Arena a;
101
    const Allocator al{a};
1✔
102
    std::map<int, std::string, std::less<>, Allocator> m{al};
1✔
103

104
    common_map_test(m);
1✔
105
}
1✔
106

107
TEST(allocator_linear, vector) {
4✔
108
    using Arena = ul::mem::alloc::Linear<>;
109
    using Allocator = ul::mem::Allocator<int, Arena>;
110
    try {
111
        Arena a{
112
            Bytes{mem100k * sizeof(int) + ul::mem::quirk::vector::constr_heap_alloc_size.value}, Bytes{alignof(int)}
113
        };
1✔
114
        const Allocator al{a};
1✔
115
        std::vector<int, Allocator> v{al};
1✔
116

117
        common_vector_test(v);
1✔
118
    } catch (const std::bad_alloc&) {
1✔
119
        std::cout << "low mem, omitted test";
×
120
    }
×
121
}
1✔
122

123
TEST(allocator_linear, map) {
4✔
124
    using Arena = ul::mem::alloc::Linear<>;
125
    using MapPair = std::pair<const int, std::string>;
126
    using Allocator = ul::mem::Allocator<MapPair, Arena>;
127
    std::cout << "sizeof(MapPair): " << sizeof(MapPair) << ", alignof(MapPair): " << alignof(MapPair) << "\n";
1✔
128
    Arena a{Bytes{mem100k}, Bytes{alignof(MapPair)}};
1✔
129
    const Allocator al{a};
1✔
130
    std::map<int, std::string, std::less<>, Allocator> m{al};
1✔
131

132
    common_map_test(m);
1✔
133
}
1✔
134

135
TEST(allocator_onstack, vector) {
4✔
136
    using Arena = ul::mem::alloc::
137
        OnStack<mem100k * sizeof(int) + ul::mem::quirk::vector::constr_heap_alloc_size.value, alignof(int)>;
138
    using Allocator = ul::mem::Allocator<int, Arena>;
139
    try {
140
        Arena a;
1✔
141
        const Allocator al{a};
1✔
142
        std::vector<int, Allocator> v{al};
1✔
143

144
        common_vector_test(v);
1✔
145
    } catch (const std::bad_alloc&) {
1✔
146
        std::cout << "low mem, omitted test";
×
147
    }
×
148
}
1✔
149

150
TEST(allocator_onstack, map) {
4✔
151
    using MapPair = std::pair<const int, std::string>;
152
    using Arena = ul::mem::alloc::OnStack<mem100k, alignof(MapPair)>;
153
    using Allocator = ul::mem::Allocator<MapPair, Arena>;
154
    Arena a;
1✔
155
    const Allocator al{a};
1✔
156
    std::map<int, std::string, std::less<>, Allocator> m{al};
1✔
157

158
    common_map_test(m);
1✔
159
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc