Add "listener registration" test to test passing "this" out of a managed class
This commit is contained in:
parent
627661158e
commit
403db54664
@ -124,6 +124,30 @@ void test_multi_construct_from_raw_pointers()
|
||||
}
|
||||
}
|
||||
|
||||
struct EventListener;
|
||||
static std::vector<rcp<EventListener>> g_listeners;
|
||||
|
||||
struct EventListener
|
||||
{
|
||||
rcp_managed_root(EventListener);
|
||||
public:
|
||||
int events_received = 0;
|
||||
void attach() { g_listeners.push_back(this); }
|
||||
};
|
||||
|
||||
void test_listener_self_registration()
|
||||
{
|
||||
g_listeners.clear();
|
||||
auto a = EventListener::create();
|
||||
auto b = EventListener::create();
|
||||
a->attach();
|
||||
b->attach();
|
||||
for (auto & l : g_listeners) l->events_received++;
|
||||
assert(a->events_received == 1);
|
||||
assert(b->events_received == 1);
|
||||
g_listeners.clear();
|
||||
}
|
||||
|
||||
void test_copy_assignment_decrements_previous_reference()
|
||||
{
|
||||
MyB myb = MyB::create(12, 13);
|
||||
@ -272,6 +296,7 @@ int main(int argc, char * argv[])
|
||||
test_booleans();
|
||||
test_create();
|
||||
test_multi_construct_from_raw_pointers();
|
||||
test_listener_self_registration();
|
||||
test_copy_assignment_decrements_previous_reference();
|
||||
test_cross_type_comparison();
|
||||
test_reset();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user