Skip to content

Commit ede29b0

Browse files
committed
refs #9, additional checks for generic_string()
1 parent d780c18 commit ede29b0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/filesystem_test.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
//---------------------------------------------------------------------------------------
3232
#include <algorithm>
3333
#include <cstdio>
34+
#include <cstring>
3435
#include <fstream>
3536
#include <functional>
3637
#include <iostream>
38+
#include <iomanip>
3739
#include <random>
40+
#include <sstream>
3841
#include <thread>
3942
#ifndef WIN32
4043
#include <sys/socket.h>
@@ -197,6 +200,41 @@ static bool has_host_root_name_support()
197200
return fs::path("//host").has_root_name();
198201
}
199202

203+
204+
template <class T>
205+
class TestAllocator
206+
{
207+
public:
208+
using value_type = T;
209+
210+
TestAllocator() noexcept {}
211+
template <class U> TestAllocator(TestAllocator<U> const&) noexcept {}
212+
213+
value_type* allocate(std::size_t n)
214+
{
215+
return static_cast<value_type*>(::operator new (n*sizeof(value_type)));
216+
}
217+
218+
void deallocate(value_type* p, std::size_t) noexcept
219+
{
220+
::operator delete(p);
221+
}
222+
};
223+
224+
template <class T, class U>
225+
bool operator==(TestAllocator<T> const&, TestAllocator<U> const&) noexcept
226+
{
227+
return true;
228+
}
229+
230+
template <class T, class U>
231+
bool operator!=(TestAllocator<T> const& x, TestAllocator<U> const& y) noexcept
232+
{
233+
return !(x == y);
234+
}
235+
236+
237+
200238
TEST_CASE("Temporary Directory", "[temp dir]")
201239
{
202240
fs::path tempPath;
@@ -424,12 +462,16 @@ TEST_CASE("30.10.8.4.7 path generic format observers", "[filesystem][path][fs.pa
424462
{
425463
#ifdef GHC_OS_WINDOWS
426464
CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_string() == std::string("\xc3\xa4/\xe2\x82\xac"));
465+
auto t = fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_string<char, std::char_traits<char>, TestAllocator<char>>()
466+
CHECK(t.c_str() == std::string("\xc3\xa4/\xe2\x82\xac"));
427467
CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_wstring() == std::wstring(L"\U000000E4/\U000020AC"));
428468
CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u8string() == std::string("\xc3\xa4/\xe2\x82\xac"));
429469
CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u16string() == std::u16string(u"\u00E4/\u20AC"));
430470
CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u32string() == std::u32string(U"\U000000E4/\U000020AC"));
431471
#else
432472
CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_string() == std::string(u8"\xc3\xa4/\xe2\x82\xac"));
473+
auto t = fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_string<char, std::char_traits<char>, TestAllocator<char>>();
474+
CHECK(t.c_str() == std::string(u8"\xc3\xa4/\xe2\x82\xac"));
433475
CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_wstring() == std::wstring(L"ä/€"));
434476
CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u8string() == std::string(u8"\xc3\xa4/\xe2\x82\xac"));
435477
CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u16string() == std::u16string(u"\u00E4/\u20AC"));

0 commit comments

Comments
 (0)