adjust unit test for rtstring
This commit is contained in:
parent
1fc3a4fe6c
commit
e2a77ba3c1
@ -262,74 +262,75 @@ TEST_CASE("bad my_allocator::construct")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
// namespace
|
||||||
{
|
// {
|
||||||
template <class T>
|
// template <class T>
|
||||||
struct NAlloc
|
// struct NAlloc
|
||||||
{
|
// {
|
||||||
// Aliases and inner types
|
// // Aliases and inner types
|
||||||
using value_type = T;
|
// using value_type = T;
|
||||||
using size_type = std::size_t;
|
// using size_type = std::size_t;
|
||||||
using difference_type = ptrdiff_t;
|
// using difference_type = ptrdiff_t;
|
||||||
using reference = value_type&;
|
// using reference = value_type&;
|
||||||
using const_reference = const value_type&;
|
// using const_reference = const value_type&;
|
||||||
using pointer = value_type*;
|
// using pointer = value_type*;
|
||||||
using const_pointer = const value_type*;
|
// using const_pointer = const value_type*;
|
||||||
|
|
||||||
template <typename U>
|
// template <typename U>
|
||||||
struct rebind
|
// struct rebind
|
||||||
{
|
// {
|
||||||
using other = NAlloc<U>;
|
// using other = NAlloc<U>;
|
||||||
};
|
// };
|
||||||
|
|
||||||
NAlloc() :
|
// NAlloc() :
|
||||||
alloc()
|
// alloc()
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
NAlloc(const NAlloc&) = default; // Copy constructor
|
// NAlloc(const NAlloc&) = default; // Copy constructor
|
||||||
NAlloc(NAlloc&&) = default; // Move constructor
|
// NAlloc(NAlloc&&) = default; // Move constructor
|
||||||
NAlloc& operator=(const NAlloc& other) = default; // Copy assignment operator
|
// NAlloc& operator=(const NAlloc& other) = default; // Copy assignment operator
|
||||||
NAlloc& operator=(NAlloc&&) = default; // Move assignment operator
|
// NAlloc& operator=(NAlloc&&) = default; // Move assignment operator
|
||||||
|
|
||||||
virtual ~NAlloc() = default;
|
// virtual ~NAlloc() = default;
|
||||||
|
|
||||||
pointer allocate(std::size_t n)
|
// pointer allocate(std::size_t n)
|
||||||
{
|
// {
|
||||||
|
|
||||||
return static_cast<pointer>(alloc.allocate(n)); // get memory from pool
|
// return static_cast<pointer>(alloc.allocate(n)); // get memory from pool
|
||||||
}
|
// }
|
||||||
void deallocate(pointer p, std::size_t n)
|
// void deallocate(pointer p, std::size_t n)
|
||||||
{
|
// {
|
||||||
m_alloc_size = n;
|
// m_alloc_size = n;
|
||||||
alloc.deallocate(static_cast<pointer>(p), 1); // return memory to pool
|
// alloc.deallocate(static_cast<pointer>(p), 1); // return memory to pool
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
bool operator!=(const NAlloc<T>& other) const
|
// bool operator!=(const NAlloc<T>& other) const
|
||||||
{
|
// {
|
||||||
return !(*this == other);
|
// return !(*this == other);
|
||||||
}
|
// }
|
||||||
bool operator==(const NAlloc<T>& other) const
|
// bool operator==(const NAlloc<T>& other) const
|
||||||
{
|
// {
|
||||||
return alloc == other.alloc;
|
// return alloc == other.alloc;
|
||||||
}
|
// }
|
||||||
|
|
||||||
my_allocator<char> alloc;
|
// my_allocator<char> alloc;
|
||||||
std::size_t m_alloc_size {};
|
// std::size_t m_alloc_size {};
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
|
||||||
using OstringStream = std::basic_ostringstream<char, std::char_traits<char>, NAlloc<char>>;
|
// using OstringStream = std::basic_ostringstream<char, std::char_traits<char>, NAlloc<char>>;
|
||||||
using IstringStream = std::basic_istringstream<char, std::char_traits<char>, NAlloc<char>>;
|
// using IstringStream = std::basic_istringstream<char, std::char_traits<char>, NAlloc<char>>;
|
||||||
using RtString = std::basic_string<char, std::char_traits<char>, NAlloc<char>>;
|
// using RtString = std::basic_string<char, std::char_traits<char>, NAlloc<char>>;
|
||||||
|
|
||||||
|
|
||||||
} //namespace
|
// } //namespace
|
||||||
|
|
||||||
TEST_CASE("controlled bad_alloc_rt_string")
|
TEST_CASE("controlled bad_alloc_rt_string")
|
||||||
{
|
{
|
||||||
|
using RtString = std::basic_string<char, std::char_traits<char>, my_allocator<char>>;
|
||||||
// create JSON type using the throwing allocator
|
// create JSON type using the throwing allocator
|
||||||
using my_json = nlohmann::basic_json<std::map,
|
using my_json = nlohmann::basic_json<std::map,
|
||||||
std::vector,
|
std::vector,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user