|
@ -3,10 +3,12 @@ |
|
|
#include "gp/array.hpp"
|
|
|
#include "gp/array.hpp"
|
|
|
#include "gp/indexed_array.hpp"
|
|
|
#include "gp/indexed_array.hpp"
|
|
|
#include "gp/allocator/aggregator.hpp"
|
|
|
#include "gp/allocator/aggregator.hpp"
|
|
|
|
|
|
#include "gp/allocator/arena.hpp"
|
|
|
#include "gp/allocator/buddy.hpp"
|
|
|
#include "gp/allocator/buddy.hpp"
|
|
|
#include "gp/allocator/dummy.hpp"
|
|
|
#include "gp/allocator/dummy.hpp"
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
#include "gp/algorithm/rotate.hpp"
|
|
|
#include "gp/algorithm/rotate.hpp"
|
|
|
|
|
|
#include "gp/algorithm/move.hpp"
|
|
|
#include "gp/ring_list.hpp"
|
|
|
#include "gp/ring_list.hpp"
|
|
|
#include <thread>
|
|
|
#include <thread>
|
|
|
#include <chrono>
|
|
|
#include <chrono>
|
|
@ -415,6 +417,35 @@ struct aggregator_test : public test_scaffold { |
|
|
} |
|
|
} |
|
|
auto duration = std::chrono::steady_clock::now() - start; |
|
|
auto duration = std::chrono::steady_clock::now() - start; |
|
|
} |
|
|
} |
|
|
|
|
|
void* a = allocator.allocate(8); |
|
|
|
|
|
gp_config::assertion(allocator.try_reallocate(a, 16) == false, "could reallocate? was it implemented?"); |
|
|
|
|
|
gp_config::assertion(allocator.deallocate(nullptr) == false, "error, could free an invalid pointer"); |
|
|
|
|
|
allocator.deallocate(a); |
|
|
|
|
|
{ |
|
|
|
|
|
gp::ring_list<int, gp::aggregator, false> list{allocator}; |
|
|
|
|
|
list.insert(8); |
|
|
|
|
|
list.insert(16); |
|
|
|
|
|
list.insert(32); |
|
|
|
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::array<char, 256> work_array; |
|
|
|
|
|
gp::arena<> alloc_work(work_array.begin().data, work_array.size()); |
|
|
|
|
|
gp::ring_list<int, gp::arena<>, false> list{alloc_work}; |
|
|
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::array<char, sizeof(int)> once_array; |
|
|
|
|
|
gp::arena<> alloc_once(once_array.begin().data, once_array.size()); |
|
|
|
|
|
gp::ring_list<int, gp::arena<>, false> list{alloc_once}; |
|
|
|
|
|
gp_config::assertion(list.insert(8) == false, "could allocate in list with insufficient allocator"); |
|
|
|
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::arena<> alloc_none(nullptr, 0); |
|
|
|
|
|
gp::ring_list<int, gp::arena<>, false> list{alloc_none}; |
|
|
|
|
|
gp_config::assertion(list.insert(8) == false, "could allocate in list with fake allocator"); |
|
|
|
|
|
} |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -531,4 +562,102 @@ struct indexed_array_test : public test_scaffold { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
append_test dummy_khxurgsd3(new indexed_array_test{}); |
|
|
|
|
|
|
|
|
append_test dummy_khxurgsd3(new indexed_array_test{}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct move_uninitialized_test : public test_scaffold { |
|
|
|
|
|
move_uninitialized_test() { |
|
|
|
|
|
name = __FILE__ ":8"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct tester { |
|
|
|
|
|
size_t* const incremented; |
|
|
|
|
|
|
|
|
|
|
|
tester(size_t* ptr) |
|
|
|
|
|
: incremented(ptr) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
tester(tester&& oth) |
|
|
|
|
|
: incremented(oth.incremented) |
|
|
|
|
|
{ |
|
|
|
|
|
++*incremented; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
|
|
|
int res = 0; |
|
|
|
|
|
{ |
|
|
|
|
|
size_t counter; |
|
|
|
|
|
using src_t = gp::array<tester, 16>; |
|
|
|
|
|
src_t *source = reinterpret_cast<src_t*>(malloc(sizeof(src_t))); |
|
|
|
|
|
gp::array<char, sizeof(tester)*16> buffer; |
|
|
|
|
|
for(auto& a : *source) { |
|
|
|
|
|
new(&a) tester(&counter); |
|
|
|
|
|
} |
|
|
|
|
|
gp::move_uninitialized(*source, buffer.as_buffer().cast<tester>()); |
|
|
|
|
|
free(source); |
|
|
|
|
|
} |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
append_test dummy_hkfyr5f5(new move_uninitialized_test{}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct clamp_test : public test_scaffold { |
|
|
|
|
|
clamp_test() { |
|
|
|
|
|
name = __FILE__ ":9"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
|
|
|
int res = 0; |
|
|
|
|
|
{ |
|
|
|
|
|
res += gp::clamp<float>(0.0, -1.0, 1.0); |
|
|
|
|
|
res += gp::clamp<float>(-1.0, 1.0, 0.0); |
|
|
|
|
|
res += gp::max(-1, -2, 0, -3); |
|
|
|
|
|
} |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
append_test dummy_gsdh25f5(new clamp_test{}); |
|
|
|
|
|
|
|
|
|
|
|
struct buffer_test : public test_scaffold { |
|
|
|
|
|
buffer_test() { |
|
|
|
|
|
name = __FILE__ ":10"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
|
|
|
int res = 0; |
|
|
|
|
|
{ |
|
|
|
|
|
gp::array<char, 24> data; |
|
|
|
|
|
gp::array<char, 24> data_e; |
|
|
|
|
|
gp::buffer<char> handle = data.as_buffer(); |
|
|
|
|
|
handle[12] = '&'; |
|
|
|
|
|
gp_config::assertion(*(handle.begin()+12) == '&', "Could not assign to the buffer"); |
|
|
|
|
|
res += 1; |
|
|
|
|
|
try { |
|
|
|
|
|
handle[24] = 16; |
|
|
|
|
|
res += 1; |
|
|
|
|
|
handle[-1] = 16; |
|
|
|
|
|
res += 1; |
|
|
|
|
|
handle[1024] = 16; |
|
|
|
|
|
} catch (...) { |
|
|
|
|
|
res -= 1; |
|
|
|
|
|
} |
|
|
|
|
|
res += 1; |
|
|
|
|
|
try { |
|
|
|
|
|
auto cast = handle.cast<gp::array<char, 32>>(); |
|
|
|
|
|
} catch (...) { |
|
|
|
|
|
res -= 1; |
|
|
|
|
|
} |
|
|
|
|
|
auto cast = handle.template cast<gp::array<char, 6>>().template cast<gp::array<char, 4>>(); |
|
|
|
|
|
gp_config::assertion(false == (data == data_e), "Different arrays should return false here"); |
|
|
|
|
|
} |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
append_test dummy_gs87ytf5f5(new buffer_test{}); |