corto_void _test_compositeApi_tc_define(
    test_compositeApi _this)
{
/* $begin(test/compositeApi/tc_define) */
    corto_int16 result;

    test_compositeType *o = test_compositeTypeDeclareChild(root_o, "o");
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeType_o));
    test_assert(!corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->x == 1);
    test_assert(o->y == 2);

    result = test_compositeTypeDefine(o, 10, 20);
    test_assert(result == 0);
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(o->x == 10);
    test_assert(o->y == 20);

    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeApi_tc_update(
    test_compositeApi _this)
{
/* $begin(test/compositeApi/tc_update) */
    corto_int16 result;

    test_compositeType *o = test_compositeTypeCreate(10, 20);
    test_assert(o != NULL);

    result = corto_observer_observe(test_compositeApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    result = test_compositeTypeUpdate(o, 20, 30);
    test_assert(result == 0);
    test_assert(_this->updated == TRUE);
    test_assert(o->x == 20);
    test_assert(o->y == 30);

    result = corto_observer_unobserve(test_compositeApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    corto_delete(o);

/* $end */
}
corto_void _test_compositeUnionApi_tc_updateDefault(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_updateDefault) */
    corto_int16 result;

    test_compositeUnionType *o = test_compositeUnionTypeCreate_num(0, 10);
    test_assert(o != NULL);

    result = corto_observer_observe(test_compositeUnionApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    result = test_compositeUnionTypeUpdate_other(o, 4, 20);
    test_assert(result == 0);
    test_assert(_this->updated == TRUE);
    test_assert(o->d == 4);
    test_assert(o->is.other == 20);

    result = corto_observer_unobserve(test_compositeUnionApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    corto_delete(o);

/* $end */
}
Beispiel #4
0
corto_void _dDDS_delete(dDDS_Object object) {
/* $begin(dDDS/delete) */

    corto_delete(object);

/* $end */
}
int objects_hierarchyMain(int argc, char *argv[]) {

    /* Create an object in the global object hierarchy */
    corto_object *parent = corto_createChild(root_o, "parent", corto_void_o);
    if (!parent) {
        goto error;
    }

    /* Show information about the parent object */
    printInfo(parent);

    /* Create an object in the scope of the parent object */
    corto_object *child = corto_createChild(parent, "child", corto_void_o);
    if (!parent) {
        goto error;
    }

    /* Show information about the child object */
    printInfo(child);

    /* Delete both the parent and child object */
    if (corto_delete(parent)) {
        goto error;
    }

    return 0;
error:
    corto_error("error: %s", corto_lasterr());
    return -1;
}
corto_void _test_OptionalStringApi_tc_updateNotSet(
    test_OptionalStringApi _this)
{
/* $begin(test/OptionalStringApi/tc_updateNotSet) */
    corto_int16 result;

    test_OptionalString *o = test_OptionalStringCreate(Set("Foo"), "Bar");
    test_assert(o != NULL);

    result = corto_observer_observe(test_OptionalStringApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    result = test_OptionalStringUpdate(o, NotSet, "Bar");
    test_assert(result == 0);
    test_assert(_this->updated == TRUE);
    test_assert(o->a == NULL);
    test_assertstr(o->b, "Bar");

    result = corto_observer_unobserve(test_OptionalStringApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    corto_delete(o);

/* $end */
}
corto_void _test_compositeUnionApi_tc_defineDefault(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_defineDefault) */
    corto_int16 result;

    test_compositeUnionType *o = test_compositeUnionTypeDeclareChild(root_o, "o");
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(!corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->d == 2);
    test_assertstr(o->is.str, "foo");

    result = test_compositeUnionTypeDefine_other(o, 4, 10);
    test_assert(result == 0);
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(o->d == 4);
    test_assert(o->is.other == 10);

    test_assert(!corto_delete(o));

/* $end */
}
Beispiel #8
0
int testMain(int argc, char* argv[]) {
/* $begin(main) */
    int result = 0;
    test_Runner runner = test_RunnerCreate("corto/md", argv[0], (argc > 1) ? argv[1] : NULL);
    if (!runner) return -1;
    if (corto_llSize(runner->failures)) {
        result = -1;
    }
    corto_delete(runner);
    return result;
/* $end */
}
corto_void _test_voidReferenceApi_tc_createAuto(
    test_voidReferenceApi _this)
{
/* $begin(test/voidReferenceApi/tc_createAuto) */

    test_voidReferenceTypeCreate_auto(o);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == test_voidReferenceType_o);
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(!corto_delete(o));

/* $end */
}
Beispiel #10
0
corto_void _test_compositeApi_tc_declare(
    test_compositeApi _this)
{
/* $begin(test/compositeApi/tc_declare) */

    test_compositeType *o = test_compositeTypeDeclare();
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeType_o));
    test_assert(!corto_checkState(o, CORTO_DEFINED));
    test_assert(o->x == 1);
    test_assert(o->y == 2);
    test_assert(!corto_delete(o));

/* $end */
}
Beispiel #11
0
corto_void _test_compositeApi_tc_createAuto(
    test_compositeApi _this)
{
/* $begin(test/compositeApi/tc_createAuto) */

    test_compositeTypeCreate_auto(o, 10, 20);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(o->x == 10);
    test_assert(o->y == 20);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_create(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_create) */

    test_compositeUnionType *o = test_compositeUnionTypeCreate_flt(1, 10.5);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(o->d == 1);
    test_assert(o->is.flt == 10.5);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_createAutoDefault(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_createAutoDefault) */

    test_compositeUnionTypeCreate_other_auto(o, 4, 10);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(o->d == 4);
    test_assert(o->is.other == 10);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_declareAuto(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_declareAuto) */

    test_compositeUnionTypeDeclare_auto(o);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(!corto_checkState(o, CORTO_DEFINED));
    test_assert(o->d == 2);
    test_assertstr(o->is.str, "foo");
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_voidReferenceApi_tc_createChildAuto(
    test_voidReferenceApi _this)
{
/* $begin(test/voidReferenceApi/tc_createChildAuto) */

    test_voidReferenceTypeCreateChild_auto(root_o, o);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == test_voidReferenceType_o);
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(!corto_delete(o));

/* $end */
}
Beispiel #16
0
corto_void _test_compositeApi_tc_createChildAuto(
    test_compositeApi _this)
{
/* $begin(test/compositeApi/tc_createChildAuto) */

    test_compositeTypeCreateChild_auto(root_o, o, 10, 20);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->x == 10);
    test_assert(o->y == 20);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_declareChildAuto(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_declareChildAuto) */

    test_compositeUnionTypeDeclareChild_auto(root_o, o);
    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(!corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->d == 2);
    test_assertstr(o->is.str, "foo");
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_createChildAutoDefault(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_createChildAutoDefault) */

    test_compositeUnionTypeCreateChild_other_auto(
        root_o,
        o,
        4,
        10);

    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->d == 4);
    test_assert(o->is.other == 10);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_compositeUnionApi_tc_createChild(
    test_compositeUnionApi _this)
{
/* $begin(test/compositeUnionApi/tc_createChild) */

    test_compositeUnionType *o = test_compositeUnionTypeCreateChild_flt(
        root_o,
        "o",
        1,
        10.5);

    test_assert(o != NULL);
    test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o));
    test_assert(corto_checkState(o, CORTO_DEFINED));
    test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED));
    test_assert(corto_parentof(o) == root_o);
    test_assert(!strcmp(corto_idof(o), "o"));
    test_assert(o->d == 1);
    test_assert(o->is.flt == 10.5);
    test_assert(!corto_delete(o));

/* $end */
}
corto_void _test_voidReferenceApi_tc_update(
    test_voidReferenceApi _this)
{
/* $begin(test/voidReferenceApi/tc_update) */
    corto_int16 result;

    test_voidReferenceType o = test_voidReferenceTypeCreate();
    test_assert(o != NULL);

    result = corto_observer_observe(test_voidReferenceApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    result = test_voidReferenceTypeUpdate(o);
    test_assert(result == 0);
    test_assert(_this->updated == TRUE);

    result = corto_observer_unobserve(test_voidReferenceApi_onUpdate_o, _this, o);
    test_assert(result == 0);

    corto_delete(o);

/* $end */
}
Beispiel #21
0
}

void test_Ownership_setup(
    test_Ownership this)
{

}

void test_Ownership_tc_checkOwnerNull(
    test_Ownership this)
{
    corto_object o = corto_voidCreateChild(NULL, "o");
    test_assert(o != NULL);
    test_assert(corto_ownerof(o) == NULL);

    corto_int16 result = corto_delete(o);
    test_assert(result == 0);

}

void test_Ownership_tc_checkOwnerReplicator(
    test_Ownership this)
{
    test_FooReplicator r = test_FooReplicatorCreate(root_o);

    corto_object old = corto_setOwner(r);
    test_assert(old == NULL);

    corto_object o = corto_voidCreateChild(NULL, "o");
    test_assert(o != NULL);
    test_assert(corto_checkAttr(o, CORTO_ATTR_PERSISTENT));
Beispiel #22
0
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);
    corto_dispatcher d = test_FooDispatcher__create(NULL, NULL);
    corto_observer o1 = corto_observe(CORTO_UPDATE, obj)
        .instance(this)
        .dispatcher(d)
        .callback(observerCallback);
    test_assert(o1 != NULL);
    corto_observer o2 = corto_observe(CORTO_UPDATE, obj)
Beispiel #23
0
static void mqtt_onMessage(
    struct mosquitto *client,
    void *data,
    const struct mosquitto_message *msg)
{
    corto_id nameBuffer;
    char *name = nameBuffer;
    corto_object o = NULL;
    mqtt_Connector this = data;
    corto_bool isDelete = FALSE;

    /* If the payload has been serialized as a corto string, the typename is
     * potentially prefixed to the value */
    char *valueStr = strchr(msg->payload, '{');

    /* mqtt is the owner of this thread. This ensures that all subsequent create
     * update / delete actions are performed with the right owner. Ownership
     * ensures to not trigger on own updates, and to only forward data from
     * other connectors (or the application). */
    corto_object prevOwner = corto_setOwner(this);

    /* Remove topic from name, so that name is relative to mount point. */
    strcpy(name, msg->topic);
    if (this->topic) {
        name += strlen(this->topic) + 1;
    }

    char *lastElem = strrchr(name, '/');
    if (lastElem && !strcmp(lastElem, "/_d")) {
        *lastElem = '\0';
        isDelete = TRUE;
    }

    corto_debug("mqtt: %s: received '%s'", msg->topic, msg->payload);

    /* If object doesn't yet exist in the store, create it */
    if (!(o = corto_lookup(corto_mount(this)->mount, name)) && !isDelete) {
        corto_id buffer;
        corto_debug("mqtt: creating new object for '%s'", name);

        /* If the mount has been configured with a fixed type, use that type to
         * create a new object. Otherwise, look for type in payload. */
        if (corto_observer(this)->type) {
            strcpy(buffer, corto_observer(this)->type);
        } else {
            char *typeStr = strchr(msg->payload, '{');
            memcpy(buffer, msg->payload, typeStr - (char*)msg->payload);
            buffer[typeStr - (char*)msg->payload] = '\0';
        }

        /* Resolve type. If type wasn't yet loaded in corto, corto_resolve will
         * do a lookup on the package repository. If it doesn't exist there
         * either throw an error. Currently, the MQTT connector does not align
         * types. */
        corto_type type = corto_resolve(NULL, buffer);
        if (!type) {
            corto_error("mqtt: type '%s' not found", buffer);
            goto error;
        }

        corto_debug("mqtt: creating '%s' with type '%s'", name, buffer);

        /* Create a new object under the mountpoint. The name is derived from
         * the MQTT topic name. */
        o = corto_declareChild(corto_mount(this)->mount, name, type);
        if (!o) {
            corto_error("mqtt: failed to create object '%s'", name);
            goto error;
        }
    } else {
        corto_debug("mqtt: found '%s' for '%s'", corto_fullpath(NULL, o), name);
    }

    /* Only continue updating object when it is owned by mqtt */
    if (o && corto_owned(o)) {
        if (isDelete) {
            if (corto_delete(o)) {
                corto_error("mqtt: failed to delete '%s': %s", name, corto_lasterr());
            }
            corto_release(o);
        } else {
            /* Start updating object (takes a writelock) */
            if (!corto_updateBegin(o)) {
                /* Serialize value from JSON string */
                if (corto_fromcontent(o, "text/json", valueStr)) {
                    corto_error("mqtt: failed to deserialize for %s: %s (%s)\n",
                        name,
                        corto_lasterr(),
                        msg->payload);

                    /* If deserialization fails, cancel the update. No notification
                     * will be sent. */
                    corto_updateCancel(o);
                    goto error;
                }
                /* Successful update. Send notification and unlock object */
                if (corto_updateEnd(o)) {
                    corto_error("mqtt: failed to update '%s': %s", name, corto_lasterr());
                    goto error;
                }
            } else {
                /* For some reason, couldn't start updating object */
                corto_error("mqtt: failed to start updating '%s': %s", name, corto_lasterr());
                goto error;
            }
        }
    } else if (o) {
        corto_debug("mqtt: '%s' not owned by me (%s, defined = %d), ignoring",
            corto_fullpath(NULL, o),
            corto_ownerof(o) ? corto_fullpath(NULL, o) : "local",
            corto_checkState(o, CORTO_DEFINED));
    }

error:
    /* Restore previous owner */
    corto_setOwner(prevOwner);
}
Beispiel #24
0
    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);

}


void notifyReadDenied_onUpdate(corto_observerEvent *e)
{
    test_Observers this = e->instance;
    this->mask = e->event;
    corto_ptr_setref(&this->observable, e->data);
    corto_ptr_setref(&this->observer, e->observer);
    this->count ++;
}
Beispiel #25
0
/* This is a managed file. Do not delete this comment. */

#include <include/test.h>

void test_AttrCheck_tc_constructorAttr(
    test_AttrCheck this)
{
    corto_int16 ret;

    corto_object o = test_AttrConstructorTest__create(NULL, NULL);
    test_assert(o != NULL);

    ret = corto_delete(o);
    test_assert(ret == 0);

    corto_attr prev = corto_set_attr(CORTO_ATTR_PERSISTENT);
    o = test_AttrConstructorTest__create(NULL, NULL);
    test_assert(o != NULL);
    corto_set_attr(prev);

    ret = corto_delete(o);
    test_assert(ret == 0);

}

void test_AttrCheck_tc_packageMainAttr(
    test_AttrCheck this)
{
    corto_int8 ret;
    corto_int8 sig;
    corto_value left = corto_value_object(foo, NULL);
    corto_value right = corto_value_object(bar, NULL);
    corto_value result = corto_value_init();

    left.ref_kind = CORTO_BY_REFERENCE;
    right.ref_kind = CORTO_BY_REFERENCE;

    int16_t ret = corto_value_binaryOp(CORTO_ASSIGN, &left, &right, &result);

    test_assert(ret != 0);
    test_assert(ut_catch() != 0);

    test_assert(*foo == false);

    test_assert(corto_delete(foo) == 0);
    test_assert(corto_delete(bar) == 0);
}


void test_assign_ref_to_bool_obj_tc_byref_fromobj_bytype(
    test_assign_ref_to_bool_obj this)
{
    bool *foo = corto_create(NULL, NULL, corto_bool_o);
    test_assert(foo != NULL);

    test_reftype bar = corto_create(NULL, NULL, test_reftype_o);
    test_assert(bar != NULL);

    corto_value left = corto_value_object(foo, NULL);
    corto_value right = corto_value_object(bar, NULL);
Beispiel #27
0
    /* Subscribe for scope in obj1: ok */
    corto_subscriber s2 = corto_subscribe("obj1/*").from("/mountRoot")
      .callback(NULL);
    test_assert(s2 != NULL);
    test_assertint(corto_ll_size(m->subscribes), 2);
    test_assertint(corto_ll_size(m->unsubscribes), 0);

    /* Subscribe for scope in obj2: should not trigger new subscription */
    corto_subscriber s3 = corto_subscribe("obj2/*").from("/mountRoot")
      .callback(NULL);
    test_assert(s3 != NULL);
    test_assertint(corto_ll_size(m->subscribes), 2);
    test_assertint(corto_ll_size(m->unsubscribes), 0);

    test_assert(corto_delete(s1) == 0);
    test_assertint(corto_ll_size(m->subscribes), 2);
    test_assertint(corto_ll_size(m->unsubscribes), 1);

    test_assert(corto_delete(s2) == 0);
    test_assertint(corto_ll_size(m->subscribes), 2);
    test_assertint(corto_ll_size(m->unsubscribes), 2);

    test_assert(corto_delete(s3) == 0);
    test_assertint(corto_ll_size(m->subscribes), 2);
    test_assertint(corto_ll_size(m->unsubscribes), 2);

    test_assert(corto_delete(m) == 0);
    test_assert(corto_delete(mountRoot) == 0);

}