Test construction from raw pointers
This commit is contained in:
parent
21f2dd4cad
commit
47273edf6e
@ -1,5 +1,6 @@
|
|||||||
#include <rcp.h>
|
#include <rcp.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
static int mybase_construct;
|
static int mybase_construct;
|
||||||
static int mybase_destruct;
|
static int mybase_destruct;
|
||||||
@ -48,7 +49,7 @@ public:
|
|||||||
double v;
|
double v;
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_destructors_called()
|
void test_class_hierarchy()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
rcp<MyBase> mybase = MyBase::create(4, 5);
|
rcp<MyBase> mybase = MyBase::create(4, 5);
|
||||||
@ -84,11 +85,46 @@ void test_create()
|
|||||||
assert(myb->x == 8);
|
assert(myb->x == 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MyObj
|
||||||
|
{
|
||||||
|
rcp_managed_root(MyObj);
|
||||||
|
public:
|
||||||
|
int v = {42};
|
||||||
|
template <typename R>
|
||||||
|
void add_to(R & receiver)
|
||||||
|
{
|
||||||
|
receiver.add(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct Receiver
|
||||||
|
{
|
||||||
|
std::vector<rcp<MyObj>> objects;
|
||||||
|
void add(MyObj * o)
|
||||||
|
{
|
||||||
|
objects.push_back(rcp<MyObj>(o));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void test_multi_construct_from_raw_pointers()
|
||||||
|
{
|
||||||
|
Receiver r;
|
||||||
|
auto myo = MyObj::create();
|
||||||
|
for (size_t i = 0u; i < 5u; i++)
|
||||||
|
{
|
||||||
|
myo->add_to(r);
|
||||||
|
}
|
||||||
|
for (size_t i = 0u; i < 5u; i++)
|
||||||
|
{
|
||||||
|
assert(r.objects[i]->v == 42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
test_destructors_called();
|
test_class_hierarchy();
|
||||||
test_dereference();
|
test_dereference();
|
||||||
test_booleans();
|
test_booleans();
|
||||||
test_create();
|
test_create();
|
||||||
|
test_multi_construct_from_raw_pointers();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user