static void testInvalid(void) {
        int status = 0;

        /* Invalid field */
        dyn_interface_type *dynIntf = NULL;
        FILE *desc = fopen("descriptors/invalids/invalid.descriptor", "r");
        assert(desc != NULL);
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of a space at the end of the name
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Header without Version */
        desc = fopen("descriptors/invalids/noVersion.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of missing version field in header section
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid section */
        desc = fopen("descriptors/invalids/invalidSection.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of unknown section type
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid return type */
        desc = fopen("descriptors/invalids/invalidMethodReturnType.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of invalid return type (D instead of N)
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid  method section */
        desc = fopen("descriptors/invalids/invalidMethod.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of space at the end of the method
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid type */
        desc = fopen("descriptors/invalids/invalidType.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Test fails because of space at the end of the type
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid metatype in method description */
        desc = fopen("descriptors/invalids/invalidMetaType.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(0, status); //Invalid meta type doesn't generate errors, just warnings
        fclose(desc);
        dynInterface_destroy(dynIntf);

        /* Invalid version section */
        desc = fopen("descriptors/invalids/invalidVersion.descriptor", "r");
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(1, status); //Invalid meta type doesn't generate errors, just warnings
        fclose(desc);
    }
Example #2
0
    static void test2(void) {
        int status = 0;
        dyn_interface_type *dynIntf = NULL;
        FILE *desc = fopen("descriptors/example3.descriptor", "r");
        assert(desc != NULL);
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(0, status);
        fclose(desc);

        dynInterface_destroy(dynIntf);
    }
Example #3
0
    static void handleTestOutputSequence(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example2.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        struct methods_head *head;
        dynInterface_methods(intf, &head);
        dyn_function_type *func = NULL;
        struct method_entry *entry = NULL;
        TAILQ_FOREACH(entry, head, entries) {
            if (strcmp(entry->name, "example1") == 0) {
                func = entry->dynFunc;
                break;
            }
        }
        CHECK(func != NULL);

        //dyn_type *arg = dynFunction_argumentTypeForIndex(func, 1);
        //dynType_print(arg, stdout);

        const char *reply = "{\"r\":[{\"a\":1.0,\"b\":1.5},{\"a\":2.0,\"b\":2.5}]}";

        void *args[2];
        args[0] = NULL;
        args[1] = NULL;

        struct item_seq *result = NULL;
        void *out = &result;
        args[1] = &out;

        rc = jsonRpc_handleReply(func, reply, args);
        CHECK_EQUAL(0, rc);
        CHECK_EQUAL(2, result->len);
        CHECK_EQUAL(1.0, result->buf[0]->a);
        CHECK_EQUAL(1.5, result->buf[0]->b);
        CHECK_EQUAL(2.0, result->buf[1]->a);
        CHECK_EQUAL(2.5, result->buf[1]->b);


        unsigned int i;
        for (i = 0; i < result->len; i +=1 ) {
            free(result->buf[i]);
        }
        free(result->buf);
        free(result);
        dynInterface_destroy(intf);
    }
Example #4
0
    void callTestOutput(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example1.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        char *result = NULL;

        struct tst_serv serv;
        serv.handle = NULL;
        serv.stats = stats;

        rc = jsonRpc_call(intf, &serv, "{\"m\":\"stats([D)LStatsResult;\", \"a\": [[1.0,2.0]]}", &result);
        CHECK_EQUAL(0, rc);
        STRCMP_CONTAINS("1.5", result); //avg

        free(result);
        dynInterface_destroy(intf);
    }
Example #5
0
    static void test1(void) {
        int status = 0;
        dyn_interface_type *dynIntf = NULL;
        FILE *desc = fopen("descriptors/example1.descriptor", "r");
        assert(desc != NULL);
        status = dynInterface_parse(desc, &dynIntf);
        CHECK_EQUAL(0, status);
        fclose(desc);

        char *name = NULL;
        status = dynInterface_getName(dynIntf, &name);
        CHECK_EQUAL(0, status);
        STRCMP_EQUAL("calculator", name);

        char *version = NULL;
        status = dynInterface_getVersion(dynIntf, &version);
        CHECK_EQUAL(0, status);
        STRCMP_EQUAL("1.0.0", version);

        char *annVal = NULL;
        status = dynInterface_getAnnotationEntry(dynIntf, "classname", &annVal);
        CHECK_EQUAL(0, status);
        STRCMP_EQUAL("org.example.Calculator", annVal);

        char *nonExist = NULL;
        status = dynInterface_getHeaderEntry(dynIntf, "nonExisting", &nonExist);
        CHECK(status != 0);
        CHECK(nonExist == NULL);

        struct methods_head *list = NULL;
        status = dynInterface_methods(dynIntf, &list);
        CHECK(status == 0);
        CHECK(list != NULL);

        int count = dynInterface_nrOfMethods(dynIntf);
        CHECK_EQUAL(4, count);

        dynInterface_destroy(dynIntf);
    }
Example #6
0
    void callTestOutChar(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example4.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        char *result = NULL;

        struct tst_serv_example4 serv;
        serv.handle = NULL;
        serv.getName_example4 = getName_example4;

        rc = jsonRpc_call(intf, &serv, "{\"m\":\"getName(V)t\", \"a\": []}", &result);
        CHECK_EQUAL(0, rc);

        STRCMP_CONTAINS("allocatedInFunction", result);

        free(result);
        dynInterface_destroy(intf);
    }
Example #7
0
    void handleTestOut(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example1.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        struct methods_head *head;
        dynInterface_methods(intf, &head);
        dyn_function_type *func = NULL;
        struct method_entry *entry = NULL;
        TAILQ_FOREACH(entry, head, entries) {
            if (strcmp(entry->name, "stats") == 0) {
                func = entry->dynFunc;
                break;
            }
        }
        CHECK(func != NULL);

        const char *reply = "{\"r\":{\"input\":[1.0,2.0],\"max\":2.0,\"average\":1.5,\"min\":1.0}}";

        void *args[3];
        args[0] = NULL;
        args[1] = NULL;
        args[2] = NULL;

        struct tst_StatsResult *result = NULL;
        void *out = &result;
        args[2] = &out;

        rc = jsonRpc_handleReply(func, reply, args);
        CHECK_EQUAL(0, rc);
        CHECK_EQUAL(1.5, result->average);

        free(result->input.buf);
        free(result);
        dynInterface_destroy(intf);
    }
Example #8
0
    void callTestPreAllocated(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example1.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        char *result = NULL;

        struct tst_serv serv;
        serv.handle = NULL;
        serv.add = add;


        rc = jsonRpc_call(intf, &serv, "{\"m\":\"add(DD)D\", \"a\": [1.0,2.0]}", &result);
        CHECK_EQUAL(0, rc);
        STRCMP_CONTAINS("3.0", result);

        free(result);
        dynInterface_destroy(intf);
    }
Example #9
0
    void handleTestOutChar(void) {
        dyn_interface_type *intf = NULL;
        FILE *desc = fopen("descriptors/example4.descriptor", "r");
        CHECK(desc != NULL);
        int rc = dynInterface_parse(desc, &intf);
        CHECK_EQUAL(0, rc);
        fclose(desc);

        struct methods_head *head;
        dynInterface_methods(intf, &head);
        dyn_function_type *func = NULL;
        struct method_entry *entry = NULL;
        TAILQ_FOREACH(entry, head, entries) {
            if (strcmp(entry->name, "getName") == 0) {
                func = entry->dynFunc;
                break;
            }
        }

        CHECK(func != NULL);

        const char *reply = "{\"r\": \"this is a test string\" }";
        char *result = NULL;
        void *out = &result;

        void *args[2];
        args[0] = NULL;
        args[1] = &out;

        rc = jsonRpc_handleReply(func, reply, args);

        STRCMP_EQUAL("this is a test string", result);

        free(result);
        dynInterface_destroy(intf);
    }