http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/dyn_function_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_function_tests.cpp b/dfi/private/test/dyn_function_tests.cpp deleted file mode 100644 index 58ad662..0000000 --- a/dfi/private/test/dyn_function_tests.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { - #include <stdio.h> - #include <stdint.h> - #include <stdlib.h> - #include <string.h> - #include <ctype.h> - - - #include "dyn_common.h" - #include "dyn_function.h" - - static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); - } - - #define EXAMPLE1_DESCRIPTOR "example(III)I" - int32_t example1(int32_t a, int32_t b, int32_t c) { - CHECK_EQUAL(2, a); - CHECK_EQUAL(4, b); - CHECK_EQUAL(8, c); - return 1; - } - - void test_example1(void) { - dyn_function_type *dynFunc = NULL; - int rc; - void (*fp)(void) = (void (*)(void)) example1; - - rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(0, rc); - - int32_t a = 2; - int32_t b = 4; - int32_t c = 8; - void *values[3]; - int32_t rVal = 0; - values[0] = &a; - values[1] = &b; - values[2] = &c; - - rc = dynFunction_call(dynFunc, fp, &rVal, values); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(1, rVal); - dynFunction_destroy(dynFunc); - } - - #define EXAMPLE2_DESCRIPTOR "example(I{IID val1 val2 val3}D)D" - struct example2_arg { - int32_t val1; - int32_t val2; - double val3; - }; - - double example2(int32_t arg1, struct example2_arg arg2, double arg3) { - CHECK_EQUAL(2, arg1); - CHECK_EQUAL(2, arg2.val1); - CHECK_EQUAL(3, arg2.val2); - CHECK_EQUAL(4.1, arg2.val3); - CHECK_EQUAL(8.1, arg3); - return 2.2; - } - - void test_example2(void) { - dyn_function_type *dynFunc = NULL; - int rc; - void (*fp)(void) = (void (*)(void)) example2; - - rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(0, rc); - - int32_t arg1 = 2; - struct example2_arg arg2; - arg2.val1 = 2; - arg2.val2 = 3; - arg2.val3 = 4.1; - double arg3 = 8.1; - double returnVal = 0; - void *values[3]; - values[0] = &arg1; - values[1] = &arg2; - values[2] = &arg3; - - rc = dynFunction_call(dynFunc, fp, &returnVal, values); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(2.2, returnVal); - dynFunction_destroy(dynFunc); - } - - static void test_access_functions(void) { - dyn_function_type *dynFunc = NULL; - int rc; - rc = dynFunction_parseWithStr("add(D{DD a b}*D)V", NULL, &dynFunc); - - CHECK_EQUAL(0, rc); - - int nrOfArgs = dynFunction_nrOfArguments(dynFunc); - CHECK_EQUAL(3, nrOfArgs); - - dyn_type *arg1 = dynFunction_argumentTypeForIndex(dynFunc, 1); - CHECK(arg1 != NULL); - CHECK_EQUAL('{', (char) dynType_descriptorType(arg1)); - - dyn_type *nonExist = dynFunction_argumentTypeForIndex(dynFunc, 10); - CHECK(nonExist == NULL); - - dyn_type *returnType = dynFunction_returnType(dynFunc); - CHECK_EQUAL('V', (char) dynType_descriptorType(returnType)); - - dynFunction_destroy(dynFunc); - } - - //example with gen pointer and output - #define EXAMPLE3_DESCRIPTOR "example(PD*D)N" - - static int testExample3(void *ptr, double a, double *out) { - double *b = (double *)ptr; - CHECK_EQUAL(2.0, *b) - CHECK_EQUAL(a, 2.0); - *out = *b * a; - return 0; - } - - static void test_example3(void) { - dyn_function_type *dynFunc = NULL; - void (*fp)(void) = (void(*)(void)) testExample3; - int rc; - - rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(0, rc); - double result = -1.0; - double *input = &result; - double a = 2.0; - void *ptr = &a; - void *args[3]; - args[0] = &ptr; - args[1] = &a; - args[2] = &input; - int rVal = 0; - rc = dynFunction_call(dynFunc, fp, &rVal, args); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(4.0, result); - - - double *inMemResult = (double *)calloc(1, sizeof(double)); - a = 2.0; - ptr = &a; - args[0] = &ptr; - args[1] = &a; - args[2] = &inMemResult; - rVal = 0; - rc = dynFunction_call(dynFunc, fp, &rVal, args); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(4.0, result); - free(inMemResult); - - dynFunction_destroy(dynFunc); - } - - struct tst_seq { - uint32_t cap; - uint32_t len; - double *buf; - }; - - #define EXAMPLE4_DESCRIPTOR "example([D)V" - - static void example4Func(struct tst_seq seq) { - CHECK_EQUAL(4, seq.cap); - CHECK_EQUAL(2, seq.len); - CHECK_EQUAL(1.1, seq.buf[0]); - CHECK_EQUAL(2.2, seq.buf[1]); - } - - static void test_example4(void) { - dyn_function_type *dynFunc = NULL; - void (*fp)(void) = (void(*)(void)) example4Func; - int rc; - - rc = dynFunction_parseWithStr(EXAMPLE4_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(0, rc); - - double buf[4]; - buf[0] = 1.1; - buf[1] = 2.2; - struct tst_seq seq; - seq.cap = 4; - seq.len = 2; - seq.buf = buf; - - void *args[1]; - args[0] = &seq; - rc = dynFunction_call(dynFunc, fp, NULL, args); - CHECK_EQUAL(0, rc); - - dynFunction_destroy(dynFunc); - } - - #define INVALID_FUNC_DESCRIPTOR "example$[D)V"//$ is an invalid symbol, missing ( - - static void test_invalidDynFunc(void) { - dyn_function_type *dynFunc = NULL; - int rc = dynFunction_parseWithStr(INVALID_FUNC_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(2, rc); //Mem error - } - - #define INVALID_FUNC_TYPE_DESCRIPTOR "example(H)A"//H and A are invalid types - - static void test_invalidDynFuncType(void) { - dyn_function_type *dynFunc = NULL; - int rc = dynFunction_parseWithStr(INVALID_FUNC_TYPE_DESCRIPTOR, NULL, &dynFunc); - CHECK_EQUAL(3, rc); //Parse Error - } -} - -TEST_GROUP(DynFunctionTests) { - void setup() { - int lvl = 1; - dynFunction_logSetup(stdLog, NULL, lvl); - dynType_logSetup(stdLog, NULL, lvl); - dynCommon_logSetup(stdLog, NULL, lvl); - } -}; - -TEST(DynFunctionTests, DynFuncTest1) { - test_example1(); -} - -TEST(DynFunctionTests, DynFuncTest2) { - test_example2(); -} - -TEST(DynFunctionTests, DynFuncAccTest) { - test_access_functions(); -} - -TEST(DynFunctionTests, DynFuncTest3) { - test_example3(); -} - -TEST(DynFunctionTests, DynFuncTest4) { - test_example4(); -} - -TEST(DynFunctionTests, InvalidDynFuncTest) { - test_invalidDynFunc(); - test_invalidDynFuncType(); -}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/dyn_interface_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_interface_tests.cpp b/dfi/private/test/dyn_interface_tests.cpp deleted file mode 100644 index df9752f..0000000 --- a/dfi/private/test/dyn_interface_tests.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" -extern "C" { - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <assert.h> - -#include "dyn_common.h" -#include "dyn_interface.h" - -#if defined(BSD) || defined(__APPLE__) -#include "open_memstream.h" -#include "fmemopen.h" -#endif - - static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); - } - - static void checkInterfaceVersion(dyn_interface_type* dynIntf, const char* v) { - int status; - - char *version = NULL; - status = dynInterface_getVersionString(dynIntf, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL(v, version); - version_pt msgVersion = NULL, localMsgVersion = NULL; - int cmpVersion = -1; - version_createVersionFromString(version, &localMsgVersion); - status = dynInterface_getVersion(dynIntf, &msgVersion); - CHECK_EQUAL(0, status); - version_compareTo(msgVersion, localMsgVersion, &cmpVersion); - CHECK_EQUAL(cmpVersion, 0); - version_destroy(localMsgVersion); - } - - 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); - - checkInterfaceVersion(dynIntf,"1.0.0"); - - 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); - } - - 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); - } - - 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); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of a space at the end of the name - fclose(desc); desc=NULL; - - - /* Header without Version */ - desc = fopen("descriptors/invalids/noVersion.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of missing version field in header section - fclose(desc); desc=NULL; - - /* Invalid section */ - desc = fopen("descriptors/invalids/invalidSection.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of unknown section type - fclose(desc); desc=NULL; - - /* Invalid return type */ - desc = fopen("descriptors/invalids/invalidMethodReturnType.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of invalid return type (D instead of N) - fclose(desc); desc=NULL; - - /* Invalid method section */ - desc = fopen("descriptors/invalids/invalidMethod.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of space at the end of the method - fclose(desc); desc=NULL; - - /* Invalid type */ - desc = fopen("descriptors/invalids/invalidType.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Test fails because of space at the end of the type - fclose(desc); desc=NULL; - - /* Invalid metatype in method description */ - desc = fopen("descriptors/invalids/invalidMetaType.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - dynInterface_destroy(dynIntf); - CHECK_EQUAL(0, status); //Invalid meta type doesn't generate errors, just warnings - fclose(desc); desc=NULL; dynIntf=NULL; - - /* Invalid version section */ - desc = fopen("descriptors/invalids/invalidVersion.descriptor", "r"); - assert(desc != NULL); - status = dynInterface_parse(desc, &dynIntf); - //dynInterface_destroy(dynIntf); - CHECK_EQUAL(1, status); //Invalid meta type doesn't generate errors, just warnings - fclose(desc); desc=NULL; - - } -} - - -TEST_GROUP(DynInterfaceTests) { - void setup() { - int level = 1; - dynCommon_logSetup(stdLog, NULL, level); - dynType_logSetup(stdLog, NULL, level); - dynFunction_logSetup(stdLog, NULL, level); - dynInterface_logSetup(stdLog, NULL, level); - } -}; - -TEST(DynInterfaceTests, test1) { - test1(); -} - -TEST(DynInterfaceTests, test2) { - test2(); -} - -TEST(DynInterfaceTests, testInvalid) { - testInvalid(); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/dyn_message_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp deleted file mode 100644 index e310537..0000000 --- a/dfi/private/test/dyn_message_tests.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <assert.h> - -#include "dyn_common.h" -#include "dyn_message.h" - -#if defined(BSD) || defined(__APPLE__) -#include "open_memstream.h" -#include "fmemopen.h" -#endif - -static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - -static void checkMessageVersion(dyn_message_type* dynMsg, const char* v){ - int status = 0; - - char *version = NULL; - status = dynMessage_getVersionString(dynMsg, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL(v, version); - version_pt msgVersion = NULL, localMsgVersion = NULL; - int cmpVersion = -1; - version_createVersionFromString(version,&localMsgVersion); - status = dynMessage_getVersion(dynMsg,&msgVersion); - CHECK_EQUAL(0, status); - version_compareTo(msgVersion,localMsgVersion,&cmpVersion); - CHECK_EQUAL(cmpVersion,0); - version_destroy(localMsgVersion); - -} - - -static void msg_test1(void) { - int status = 0; - dyn_message_type *dynMsg = NULL; - FILE *desc = fopen("descriptors/msg_example1.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(0, status); - fclose(desc); - - char *name = NULL; - status = dynMessage_getName(dynMsg, &name); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("poi", name); - - checkMessageVersion(dynMsg,"1.0.0"); - - char *annVal = NULL; - status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("org.example.PointOfInterest", annVal); - - char *nonExist = NULL; - status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist); - CHECK(status != 0); - CHECK(nonExist == NULL); - - dyn_type *msgType = NULL; - status = dynMessage_getMessageType(dynMsg, &msgType); - CHECK_EQUAL(0, status); - CHECK(msgType != NULL); - - dynMessage_destroy(dynMsg); -} - - -static void msg_test2(void) { - int status = 0; - dyn_message_type *dynMsg = NULL; - FILE *desc = fopen("descriptors/msg_example2.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(0, status); - fclose(desc); - - char *name = NULL; - status = dynMessage_getName(dynMsg, &name); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("track", name); - - checkMessageVersion(dynMsg,"0.0.1"); - - char *annVal = NULL; - status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("org.example.Track", annVal); - - char *nonExist = NULL; - status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist); - CHECK(status != 0); - CHECK(nonExist == NULL); - - dyn_type *msgType = NULL; - status = dynMessage_getMessageType(dynMsg, &msgType); - CHECK_EQUAL(0, status); - CHECK(msgType != NULL); - - dynMessage_destroy(dynMsg); -} - -static void msg_test3(void) { - int status = 0; - dyn_message_type *dynMsg = NULL; - FILE *desc = fopen("descriptors/msg_example3.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(0, status); - fclose(desc); - - char *name = NULL; - status = dynMessage_getName(dynMsg, &name); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("logEntry", name); - - checkMessageVersion(dynMsg,"1.0.0"); - - char *annVal = NULL; - status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("org.example.LogEntry", annVal); - - char *nonExist = NULL; - status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist); - CHECK(status != 0); - CHECK(nonExist == NULL); - - dyn_type *msgType = NULL; - status = dynMessage_getMessageType(dynMsg, &msgType); - CHECK_EQUAL(0, status); - CHECK(msgType != NULL); - - dynMessage_destroy(dynMsg); -} - -static void msg_test4(void) { - int status = 0; - dyn_message_type *dynMsg = NULL; - FILE *desc = fopen("descriptors/msg_example4.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK(status != 0); - fclose(desc); -} - -static void msg_invalid(void) { - int status = 0; - dyn_message_type *dynMsg = NULL; - FILE *desc = fopen("descriptors/invalids/invalidMsgHdr.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - - desc = fopen("descriptors/invalids/invalidMsgMissingVersion.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - - desc = fopen("descriptors/invalids/invalidMsgInvalidSection.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - - desc = fopen("descriptors/invalids/invalidMsgInvalidName.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - - desc = fopen("descriptors/invalids/invalidMsgInvalidType.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - - desc = fopen("descriptors/invalids/invalidMsgInvalidVersion.descriptor", "r"); - assert(desc != NULL); - status = dynMessage_parse(desc, &dynMsg); - CHECK_EQUAL(1, status); - fclose(desc); - -} - -} - - -TEST_GROUP(DynMessageTests) { - void setup() { - int level = 1; - dynCommon_logSetup(stdLog, NULL, level); - dynType_logSetup(stdLog, NULL, level); - dynMessage_logSetup(stdLog, NULL, level); - } -}; - - -TEST(DynMessageTests, msg_test1) { - msg_test1(); -} - -TEST(DynMessageTests, msg_test2) { - msg_test2(); -} - -TEST(DynMessageTests, msg_test3) { - msg_test3(); -} - -TEST(DynMessageTests, msg_test4) { - msg_test4(); -} - -TEST(DynMessageTests, msg_invalid) { - msg_invalid(); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/dyn_type_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_type_tests.cpp b/dfi/private/test/dyn_type_tests.cpp deleted file mode 100644 index 52f9537..0000000 --- a/dfi/private/test/dyn_type_tests.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { - #include <stdarg.h> - - #include "dyn_common.h" - #include "dyn_type.h" - - static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); - } - - static void runTest(const char *descriptorStr, const char *exName) { - dyn_type *type; - type = NULL; - //printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr); - int status = dynType_parseWithStr(descriptorStr, exName, NULL, &type); - CHECK_EQUAL(0, status); - - //MEM check, to try to ensure no mem leaks/corruptions occur. - int i; - int j; - int nrOfBurst = 10; - int burst = 50; - void *pointers[burst]; - for (j = 0; j < nrOfBurst; j += 1) { - for (i = 0; i < burst ; i +=1 ) { - pointers[i] = NULL; - dynType_alloc(type, &pointers[i]); - } - for (i = 0; i < burst ; i +=1 ) { - dynType_free(type, pointers[i]); - } - } - - FILE *stream = fopen("/dev/null", "w"); - dynType_print(type, stream); - fclose(stream); - dynType_destroy(type); - //printf("--\n\n"); - } -} - -TEST_GROUP(DynTypeTests) { - void setup() { - dynType_logSetup(stdLog, NULL, 1); - } -}; - -#define EX1 "{BbJjIiSsDFNN arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12}" -#define EX2 "{D{DD b_1 b_2}I a b c}" -#define EX3 "Tsub={DD b_1 b_2};{DLsub;I a b c}" -#define EX4 "{[I numbers}" -#define EX5 "[[{DD{iii val3_1 val3_2 val3_3} val1 val2 val3}" -#define EX6 "Tsample={DD vala valb};Lsample;" -#define EX7 "Tsample={DD vala valb};[Lsample;" -#define EX8 "[Tsample={DD a b};Lsample;" -#define EX9 "*D" -#define EX10 "Tsample={DD a b};******Lsample;" -#define EX11 "Tsample=D;Lsample;" -#define EX12 "Tnode={Lnode;Lnode; left right};{Lnode; head}" //note recursive example -#define EX13 "Ttype={DDDDD a b c d e};{ltype;Ltype;ltype;Ltype; byVal1 byRef1 byVal2 ByRef2}" -#define EX14 "{DD{FF{JJ}{II*{ss}}}}" //unnamed fields -#define EX15 "Tsample={jDD time val1 val2};Tresult={jDlsample; time result sample};Lresult;" -#define EX16 "Tpoi={BDD id lat lon};Lpoi;" - -#define CREATE_EXAMPLES_TEST(DESC) \ - TEST(DynTypeTests, ParseTestExample ## DESC) { \ - runTest(DESC, #DESC); \ - } - -CREATE_EXAMPLES_TEST(EX1) -CREATE_EXAMPLES_TEST(EX2) -CREATE_EXAMPLES_TEST(EX3) -CREATE_EXAMPLES_TEST(EX4) -CREATE_EXAMPLES_TEST(EX5) -CREATE_EXAMPLES_TEST(EX6) -CREATE_EXAMPLES_TEST(EX7) -CREATE_EXAMPLES_TEST(EX8) -CREATE_EXAMPLES_TEST(EX9) -CREATE_EXAMPLES_TEST(EX10) -CREATE_EXAMPLES_TEST(EX11) -CREATE_EXAMPLES_TEST(EX12) -CREATE_EXAMPLES_TEST(EX13) -CREATE_EXAMPLES_TEST(EX14) -CREATE_EXAMPLES_TEST(EX15) -CREATE_EXAMPLES_TEST(EX16) - -TEST(DynTypeTests, ParseRandomGarbageTest) { - /* - unsigned int seed = 4148; - char *testRandom = getenv("DYN_TYPE_TEST_RANDOM"); - if (testRandom != NULL && strcmp("true", testRandom) == 0) { - seed = (unsigned int) time(NULL); - } - srandom(seed); - size_t nrOfTests = 100; - - printf("\nStarting test with random seed %i and nrOfTests %zu.\n", seed, nrOfTests); - - int i; - int k; - int c; - int sucesses = 0; - char descriptorStr[32]; - descriptorStr[31] = '\0'; - for(i = 0; i < nrOfTests; i += 1) { - for(k = 0; k < 31; k += 1) { - do { - c = (char) (((random() * 128) / RAND_MAX) - 1); - } while (!isprint(c)); - descriptorStr[k] = c; - if (c == '\0') { - break; - } - } - - //printf("ParseRandomGarbageTest iteration %i with descriptor string '%s'\n", k, descriptorStr); - dyn_type *type = NULL; - int status = dynType_parseWithStr(descriptorStr, NULL, NULL, &type); - if (status == 0) { - dynType_destroy(type); - } - } - */ -} - -TEST(DynTypeTests, AssignTest1) { - struct ex1 { - int32_t a; - int32_t b; - int32_t c; - }; - struct ex1 inst; - const char *desc = "{III a b c}"; - dyn_type *type = NULL; - int status = dynType_parseWithStr(desc, NULL, NULL, &type); - CHECK_EQUAL(0, status); - int32_t val1 = 2; - int32_t val2 = 4; - int32_t val3 = 8; - dynType_complex_setValueAt(type, 0, &inst, &val1); - CHECK_EQUAL(2, inst.a); - dynType_complex_setValueAt(type, 1, &inst, &val2); - CHECK_EQUAL(4, inst.b); - dynType_complex_setValueAt(type, 2, &inst, &val3); - CHECK_EQUAL(8, inst.c); - - dynType_destroy(type); -} - -TEST(DynTypeTests, AssignTest2) { - struct ex { - int32_t a; - struct { - double a; - double b; - } b; - }; - struct ex inst; - const char *desc = "{I{DD a b} a b}"; - dyn_type *type = NULL; - int status = dynType_parseWithStr(desc, NULL, NULL, &type); - CHECK_EQUAL(0, status); - int32_t a = 2; - double b_a = 1.1; - double b_b = 1.2; - - dynType_complex_setValueAt(type, 0, &inst, &a); - CHECK_EQUAL(2, inst.a); - - void *loc = NULL; - dyn_type *subType = NULL; - dynType_complex_valLocAt(type, 1, (void *)&inst, &loc); - dynType_complex_dynTypeAt(type, 1, &subType); - - dynType_complex_setValueAt(subType, 0, &inst.b, &b_a); - CHECK_EQUAL(1.1, inst.b.a); - - dynType_complex_setValueAt(subType, 1, &inst.b, &b_b); - CHECK_EQUAL(1.2, inst.b.b); - - dynType_destroy(type); -} - -TEST(DynTypeTests, AssignTest3) { - int simple = 1; - dyn_type *type = NULL; - int rc = dynType_parseWithStr("N", NULL, NULL, &type); - CHECK_EQUAL(0, rc); - - int newValue = 42; - void *loc = &simple; - void *input = &newValue; - dynType_simple_setValue(type, loc, input); - CHECK_EQUAL(42, simple); - dynType_destroy(type); -} - -TEST(DynTypeTests, MetaInfoTest) { - dyn_type *type = NULL; - int rc = 0; - rc = dynType_parseWithStr("#a=t;{DD#longname=longvalue;D a b c}", NULL, NULL, &type); - //rc = dynType_parseWithStr("{DDD a b c}", NULL, NULL, &type); - - CHECK_EQUAL(0, rc); - - const char *val = NULL; - val = dynType_getMetaInfo(type, "a"); - CHECK(val != NULL); - CHECK(strcmp("t", val) == 0); - - val = dynType_getMetaInfo(type, "longname"); - CHECK(val == NULL); - - val = dynType_getMetaInfo(type, "nonexisting"); - CHECK(val == NULL); - - dynType_destroy(type); -} - -TEST(DynTypeTests, SequenceWithPointerTest) { - struct val { - double a; - double b; - }; - - struct item { - int64_t a; - const char *text; - struct val val; - double c; - double d; - long e; - }; - - struct item_sequence { - uint32_t cap; - uint32_t len; - struct item **buf; - }; - - dyn_type *type = NULL; - int rc = 0; - rc = dynType_parseWithStr("Tval={DD a b};Titem={Jtlval;DDJ a text val c d e};**[Litem;", NULL, NULL, &type); - CHECK_EQUAL(0, rc); - - struct item_sequence *seq = NULL; - rc = dynType_alloc(type, (void **)&seq); - CHECK_EQUAL(0, rc); - CHECK(seq != NULL); - - dynType_free(type, seq); - - /* - - - struct item_sequence *items = (struct item_sequence *) calloc(1,sizeof(struct item_sequence)); - items->buf = (struct item **) calloc(2, sizeof(struct item *)); - items->cap = 2; - items->len = 2; - items->buf[0] = (struct item *)calloc(1, sizeof(struct item)); - items->buf[0]->text = strdup("boe"); - items->buf[1] = (struct item *)calloc(1, sizeof(struct item)); - items->buf[1]->text = strdup("boe2"); - - dynType_free(type, items); - */ - - dynType_destroy(type); -} - http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/json_rpc_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/json_rpc_tests.cpp b/dfi/private/test/json_rpc_tests.cpp deleted file mode 100644 index bff582e..0000000 --- a/dfi/private/test/json_rpc_tests.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include <float.h> -#include <assert.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include <ffi.h> - -#include "dyn_common.h" -#include "dyn_type.h" -#include "json_serializer.h" -#include "json_rpc.h" - -static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - - - void prepareTest(void) { - dyn_function_type *dynFunc = NULL; - int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc); - CHECK_EQUAL(0, rc); - - char *result = NULL; - - void *handle = NULL; - double arg1 = 1.0; - double arg2 = 2.0; - - void *args[4]; - args[0] = &handle; - args[1] = &arg1; - args[2] = &arg2; - - rc = jsonRpc_prepareInvokeRequest(dynFunc, "add", args, &result); - CHECK_EQUAL(0, rc); - - //printf("result is %s\n", result); - - STRCMP_CONTAINS("\"add\"", result); - STRCMP_CONTAINS("1.0", result); - STRCMP_CONTAINS("2.0", result); - - free(result); - dynFunction_destroy(dynFunc); - } - - void handleTestPre(void) { - dyn_function_type *dynFunc = NULL; - int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc); - CHECK_EQUAL(0, rc); - - const char *reply = "{\"r\":2.2}"; - double result = -1.0; - double *out = &result; - void *args[4]; - args[3] = &out; - rc = jsonRpc_handleReply(dynFunc, reply, args); - CHECK_EQUAL(0, rc); - //CHECK_EQUAL(2.2, result); - - dynFunction_destroy(dynFunc); - } - - int add(void*, double a, double b, double *result) { - *result = a + b; - return 0; - } - - int getName_example4(void*, char** result) { - *result = strdup("allocatedInFunction"); - return 0; - } - - struct tst_seq { - uint32_t cap; - uint32_t len; - double *buf; - }; - - - //StatsResult={DDD[D average min max input} - struct tst_StatsResult { - double average; - double min; - double max; - struct tst_seq input; - }; - - - int stats(void*, struct tst_seq input, struct tst_StatsResult **out) { - assert(out != NULL); - assert(*out == NULL); - double total = 0.0; - unsigned int count = 0; - double max = DBL_MIN; - double min = DBL_MAX; - - unsigned int i; - for (i = 0; i<input.len; i += 1) { - total += input.buf[i]; - count += 1; - if (input.buf[i] > max) { - max = input.buf[i]; - } - if (input.buf[i] < min) { - min = input.buf[i]; - } - } - - struct tst_StatsResult *result = (struct tst_StatsResult *) calloc(1, sizeof(*result)); - if(count>0){ - result->average = total / count; - } - result->min = min; - result->max = max; - double *buf = (double *)calloc(input.len, sizeof(double)); - memcpy(buf, input.buf, input.len * sizeof(double)); - result->input.len = input.len; - result->input.cap = input.len; - result->input.buf = buf; - - *out = result; - return 0; - } - - struct item { - double a; - double b; - }; - - struct item_seq { - uint32_t cap; - uint32_t len; - struct item **buf; - }; - - struct tst_serv { - void *handle; - int (*add)(void *, double, double, double *); - int (*sub)(void *, double, double, double *); - int (*sqrt)(void *, double, double *); - int (*stats)(void *, struct tst_seq, struct tst_StatsResult **); - }; - - struct tst_serv_example4 { - void *handle; - int (*getName_example4)(void *, char** name); - }; - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - - - - 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); - } - - - 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; - - if(func!=NULL){ // Check needed just to satisfy Coverity - rc = jsonRpc_handleReply(func, reply, args); - } - - STRCMP_EQUAL("this is a test string", result); - - free(result); - dynInterface_destroy(intf); - } - - -} - -TEST_GROUP(JsonRpcTests) { - void setup() { - int lvl = 1; - dynCommon_logSetup(stdLog, NULL, lvl); - dynType_logSetup(stdLog, NULL,lvl); - dynFunction_logSetup(stdLog, NULL,lvl); - dynInterface_logSetup(stdLog, NULL,lvl); - jsonSerializer_logSetup(stdLog, NULL, lvl); - jsonRpc_logSetup(stdLog, NULL, lvl); - - } -}; - - -TEST(JsonRpcTests, prepareTest) { - prepareTest(); -} - -TEST(JsonRpcTests, handleTestPre) { - handleTestPre(); -} - -TEST(JsonRpcTests, handleTestOut) { - handleTestOut(); -} - -TEST(JsonRpcTests, callPre) { - callTestPreAllocated(); -} - -TEST(JsonRpcTests, callOut) { - callTestOutput(); -} - -TEST(JsonRpcTests, handleOutSeq) { - handleTestOutputSequence(); -} - - - -TEST(JsonRpcTests, callTestOutChar) { - callTestOutChar(); -} - -TEST(JsonRpcTests, handleOutChar) { - handleTestOutChar(); -} - http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/json_serializer_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/json_serializer_tests.cpp b/dfi/private/test/json_serializer_tests.cpp deleted file mode 100644 index a52e4cc..0000000 --- a/dfi/private/test/json_serializer_tests.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include <ffi.h> - -#include "dyn_common.h" -#include "dyn_type.h" -#include "json_serializer.h" - -static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"}; - fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line); - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - -/*********** example 1 ************************/ -/** struct type ******************************/ -const char *example1_descriptor = "{DJISF a b c d e}"; - -const char *example1_input = "{ \ - \"a\" : 1.0, \ - \"b\" : 22, \ - \"c\" : 32, \ - \"d\" : 42, \ - \"e\" : 4.4 \ -}"; - -struct example1 { - double a; //0 - int64_t b; //1 - int32_t c; //2 - int16_t d; //3 - float e; //4 -}; - -static void check_example1(void *data) { - struct example1 *ex = (struct example1 *)data; - CHECK_EQUAL(1.0, ex->a); - LONGS_EQUAL(22, ex->b); - LONGS_EQUAL(32, ex->c); - LONGS_EQUAL(42, ex->d); - CHECK_EQUAL(4.4f, ex->e); -} - -/*********** example 2 ************************/ -const char *example2_descriptor = "{BJJDFD byte long1 long2 double1 float1 double2}"; - -const char *example2_input = "{ \ - \"byte\" : 42, \ - \"long1\" : 232, \ - \"long2\" : 242, \ - \"double1\" : 4.2, \ - \"float1\" : 3.2, \ - \"double2\" : 4.4 \ -}"; - -struct example2 { - char byte; //0 - int64_t long1; //1 - int64_t long2; //2 - double double1; //3 - float float1; //4 - double double2; //5 -}; - -static void check_example2(void *data) { - struct example2 *ex = (struct example2 *)data; - CHECK_EQUAL(42, ex->byte); - LONGS_EQUAL(232, ex->long1); - LONGS_EQUAL(242, ex->long2); - CHECK_EQUAL(4.2, ex->double1); - CHECK_EQUAL(3.2f, ex->float1); - CHECK_EQUAL(4.4, ex->double2); -} - - -/*********** example 3 ************************/ -/** sequence with a simple type **************/ -const char *example3_descriptor = "{[I numbers}"; - -const char *example3_input = "{ \ - \"numbers\" : [22,32,42] \ -}"; - -struct example3 { - struct { - uint32_t cap; - uint32_t len; - int32_t *buf; - } numbers; -}; - -static void check_example3(void *data) { - struct example3 *ex = (struct example3 *)data; - CHECK_EQUAL(3, ex->numbers.len); - CHECK_EQUAL(22, ex->numbers.buf[0]); - CHECK_EQUAL(32, ex->numbers.buf[1]); - CHECK_EQUAL(42, ex->numbers.buf[2]); -} - -/*********** example 4 ************************/ -/** structs within a struct (by reference)*******/ -const char *example4_descriptor = "{{IDD index val1 val2}{IDD index val1 val2} left right}"; - -static const char *example4_input = "{ \ - \"left\" : {\"index\":1, \"val1\":1.0, \"val2\":2.0 }, \ - \"right\" : {\"index\":2, \"val1\":5.0, \"val2\":4.0 } \ -}"; - -struct ex4_leaf { - int32_t index; - double val1; - double val2; -}; - -struct example4 { - struct ex4_leaf left; - struct ex4_leaf right; -}; - -static void check_example4(void *data) { - struct example4 *ex = (struct example4 *)data; - CHECK_EQUAL(1, ex->left.index); - CHECK_EQUAL(1.0, ex->left.val1); - CHECK_EQUAL(2.0, ex->left.val2); - CHECK_EQUAL(2, ex->right.index); - CHECK_EQUAL(5.0, ex->right.val1); - CHECK_EQUAL(4.0, ex->right.val2); -} - - -/*********** example 5 ************************/ -/** structs within a struct (by reference)*******/ -const char *example5_descriptor = "Tleaf={ts name age};Tnode={Lnode;Lnode;Lleaf; left right value};{Lnode; head}"; - -static const char *example5_input = "{ \ - \"head\" : {\ - \"left\" : {\ - \"value\" : {\ - \"name\" : \"John\",\ - \"age\" : 44 \ - }\ - },\ - \"right\" : {\ - \"value\" : {\ - \"name\" : \"Peter\", \ - \"age\" : 55 \ - }\ - }\ - }\ -}"; - -struct leaf { - const char *name; - uint16_t age; -}; - -struct node { - struct node *left; - struct node *right; - struct leaf *value; -}; - -struct example5 { - struct node *head; -}; - -static void check_example5(void *data) { - struct example5 *ex = (struct example5 *)data; - CHECK_TRUE(ex->head != NULL); - - CHECK(ex->head->left != NULL); - CHECK(ex->head->left->value != NULL); - STRCMP_EQUAL("John", ex->head->left->value->name); - CHECK_EQUAL(44, ex->head->left->value->age); - CHECK(ex->head->left->left == NULL); - CHECK(ex->head->left->right == NULL); - - CHECK(ex->head->right != NULL); - CHECK(ex->head->right->value != NULL); - STRCMP_EQUAL("Peter", ex->head->right->value->name); - CHECK_EQUAL(55, ex->head->right->value->age); - CHECK(ex->head->right->left == NULL); - CHECK(ex->head->right->right == NULL); -} - -static const char *example6_descriptor = "Tsample={DD v1 v2};[lsample;"; - -static const char *example6_input = "[{\"v1\":0.1,\"v2\":0.2},{\"v1\":1.1,\"v2\":1.2},{\"v1\":2.1,\"v2\":2.2}]"; - -struct ex6_sample { - double v1; - double v2; -}; - -struct ex6_sequence { - uint32_t cap; - uint32_t len; - struct ex6_sample *buf; -}; - -static void check_example6(struct ex6_sequence seq) { - CHECK_EQUAL(3, seq.cap); - CHECK_EQUAL(3, seq.len); - CHECK_EQUAL(0.1, seq.buf[0].v1); - CHECK_EQUAL(0.2, seq.buf[0].v2); - CHECK_EQUAL(1.1, seq.buf[1].v1); - CHECK_EQUAL(1.2, seq.buf[1].v2); - CHECK_EQUAL(2.1, seq.buf[2].v1); - CHECK_EQUAL(2.2, seq.buf[2].v2); -} - - -/*********** example 7 ************************/ -const char *example7_descriptor = "{t a}"; - -const char *example7_input = "{ \ - \"a\" : \"apache celix\" \ -}"; - -struct example7 { - char* a; //0 -}; - -static void check_example7(void *data) { - struct example7 *ex = (struct example7 *)data; - STRCMP_EQUAL("apache celix", ex->a); -} - - -/*********** example 8 ************************/ - -const char *example8_descriptor = "{ZbijNP a b c d e f}"; - -const char *example8_input = "{ \ - \"a\" : true, \ - \"b\" : 4, \ - \"c\" : 8, \ - \"d\" : 16, \ - \"e\" : 32 \ -}"; - -struct example8 { - bool a; - unsigned char b; - uint32_t c; - uint64_t d; - int e; - void* f; -}; - -static void check_example8(void *data) { - struct example8 *ex = (struct example8 *)data; - CHECK_EQUAL(true,ex->a); - CHECK_EQUAL(4,ex->b); - CHECK_EQUAL(8,ex->c); - //error on mac CHECK_EQUAL(16,ex->d); - CHECK(16 == ex->d) - CHECK_EQUAL(32,ex->e); -} - - -static void parseTests(void) { - dyn_type *type; - void *inst; - int rc; - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example1_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example1_input, &inst); - CHECK_EQUAL(0, rc); - check_example1(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example2_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example2_input, &inst); - CHECK_EQUAL(0, rc); - check_example2(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example3_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example3_input, &inst); - CHECK_EQUAL(0, rc); - check_example3(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example4_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example4_input, &inst); - CHECK_EQUAL(0, rc); - check_example4(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example5_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example5_input, &inst); - CHECK_EQUAL(0, rc); - check_example5(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - struct ex6_sequence *seq; - rc = dynType_parseWithStr(example6_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example6_input, (void **)&seq); - CHECK_EQUAL(0, rc); - check_example6((*seq)); - dynType_free(type, seq); - dynType_destroy(type); - - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example7_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example7_input, &inst); - CHECK_EQUAL(0, rc); - check_example7(inst); - dynType_free(type, inst); - dynType_destroy(type); - - type = NULL; - inst = NULL; - rc = dynType_parseWithStr(example8_descriptor, NULL, NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_deserialize(type, example8_input, &inst); - CHECK_EQUAL(0, rc); - check_example8(inst); - dynType_free(type, inst); - dynType_destroy(type); -} - -const char *write_example1_descriptor = "{BSIJsijFDNZb a b c d e f g h i j k l}"; - -struct write_example1 { - char a; - int16_t b; - int32_t c; - int64_t d; - uint16_t e; - uint32_t f; - uint64_t g; - float h; - double i; - int j; - bool k; - unsigned char l; -}; - -void writeTest1(void) { - struct write_example1 ex1; - ex1.a=1; - ex1.b=2; - ex1.c=3; - ex1.d=4; - ex1.e=5; - ex1.f=6; - ex1.g=7; - ex1.h=8.8f; - ex1.i=9.9; - ex1.j=10; - ex1.k=true; - ex1.l=12; - - dyn_type *type = NULL; - char *result = NULL; - int rc = dynType_parseWithStr(write_example1_descriptor, "ex1", NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_serialize(type, &ex1, &result); - CHECK_EQUAL(0, rc); - STRCMP_CONTAINS("\"a\":1", result); - STRCMP_CONTAINS("\"b\":2", result); - STRCMP_CONTAINS("\"c\":3", result); - STRCMP_CONTAINS("\"d\":4", result); - STRCMP_CONTAINS("\"e\":5", result); - STRCMP_CONTAINS("\"f\":6", result); - STRCMP_CONTAINS("\"g\":7", result); - STRCMP_CONTAINS("\"h\":8.8", result); - STRCMP_CONTAINS("\"i\":9.9", result); - STRCMP_CONTAINS("\"j\":10", result); - STRCMP_CONTAINS("\"k\":true", result); - STRCMP_CONTAINS("\"l\":12", result); - //printf("example 1 result: '%s'\n", result); - dynType_destroy(type); - free(result); -} - -const char *write_example2_descriptor = "{*{JJ a b}{SS c d} sub1 sub2}"; - -struct write_example2_sub { - int64_t a; - int64_t b; -}; - -struct write_example2 { - struct write_example2_sub *sub1; - struct { - int16_t c; - int16_t d; - } sub2; -}; - -void writeTest2(void) { - struct write_example2_sub sub1; - sub1.a = 1; - sub1.b = 2; - - struct write_example2 ex; - ex.sub1=&sub1; - ex.sub2.c = 3; - ex.sub2.d = 4; - - dyn_type *type = NULL; - char *result = NULL; - int rc = dynType_parseWithStr(write_example2_descriptor, "ex2", NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_serialize(type, &ex, &result); - CHECK_EQUAL(0, rc); - STRCMP_CONTAINS("\"a\":1", result); - STRCMP_CONTAINS("\"b\":2", result); - STRCMP_CONTAINS("\"c\":3", result); - STRCMP_CONTAINS("\"d\":4", result); - //printf("example 2 result: '%s'\n", result); - dynType_destroy(type); - free(result); -} - -const char *write_example3_descriptor = "Tperson={ti name age};[Lperson;"; - -struct write_example3_person { - const char *name; - uint32_t age; -}; - -struct write_example3 { - uint32_t cap; - uint32_t len; - struct write_example3_person **buf; -}; - -void writeTest3(void) { - struct write_example3_person p1; - p1.name = "John"; - p1.age = 33; - - struct write_example3_person p2; - p2.name = "Peter"; - p2.age = 44; - - struct write_example3_person p3; - p3.name = "Carol"; - p3.age = 55; - - struct write_example3_person p4; - p4.name = "Elton"; - p4.age = 66; - - struct write_example3 seq; - seq.buf = (struct write_example3_person **) calloc(4, sizeof(void *)); - seq.len = seq.cap = 4; - seq.buf[0] = &p1; - seq.buf[1] = &p2; - seq.buf[2] = &p3; - seq.buf[3] = &p4; - - dyn_type *type = NULL; - char *result = NULL; - int rc = dynType_parseWithStr(write_example3_descriptor, "ex3", NULL, &type); - CHECK_EQUAL(0, rc); - rc = jsonSerializer_serialize(type, &seq, &result); - CHECK_EQUAL(0, rc); - STRCMP_CONTAINS("\"age\":33", result); - STRCMP_CONTAINS("\"age\":44", result); - STRCMP_CONTAINS("\"age\":55", result); - STRCMP_CONTAINS("\"age\":66", result); - //printf("example 3 result: '%s'\n", result); - free(seq.buf); - dynType_destroy(type); - free(result); -} - - - -} - -TEST_GROUP(JsonSerializerTests) { - void setup() { - int lvl = 1; - dynCommon_logSetup(stdLog, NULL, lvl); - dynType_logSetup(stdLog, NULL,lvl); - jsonSerializer_logSetup(stdLog, NULL, lvl); - } -}; - -TEST(JsonSerializerTests, ParseTests) { - //TODO split up - parseTests(); -} - -TEST(JsonSerializerTests, WriteTest1) { - writeTest1(); -} - -TEST(JsonSerializerTests, WriteTest2) { - writeTest2(); -} - -TEST(JsonSerializerTests, WriteTest3) { - writeTest3(); -} - - http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/run_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/run_tests.cpp b/dfi/private/test/run_tests.cpp deleted file mode 100644 index 786f4bf..0000000 --- a/dfi/private/test/run_tests.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -int main(int argc, char** argv) { - return RUN_ALL_TESTS(argc, argv); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/complex.avdl ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/complex.avdl b/dfi/private/test/schemas/complex.avdl deleted file mode 100644 index eff1fd8..0000000 --- a/dfi/private/test/schemas/complex.avdl +++ /dev/null @@ -1,30 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - -protocol Complex { - - record StatResult { - double sum; - double min; - double max; - array<double> input; - } - - StatResult stats(array<double> input); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/complex.avpr ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/complex.avpr b/dfi/private/test/schemas/complex.avpr deleted file mode 100644 index ca39b56..0000000 --- a/dfi/private/test/schemas/complex.avpr +++ /dev/null @@ -1,55 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - -{ - "protocol" : "Complex", - "namespace" : null, - "types" : [ { - "type" : "record", - "name" : "StatResult", - "fields" : [ { - "name" : "sum", - "type" : "double" - }, { - "name" : "min", - "type" : "double" - }, { - "name" : "max", - "type" : "double" - }, { - "name" : "input", - "type" : { - "type" : "array", - "items" : "double" - } - } ] - } ], - "messages" : { - "stats" : { - "request" : [ { - "name" : "input", - "type" : { - "type" : "array", - "items" : "double" - } - } ], - "response" : "StatResult" - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/invalid1.avpr ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/invalid1.avpr b/dfi/private/test/schemas/invalid1.avpr deleted file mode 100644 index bbf77ee..0000000 --- a/dfi/private/test/schemas/invalid1.avpr +++ /dev/null @@ -1,47 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -{ - "protocol" : "Complex", - "namespace" : null, - "types" : [ { - "type" : "record", - "name" : "StatResult", - "fields" : [ { - "name" : "sum", - "type" : "double" - }, { - "name" : "min", - "type" : "double" - }, { - "name" : "max", - "type" : "double" - }, { - "name" : "input", - "type" : { - "type" : "array", - "items" : "double" - } - } ] - } ], - "messages" : { - "stats" : { - "response" : "StatResult" - } - } -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/invalid2.avpr ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/invalid2.avpr b/dfi/private/test/schemas/invalid2.avpr deleted file mode 100644 index 9eb9209..0000000 --- a/dfi/private/test/schemas/invalid2.avpr +++ /dev/null @@ -1,49 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - { - "protocol" : "Simple", - "types" : [ ], - "messages" : { - "sum" : { - "request" : [ { - "name" : "a" - }, { - "name" : "b", - "type" : "double" - } ], - "response" : "double" - }, - "sub" : { - "request" : [ { - "name" : "a", - "type" : "double" - }, { - "name" : "b", - "type" : "double" - } ], - "response" : "double" - }, - "sqrt" : { - "request" : [ { - "name" : "a" - } ], - "response" : "double" - } - } -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/simple.avdl ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/simple.avdl b/dfi/private/test/schemas/simple.avdl deleted file mode 100644 index a03e352..0000000 --- a/dfi/private/test/schemas/simple.avdl +++ /dev/null @@ -1,24 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - @namespace("org.apache.avro.test") -protocol Simple { - double sum(double a, double b); - double sub(double a, double b); - double sqrt(double a); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/simple.avpr ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/simple.avpr b/dfi/private/test/schemas/simple.avpr deleted file mode 100644 index 4910346..0000000 --- a/dfi/private/test/schemas/simple.avpr +++ /dev/null @@ -1,51 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - { - "protocol" : "Simple", - "types" : [ ], - "messages" : { - "sum" : { - "request" : [ { - "name" : "a", - "type" : "double" - }, { - "name" : "b", - "type" : "double" - } ], - "response" : "double" - }, - "sub" : { - "request" : [ { - "name" : "a", - "type" : "double" - }, { - "name" : "b", - "type" : "double" - } ], - "response" : "double" - }, - "sqrt" : { - "request" : [ { - "name" : "a", - "type" : "double" - } ], - "response" : "double" - } - } -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/private/test/schemas/simple_min.avpr ---------------------------------------------------------------------- diff --git a/dfi/private/test/schemas/simple_min.avpr b/dfi/private/test/schemas/simple_min.avpr deleted file mode 100644 index f5c6673..0000000 --- a/dfi/private/test/schemas/simple_min.avpr +++ /dev/null @@ -1,19 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - {"protocol":"Simple","types":[],"messages":{"sum":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sub":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sqrt":{"request":[{"name":"a","type":"double"}],"response":"double"}}} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dfi_log_util.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dfi_log_util.h b/dfi/public/include/dfi_log_util.h deleted file mode 100644 index 2bcd8fa..0000000 --- a/dfi/public/include/dfi_log_util.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#ifndef _DFI_LOG_UTIL_H_ -#define _DFI_LOG_UTIL_H_ - -typedef void (*logf_ft)(void *handle, int level, const char *file, int line, const char *format, ...); - -#define DFI_SETUP_LOG_HEADER(cmp) \ - void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel); - -#define DFI_SETUP_LOG(cmp) \ - static logf_ft g_logf = NULL; \ - static void *g_logHandle = NULL; \ - static int g_currentLogLevel = 1; \ - \ - void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel) { \ - g_currentLogLevel = currentLogLevel; \ - g_logHandle = handle; \ - g_logf = logf; \ - } - -#define LOG_LVL_ERROR 1 -#define LOG_LVL_WARNING 2 -#define LOG_LVL_INFO 3 -#define LOG_LVL_DEBUG 4 - -#define LOG_ERROR(msg, ...) \ - if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_ERROR) { \ - g_logf(g_logHandle, LOG_LVL_ERROR, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \ - } - -#define LOG_WARNING(msg, ...) \ - if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_WARNING) { \ - g_logf(g_logHandle, LOG_LVL_WARNING, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \ - } - -#define LOG_INFO(msg, ...) \ - if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_INFO) { \ - g_logf(g_logHandle, LOG_LVL_INFO, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \ - } - -#define LOG_DEBUG(msg, ...) \ - if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_DEBUG) { \ - g_logf(g_logHandle, LOG_LVL_DEBUG, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \ - } - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dyn_common.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_common.h b/dfi/public/include/dyn_common.h deleted file mode 100644 index 6ec236f..0000000 --- a/dfi/public/include/dyn_common.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#ifndef _DYN_COMMON_H_ -#define _DYN_COMMON_H_ - -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <sys/queue.h> - -#include "dfi_log_util.h" - -//logging -DFI_SETUP_LOG_HEADER(dynCommon); - -TAILQ_HEAD(namvals_head, namval_entry); - -struct namval_entry { - char *name; - char *value; - TAILQ_ENTRY(namval_entry) entries; -}; - -int dynCommon_parseName(FILE *stream, char **result); -int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result); -int dynCommon_parseNameValue(FILE *stream, char **name, char **value); -int dynCommon_eatChar(FILE *stream, int c); - -void dynCommon_clearNamValHead(struct namvals_head *head); - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dyn_function.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_function.h b/dfi/public/include/dyn_function.h deleted file mode 100644 index 7f5cd57..0000000 --- a/dfi/public/include/dyn_function.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#ifndef __DYN_FUNCTION_H_ -#define __DYN_FUNCTION_H_ - -#include "dyn_type.h" -#include "dfi_log_util.h" - -/** - * Uses the following schema - * (Name)([Type]*)Type - * - * Dyn fynction argument meta (am) as meta info, with the following possible values - * am=handle #void pointer for the handle - * am=pre #output pointer with memory preallocated - * am=out #output pointer - */ - -typedef struct _dyn_function_type dyn_function_type; - -DFI_SETUP_LOG_HEADER(dynFunction); - -enum dyn_function_argument_meta { - DYN_FUNCTION_ARGUMENT_META__STD = 0, - DYN_FUNCTION_ARGUMENT_META__HANDLE = 1, - DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT = 2, - DYN_FUNCTION_ARGUMENT_META__OUTPUT = 3 -}; - -int dynFunction_parse(FILE *descriptorStream, struct types_head *refTypes, dyn_function_type **dynFunc); -int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes, dyn_function_type **dynFunc); - -int dynFunction_nrOfArguments(dyn_function_type *dynFunc); -dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr); -enum dyn_function_argument_meta dynFunction_argumentMetaForIndex(dyn_function_type *dynFunc, int argumentNr); -dyn_type * dynFunction_returnType(dyn_function_type *dynFunction); - -void dynFunction_destroy(dyn_function_type *dynFunc); -int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues); - -int dynFunction_createClosure(dyn_function_type *func, void (*bind)(void *, void **, void*), void *userData, void(**fn)(void)); -int dynFunction_getFnPointer(dyn_function_type *func, void (**fn)(void)); - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dyn_interface.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_interface.h b/dfi/public/include/dyn_interface.h deleted file mode 100644 index 54bf41c..0000000 --- a/dfi/public/include/dyn_interface.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#ifndef __DYN_INTERFACE_H_ -#define __DYN_INTERFACE_H_ - -#include "dyn_common.h" -#include "dyn_type.h" -#include "dyn_function.h" -#include "dfi_log_util.h" - -#include "version.h" - -DFI_SETUP_LOG_HEADER(dynInterface); - -/* Description string - * - * Descriptor (interface) = HeaderSection AnnotationSection TypesSection MethodsSection - * - * HeaderSection= - * ':header\n' [NameValue]* - * ':annotations\n' [NameValue]* - * ':types\n' [TypeIdValue]* - * ':methods\n' [MethodIdValue] - * - */ -typedef struct _dyn_interface_type dyn_interface_type; - -TAILQ_HEAD(methods_head, method_entry); -struct method_entry { - int index; - char *id; - char *name; - dyn_function_type *dynFunc; - - TAILQ_ENTRY(method_entry) entries; -}; - -int dynInterface_parse(FILE *descriptor, dyn_interface_type **out); -void dynInterface_destroy(dyn_interface_type *intf); - -int dynInterface_getName(dyn_interface_type *intf, char **name); -int dynInterface_getVersion(dyn_interface_type *intf, version_pt* version); -int dynInterface_getVersionString(dyn_interface_type *intf, char **version); -int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value); -int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value); -int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list); -int dynInterface_nrOfMethods(dyn_interface_type *intf); - - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dyn_message.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_message.h b/dfi/public/include/dyn_message.h deleted file mode 100644 index d1c8dd7..0000000 --- a/dfi/public/include/dyn_message.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -#ifndef __DYN_MESSAGE_H_ -#define __DYN_MESSAGE_H_ - -#include "dyn_common.h" -#include "dyn_type.h" -#include "dfi_log_util.h" - -#include "version.h" - -DFI_SETUP_LOG_HEADER(dynMessage); - -/* Description string - * - * Descriptor (message) = HeaderSection AnnotationSection TypesSection MessageSection - * - * HeaderSection= - * ':header\n' [NameValue]* - * ':annotations\n' [NameValue]* - * ':types\n' [TypeIdValue]* - * ':message\n' [MessageIdValue] - * - */ -typedef struct _dyn_message_type dyn_message_type; - - -int dynMessage_parse(FILE *descriptor, dyn_message_type **out); -void dynMessage_destroy(dyn_message_type *msg); - -int dynMessage_getName(dyn_message_type *msg, char **name); -int dynMessage_getVersion(dyn_message_type *msg, version_pt* version); -int dynMessage_getVersionString(dyn_message_type *msg, char **version); -int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value); -int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value); -int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type); - - - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/dfi/public/include/dyn_type.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_type.h b/dfi/public/include/dyn_type.h deleted file mode 100644 index 554966a..0000000 --- a/dfi/public/include/dyn_type.h +++ /dev/null @@ -1,155 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ - -#ifndef _DYN_TYPE_H_ -#define _DYN_TYPE_H_ - -#include <stdio.h> -#include <sys/queue.h> -#include <stdbool.h> - -#include <stdint.h> - -#include "dfi_log_util.h" - -#if defined(BSD) || defined(__APPLE__) || defined(__ANDROID__) -#include "memstream/open_memstream.h" -#include "memstream/fmemopen.h" -#endif - -/* Description string - * - * Type = [TypeDef]* (MetaInfo)* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference ) [TypeDef]* - * Name = alpha[(alpha|numeric)*] - * SPACE = ' ' - * - * SimplesTypes (based on java bytecode method signatures) - * //Java based: - * B char - * C (not supported) - * D double - * F float - * I int32_t - * J int64_t - * S int16_t - * V void - * Z boolean - * //Extended - * b unsigned char - * i uint32_t - * j uint62_t - * s uint64_t - * P untyped pointer (void *) - * t char* string - * N native int - * - * ComplexTypes (Struct) - * {[Type]+ [(Name)(SPACE)]+} - * - * ReferenceByValue - * l(name); - * - * PointerReference -> note shortcut for *l(name); - * L(Name); - * - * TypeDef - * T(Name)=Type; - * - * SequenceType - * [(Type) - * - * TypedPointer - * *(Type) - * - * MetaInfo TODO - * #Name=Value; - * - * - * - * examples - * "{DDII a b c d}" -> struct { double a; double b; int c; int d; }; - * "{DD{FF c1 c2} a b c}" -> struct { double a; double b; struct c { float c1; float c2; }; }; - * - * - */ - -#define DYN_TYPE_INVALID 0 -#define DYN_TYPE_SIMPLE 1 -#define DYN_TYPE_COMPLEX 2 -#define DYN_TYPE_SEQUENCE 3 -#define DYN_TYPE_TYPED_POINTER 4 -#define DYN_TYPE_TEXT 5 -#define DYN_TYPE_REF 6 - -typedef struct _dyn_type dyn_type; - -TAILQ_HEAD(types_head, type_entry); -struct type_entry { - dyn_type *type; - TAILQ_ENTRY(type_entry) entries; -}; - -TAILQ_HEAD(complex_type_entries_head, complex_type_entry); -struct complex_type_entry { - dyn_type *type; - char *name; - TAILQ_ENTRY(complex_type_entry) entries; -}; - -//logging -DFI_SETUP_LOG_HEADER(dynType); - -//generic -int dynType_parse(FILE *descriptorStream, const char *name, struct types_head *refTypes, dyn_type **type); -int dynType_parseWithStr(const char *descriptor, const char *name, struct types_head *refTypes, dyn_type **type); -void dynType_destroy(dyn_type *type); - -int dynType_alloc(dyn_type *type, void **bufLoc); -void dynType_free(dyn_type *type, void *loc); - -void dynType_print(dyn_type *type, FILE *stream); -size_t dynType_size(dyn_type *type); -int dynType_type(dyn_type *type); -int dynType_descriptorType(dyn_type *type); -const char * dynType_getMetaInfo(dyn_type *type, const char *name); - -//complexType -int dynType_complex_indexForName(dyn_type *type, const char *name); -int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **subType); -int dynType_complex_setValueAt(dyn_type *type, int index, void *inst, void *in); -int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **valLoc); -int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries); - -//sequence -int dynType_sequence_alloc(dyn_type *type, void *inst, uint32_t cap); -int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index, void **valLoc); -int dynType_sequence_increaseLengthAndReturnLastLoc(dyn_type *type, void *seqLoc, void **valLoc); -dyn_type * dynType_sequence_itemType(dyn_type *type); -uint32_t dynType_sequence_length(void *seqLoc); - -//typed pointer -int dynType_typedPointer_getTypedType(dyn_type *type, dyn_type **typedType); - -//text -int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value); - -//simple -void dynType_simple_setValue(dyn_type *type, void *inst, void *in); - -#endif
