Exemple #1
0
/* This is a managed file. Do not delete this comment. */

#include <include/test.h>
void observerCallback(corto_observer_event *event) {
    test_Dispatcher instance = event->instance;
    instance->observerPosted ++;
}

void test_Dispatcher_tc_observerDispatcher(
    test_Dispatcher this)
{
    corto_object obj = corto_create(root_o, "data/obj", corto_void_o);
    corto_dispatcher d = test_FooDispatcher__create(NULL, NULL);
    corto_observer o = corto_observe(CORTO_UPDATE, obj)
        .instance(this)
        .dispatcher(d)
        .callback(observerCallback);
    test_assert(o != NULL);

    test_assert(corto_update(obj) == 0);
    test_assertint(this->observerPosted, 1);

    test_assert(corto_delete(o) == 0);
    test_assert(corto_delete(d) == 0);
    test_assert(corto_delete(obj) == 0);
}

void test_Dispatcher_tc_observerDispatcherMulti(
    test_Dispatcher this)
{
    corto_object obj = corto_create(root_o, "data/obj", corto_void_o);
Exemple #2
0
    corto_ptr_setref(&this->observable, e->data);
    corto_ptr_setref(&this->observer, e->observer);
}

void test_Observers_tc_dispatchObserver(
    test_Observers this)
{
    corto_object o = corto_create(corto_void_o);
    test_assert(o != NULL);

    test_ObserverDispatcher d = corto_create(test_ObserverDispatcher_o);
    test_assert(d != NULL);

    test_assert(o != NULL);
    corto_observer observer = corto_observe(CORTO_UPDATE, o)
      .dispatcher(d)
      .instance(this)
      .callback(dispatchObserver_onUpdate);
    test_assert(observer != NULL);

    test_assert(corto_update(o) == 0);

    test_assert(d->called == TRUE);
    test_assert(this->mask == CORTO_UPDATE);
    test_assert(this->observable == o);
    test_assert(this->observer == observer);

    test_assert(corto_delete(observer) == 0);
    test_assert(corto_delete(o) == 0);
    test_assert(corto_delete(d) == 0);

}