CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/a129b488 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/a129b488 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/a129b488 Branch: refs/heads/develop Commit: a129b4884451d7347749faa43915dcc8452e14b8 Parents: 2522330 Author: Pepijn Noltes <[email protected]> Authored: Thu Aug 13 11:08:56 2015 +0200 Committer: Pepijn Noltes <[email protected]> Committed: Thu Aug 13 11:08:56 2015 +0200 ---------------------------------------------------------------------- remote_services/CMakeLists.txt | 1 - .../public/include/endpoint_listener.h | 48 -- .../public/include/endpoint_listener.h | 48 ++ .../public/include/remote_constants.h | 38 + .../remote_service_admin_dfi/CMakeLists.txt | 75 +- .../dynamic_function_interface/CMakeLists.txt | 37 +- .../avro_descriptor_translator.c | 319 -------- .../descriptor_translator.h | 18 - .../descriptors/example1.descriptor | 13 - .../schemas/complex.avdl | 11 - .../schemas/complex.avpr | 36 - .../schemas/invalid1.avpr | 29 - .../schemas/invalid2.avpr | 31 - .../schemas/simple.avdl | 6 - .../schemas/simple.avpr | 33 - .../schemas/simple_min.avpr | 1 - .../tst/avro_descriptor_translator_tests.cpp | 164 ---- .../tst/dyn_closure_tests.cpp | 146 ---- .../tst/dyn_function_tests.cpp | 231 ------ .../tst/dyn_interface_tests.cpp | 87 --- .../tst/dyn_type_tests.cpp | 190 ----- .../tst/json_serializer_tests.cpp | 398 ---------- .../tst/run_tests.cpp | 9 - .../CMakeLists.txt | 26 + .../avro_descriptor_translator_tests.cpp | 164 ++++ .../descriptors/example1.descriptor | 13 + .../dyn_closure_tests.cpp | 146 ++++ .../dyn_function_tests.cpp | 231 ++++++ .../dyn_interface_tests.cpp | 87 +++ .../dyn_type_tests.cpp | 190 +++++ .../json_serializer_tests.cpp | 398 ++++++++++ .../run_tests.cpp | 9 + .../schemas/complex.avdl | 11 + .../schemas/complex.avpr | 36 + .../schemas/invalid1.avpr | 29 + .../schemas/invalid2.avpr | 31 + .../schemas/simple.avdl | 6 + .../schemas/simple.avpr | 33 + .../schemas/simple_min.avpr | 1 + .../private/include/export_registration_dfi.h | 21 - .../private/include/import_registration_dfi.h | 25 - .../include/remote_service_admin_http_impl.h | 73 -- .../private/src/export_registration_dfi.c | 239 ------ .../private/src/import_registration_dfi.c | 318 -------- .../src/remote_service_admin_activator.c | 122 --- .../private/src/remote_service_admin_dfi.c | 747 ------------------- .../remote_service_admin_dfi/rsa/CMakeLists.txt | 45 ++ .../private/include/export_registration_dfi.h | 21 + .../private/include/import_registration_dfi.h | 25 + .../include/remote_service_admin_http_impl.h | 73 ++ .../rsa/private/src/export_registration_dfi.c | 239 ++++++ .../rsa/private/src/import_registration_dfi.c | 318 ++++++++ .../src/remote_service_admin_activator.c | 122 +++ .../rsa/private/src/remote_service_admin_dfi.c | 747 +++++++++++++++++++ .../rsa_tst/CMakeLists.txt | 47 ++ .../rsa_tst/bundle/CMakeLists.txt | 24 + .../rsa_tst/bundle/tst_activator.c | 137 ++++ .../rsa_tst/bundle/tst_service.h | 17 + .../rsa_tst/client.properties.in | 8 + .../rsa_tst/config.properties.in | 3 + .../rsa_tst/rsa_client_server_tests.cpp | 113 +++ .../rsa_tst/rsa_tests.cpp | 201 +++++ .../rsa_tst/run_tests.cpp | 9 + .../rsa_tst/server.properties.in | 8 + .../remote_service_admin_dfi/tst/CMakeLists.txt | 47 -- .../tst/bundle/CMakeLists.txt | 25 - .../tst/bundle/tst_activator.c | 137 ---- .../tst/bundle/tst_service.h | 17 - .../tst/client.properties.in | 8 - .../tst/config.properties.in | 3 - .../tst/rsa_client_server_tests.cpp | 113 --- .../remote_service_admin_dfi/tst/rsa_tests.cpp | 201 ----- .../remote_service_admin_dfi/tst/run_tests.cpp | 9 - .../tst/server.properties.in | 8 - .../utils/public/include/remote_constants.h | 38 - 75 files changed, 3680 insertions(+), 4008 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt index f39b604..abc9177 100644 --- a/remote_services/CMakeLists.txt +++ b/remote_services/CMakeLists.txt @@ -39,7 +39,6 @@ if (REMOTE_SERVICE_ADMIN) add_subdirectory(remote_service_admin) add_subdirectory(remote_service_admin_http) - add_subdirectory(remote_service_admin_dfi/tst/bundle) add_subdirectory(remote_service_admin_dfi) add_subdirectory(remote_service_admin_shm) http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/endpoint_listener/public/include/endpoint_listener.h ---------------------------------------------------------------------- diff --git a/remote_services/endpoint_listener/public/include/endpoint_listener.h b/remote_services/endpoint_listener/public/include/endpoint_listener.h deleted file mode 100644 index ccf52a8..0000000 --- a/remote_services/endpoint_listener/public/include/endpoint_listener.h +++ /dev/null @@ -1,48 +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. - */ -/* - * endpoint_listener.h - * - * \date Sep 29, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef ENDPOINT_LISTENER_H_ -#define ENDPOINT_LISTENER_H_ - -#include "array_list.h" -#include "properties.h" - -#include "endpoint_description.h" - -static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener"; - -static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope"; - -struct endpoint_listener { - void *handle; - celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter); - celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter); -}; - -typedef struct endpoint_listener *endpoint_listener_pt; - - -#endif /* ENDPOINT_LISTENER_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin/public/include/endpoint_listener.h ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin/public/include/endpoint_listener.h b/remote_services/remote_service_admin/public/include/endpoint_listener.h new file mode 100644 index 0000000..ccf52a8 --- /dev/null +++ b/remote_services/remote_service_admin/public/include/endpoint_listener.h @@ -0,0 +1,48 @@ +/** + *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. + */ +/* + * endpoint_listener.h + * + * \date Sep 29, 2011 + * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ + +#ifndef ENDPOINT_LISTENER_H_ +#define ENDPOINT_LISTENER_H_ + +#include "array_list.h" +#include "properties.h" + +#include "endpoint_description.h" + +static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener"; + +static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope"; + +struct endpoint_listener { + void *handle; + celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter); + celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter); +}; + +typedef struct endpoint_listener *endpoint_listener_pt; + + +#endif /* ENDPOINT_LISTENER_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin/public/include/remote_constants.h ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin/public/include/remote_constants.h b/remote_services/remote_service_admin/public/include/remote_constants.h new file mode 100644 index 0000000..0736685 --- /dev/null +++ b/remote_services/remote_service_admin/public/include/remote_constants.h @@ -0,0 +1,38 @@ +/** + *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. + */ +/* + * remote_constants.h + * + * \date Sep 30, 2011 + * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ + +#ifndef REMOTE_CONSTANTS_H_ +#define REMOTE_CONSTANTS_H_ + +static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces"; +static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid"; +static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id"; +static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id"; +static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported"; +static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs"; +static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location"; + +#endif /* REMOTE_CONSTANTS_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/CMakeLists.txt b/remote_services/remote_service_admin_dfi/CMakeLists.txt index 83dfc41..ccd01f9 100644 --- a/remote_services/remote_service_admin_dfi/CMakeLists.txt +++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt @@ -1,65 +1,36 @@ -# 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. + + celix_subproject(RSA_REMOTE_SERVICE_ADMIN_DFI "Option to enable building the Remote Service Admin Service DFI" OFF) + if (RSA_REMOTE_SERVICE_ADMIN_DFI) + find_package(CURL REQUIRED) find_package(Jansson REQUIRED) find_package(FFI REQUIRED) + #TODO if test + find_package(CppUTest REQUIRED) - add_subdirectory(dynamic_function_interface) - - include_directories(private/include) - - include_directories(${FFI_INCLUDE_DIRS}) - include_directories(${CURL_INCLUDE_DIRS}) - include_directories(${JANSSON_INCLUDE_DIRS}) - - include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") - - include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include") + include_directories( + ${CURL_INCLUDE_DIRS} + ${JANSSON_INCLUDE_DIRS} + ${FFI_INCLUDE_DIRS} + ) - include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include") - include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include") + if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + include_directories(dynamic_function_interface/memstream) + endif() - include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include") - include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include") + #TODO if test + include_directories(${CPPUTEST_INCLUDE_DIR}) - include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include") - include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface") - include_directories("${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include") - - SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi") - SET(BUNDLE_VERSION "0.0.1") - SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin Dynamic Function Interface (DFI)") - - bundle(remote_service_admin_dfi SOURCES - private/src/remote_service_admin_dfi.c - private/src/remote_service_admin_activator.c - private/src/export_registration_dfi.c - private/src/import_registration_dfi.c - ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c - ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c - ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c - ) - target_link_libraries(remote_service_admin_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES} dfi) + add_subdirectory(dynamic_function_interface) + #TODO if test + add_subdirectory(dynamic_function_interface_tst) - install_bundle(remote_service_admin_dfi) + add_subdirectory(rsa) + #TODO if test + add_subdirectory(rsa_tst) - add_subdirectory(tst) -endif (RSA_REMOTE_SERVICE_ADMIN_DFI) +endif() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt index 0dad5e1..142ae32 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt @@ -1,16 +1,8 @@ # # Licensed under Apache License v2. See LICENSE for more information. # -find_package(Jansson REQUIRED) -find_package(CppUTest REQUIRED) -find_package(FFI REQUIRED) - -include_directories( - ${CPPUTEST_INCLUDE_DIR} - ${JANSSON_INCLUDE_DIRS} - ${CMAKE_CURRENT_LIST_DIR} - ${FFI_INCLUDE_DIRS} - memstream +include_directories( + . ) set(MEMSTREAM_SOURCES "") @@ -24,29 +16,6 @@ add_library(dfi STATIC dyn_function.c dyn_interface.c json_serializer.c -# avro_descriptor_translator.c ${MEMSTREAM_SOURCES} ) -target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) - - -#if (FRAMEWORK_TESTS) TODO - add_executable(test_dfi - tst/dyn_type_tests.cpp - tst/dyn_function_tests.cpp - tst/dyn_closure_tests.cpp - tst/dyn_interface_tests.cpp - tst/json_serializer_tests.cpp - tst/run_tests.cpp - ) - target_link_libraries(test_dfi dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY}) - - add_custom_target(copy-input - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/schemas schemas - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/descriptors descriptors - ) - add_dependencies(test_dfi copy-input) - - add_test(NAME run_test_dfi COMMAND test_dfi) - SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/dfi) -#endif() +target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c deleted file mode 100644 index a9fea1d..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c +++ /dev/null @@ -1,319 +0,0 @@ -/** - * Licensed under Apache License v2. See LICENSE for more information. - */ -#include "descriptor_translator.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> - -#include <jansson.h> - -#if defined(BSD) || defined(__APPLE__) -#include "open_memstream.h" -#include "fmemopen.h" -#endif - -DFI_SETUP_LOG(descriptorTranslator) - -static const int OK = 0; -static const int MEM_ERROR = 1; -static const int PARSE_ERROR = 2; -static const int INV_ARG_ERROR = 2; - -static int descriptorTranslator_createMethodInfo(dyn_interface_type *intf, json_t *schema, const char *name, int index, json_t *message); -static int descriptorTranslator_parseType(dyn_interface_type *intf, json_t *type); -static int descriptorTranslator_parseMessage(json_t *schema, const char *name, json_t *message, bool asJavaSignature, char **descriptor); -static int descriptorTranslator_parseArgument(FILE *stream, json_t *type); - -int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type **out) { - LOG_DEBUG("translating descriptor for schema '%s'\n", schemaStr); - int status = OK; - - dyn_interface_type *intf = NULL; - status = dynInterface_create("TODO", &intf); //TODO parse json first retreive 'Protocol' string value - if (status == 0) { - json_error_t error; - json_t *schema = json_loads(schemaStr, JSON_DECODE_ANY, &error); - - if (schema != NULL) { - json_t *types = json_object_get(schema, "types"); - if (types != NULL) { - json_t *type = NULL; - int index = 0; - json_array_foreach(types, index, type) { - status = descriptorTranslator_parseType(intf, type); - if (status != OK) { - break; - } - } - } - json_t *messages = json_object_get(schema, "messages"); - if (status == OK && messages != NULL) { - const char *name; - json_t *message; - int index = 0; - json_object_foreach(messages, name, message) { - status = descriptorTranslator_createMethodInfo(intf, schema, name, index++, message); - if (status != OK) { - break; - } - } - } - json_decref(schema); - } else { - status = PARSE_ERROR; - printf("AVRO_DESCRIPTOR_TRANSLATOR: error parsing json input '%s'. Error is %s\n", schemaStr, error.text); - } - } else { - status = MEM_ERROR; - } - - - if (status == OK) { - *out = intf; - } else { - dynInterface_destroy(intf); - } - return status; -} - -static int descriptorTranslator_createMethodInfo(dyn_interface_type *intf, json_t *schema, const char *name, int index, json_t *message) { - int status = OK; - - method_info_type *mInfo = calloc(1, sizeof(*mInfo)); - if (mInfo != NULL) { - mInfo->identifier = index; - status = descriptorTranslator_parseMessage(schema, name, message, false, &mInfo->descriptor); - if (status == OK) { - mInfo->name = strdup(name); - if (mInfo->name == NULL) { - status = MEM_ERROR; - } else { - status = descriptorTranslator_parseMessage(schema, name, message, true, &mInfo->strIdentifier); - } - } - } else { - status = MEM_ERROR; - } - - if (status == OK) { - TAILQ_INSERT_TAIL(&intf->methodInfos, mInfo, entries); - } else { - if (mInfo != NULL) { - if (mInfo->name != NULL) { - free(mInfo->name); - } - if (mInfo->descriptor != NULL) { - free(mInfo->descriptor); - } - if (mInfo->strIdentifier != NULL) { - free(mInfo->strIdentifier); - } - free(mInfo); - } - } - - return status; -} - -static int descriptorTranslator_parseMessage(json_t *schema, const char *name, json_t *message, bool asJavaSignature, char **descriptor) { - int status = OK; - //message -> { "request" : [ {"name":"<name>", "type":"<type>"} * ], "response":"<type>" } - //array -> "type":"array", "items:"<type>" - - char *ptr = NULL; - size_t ptrSize; - FILE *memStream = open_memstream(&ptr, &ptrSize); - - if (memStream != NULL) { - json_t *request = json_object_get(message, "request"); - fwrite(name, 1, strlen(name), memStream); - fputc('(', memStream); - if (!asJavaSignature) { - fputc('P', memStream); //handle - } - - if (request != NULL) { - size_t index; - json_t *arg; - json_array_foreach(request, index, arg) { - //json_t *name = json_object_get(arg, "name"); - json_t *type = json_object_get(arg, "type"); - if (type != NULL) { - status = descriptorTranslator_parseArgument(memStream, type); - } else { - LOG_ERROR("expected json object with name value for request argument %zu for message/method %s\n", index, name); - status = PARSE_ERROR; - } - if (status != OK) { - break; - } - } - } else { - status = PARSE_ERROR; - LOG_ERROR("Expected request for message %s\n", name); - } - - json_t *response = json_object_get(message, "response"); - if (status == OK && response != NULL) { - if (asJavaSignature) { - fputc(')', memStream); - } else { - fputc('*', memStream); //output parameter - } - status = descriptorTranslator_parseArgument(memStream, response); - } - - if (!asJavaSignature) { - fputc(')', memStream); - fputc('N', memStream); //error / exceptions - } - } else { - status = MEM_ERROR; - } - - if (memStream != NULL) { - fclose(memStream); - if (status == OK) { - *descriptor = ptr; - } else { - free(ptr); - } - } - - return status; -} - -static const char * const PRIMITIVE_INT = "int"; -static const char * const PRIMITIVE_LONG = "long"; -static const char * const PRIMITIVE_STRING = "string"; -static const char * const PRIMITIVE_BOOL = "boolean"; -static const char * const PRIMITIVE_FLOAT = "float"; -static const char * const PRIMITIVE_DOUBLE = "double"; -static const char * const PRIMITIVE_NULL = "null"; -static const char * const PRIMITIVE_BYTES = "bytes"; - -static int descriptorTranslator_parseArgument(FILE *stream, json_t *type) { - int status = OK; - if (json_is_string(type)) { - const char *typeStr = json_string_value(type); - char t = '\0'; - if (strcmp(typeStr, PRIMITIVE_INT) == 0) { - t = 'I'; - } else if (strcmp(typeStr, PRIMITIVE_LONG) == 0) { - t = 'J'; - } else if (strcmp(typeStr, PRIMITIVE_STRING) == 0) { - t = 'T'; - } else if (strcmp(typeStr, PRIMITIVE_BOOL) == 0) { - t = 'Z'; - } else if (strcmp(typeStr, PRIMITIVE_FLOAT) == 0) { - t = 'F'; - } else if (strcmp(typeStr, PRIMITIVE_DOUBLE) == 0) { - t = 'D'; - } else if (strcmp(typeStr, PRIMITIVE_NULL) == 0) { - t = 'V'; - } else if (strcmp(typeStr, PRIMITIVE_BYTES) == 0) { - t = 'B'; - } else { - fprintf(stream, "L%s;", typeStr); - } - if (t != '\0') { - fputc(t, stream); - } - } else { - json_t *subType = json_object_get(type, "type"); - json_t *items = json_object_get(type, "items"); - if (strcmp("array", json_string_value(subType)) == 0) { - //array - fputc('[', stream); - descriptorTranslator_parseArgument(stream, items); - } else { - LOG_ERROR("sub type %s not supported\n", json_string_value(subType)); - status = PARSE_ERROR; - } - } - return status; -} - -static int descriptorTranslator_parseType(dyn_interface_type *intf, json_t *type) { - int status = OK; - const char *name = json_string_value(json_object_get(type, "name")); - type_info_type *tInfo = NULL; - - char *ptr = NULL; - size_t ptrSize; - FILE *stream = open_memstream(&ptr, &ptrSize); - - if (stream != NULL) { - fputc('{', stream); - json_t *fields = json_object_get(type, "fields"); - if (json_is_array(fields)) { - int index = 0; - json_t *field = NULL; - json_array_foreach(fields, index, field) { - json_t *type = json_object_get(field, "type"); - status = descriptorTranslator_parseArgument(stream, type); - if (status != OK) { - break; - } - } - if (status == OK) { - json_array_foreach(fields, index, field) { - const char *fieldName = json_string_value(json_object_get(field, "name")); - if (fieldName != NULL) { - fputc(' ', stream); - fwrite(fieldName, 1, strlen(fieldName), stream); - } else { - status = PARSE_ERROR; - printf("Expected name for field\n"); - break; - } - } - } - } else { - status = PARSE_ERROR; - printf("Expected array type"); - } - fputc('}', stream); - fclose(stream); - } else { - status = MEM_ERROR; - LOG_ERROR("Error creating memory stream"); - } - - if (status == OK) { - tInfo = calloc(1, sizeof(*tInfo)); - if (tInfo != NULL) { - tInfo->name = strdup(name); - if (tInfo->name != NULL) { - tInfo->descriptor = ptr; - } else { - status = MEM_ERROR; - LOG_ERROR("Error allocating memory for type info name"); - } - } else { - status = MEM_ERROR; - LOG_ERROR("Error allocating memory for type_info"); - } - } - - if (status != 0 ) { - if (tInfo != NULL) { - if (tInfo->name != NULL) { - free(tInfo->name); - } - free(tInfo); - } - if (ptr != NULL) { - free(ptr); - } - } - - if (status == OK) { - TAILQ_INSERT_TAIL(&intf->typeInfos, tInfo, entries); - } - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h deleted file mode 100644 index 6473d0d..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Licensed under Apache License v2. See LICENSE for more information. - */ -#ifndef __DESCRIPTOR_TRANSLATOR_H_ -#define __DESCRIPTOR_TRANSLATOR_H_ - -#include <stdio.h> -#include <sys/queue.h> - -#include "dfi_log_util.h" -#include "dyn_interface.h" - -//logging -DFI_SETUP_LOG_HEADER(descriptorTranslator); - -int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type **out); - -#endif http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor deleted file mode 100644 index 97b1df8..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor +++ /dev/null @@ -1,13 +0,0 @@ -:header -type=interface -name=calculator -version=1.0.0 -:annotations -classname=org.example.Calculator -:types -StatsResult={DDD[D average min max input} -:methods -add(DD)D=add(PDD*D)N -sub(DD)D=sub(PDD*D)N -sqrt(D)D=sqrt(PD*D)N -stats([D)LStatsResult;=stats(P[D*LStatsResult;)N http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl deleted file mode 100644 index 0490dcd..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl +++ /dev/null @@ -1,11 +0,0 @@ -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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr deleted file mode 100644 index 0577397..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr +++ /dev/null @@ -1,36 +0,0 @@ -{ - "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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr deleted file mode 100644 index c968c61..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr deleted file mode 100644 index fc48ca9..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr +++ /dev/null @@ -1,31 +0,0 @@ -{ - "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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl deleted file mode 100644 index cd5cafe..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl +++ /dev/null @@ -1,6 +0,0 @@ -@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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr deleted file mode 100644 index 8a90bb2..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr +++ /dev/null @@ -1,33 +0,0 @@ -{ - "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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr deleted file mode 100644 index c2bce19..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr +++ /dev/null @@ -1 +0,0 @@ -{"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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp deleted file mode 100644 index 63401e5..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Licensed under Apache License v2. See LICENSE for more information. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { - -#include <stdio.h> -#include <assert.h> -#include <string.h> - -#include "dyn_common.h" -#include "descriptor_translator.h" - -#if defined(BSD) || defined(__APPLE__) -#include "open_memstream.h" -#include "fmemopen.h" -#endif - - static void stdLog(void *handle, 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"); - } - - - static char *readSchema(const char *file) { - size_t size = 0; - char *ptr = NULL; - - FILE *schema = fopen(file, "r"); - FILE *stream = open_memstream(&ptr, &size); - - assert(schema != NULL); - assert(stream != NULL); - - int c = fgetc(schema); - while (c != EOF ) { - fputc(c, stream); - c = fgetc(schema); - } - fclose(schema); - fclose(stream); - - assert(ptr != NULL); - return ptr; - } - - static dyn_interface_type *createInterfaceInfo(const char *schemaFile) { - char *schema = readSchema(schemaFile); - dyn_interface_type *ift= NULL; - - int status = descriptorTranslator_translate(schema, &ift); - CHECK_EQUAL(0, status); - - free(schema); - return ift; - } - - static int countMethodInfos(dyn_interface_type *info) { - int count = 0; - method_info_type *mInfo = NULL; - TAILQ_FOREACH(mInfo, &info->methodInfos, entries) { - count +=1; - } - return count; - } - - static int countTypeInfos(dyn_interface_type *info) { - int count = 0; - type_info_type *tInfo = NULL; - TAILQ_FOREACH(tInfo, &info->typeInfos, entries) { - count +=1; - } - return count; - } - - static void simple(void) { - //first argument void *handle, last argument output pointer for result and return int with status for exception handling - //sum(DD)D -> sum(PDD*D)N - //sub(DD)D -> sub(PDD*D)N - //sqrt(D)D -> sqrt(PD*D)N - - dyn_interface_type *intf = createInterfaceInfo("schemas/simple.avpr"); - - int count = countMethodInfos(intf); - CHECK_EQUAL(3, count); - - count = countTypeInfos(intf); - CHECK_EQUAL(0, count); - - method_info_type *mInfo = NULL; - TAILQ_FOREACH(mInfo, &intf->methodInfos, entries) { - if (strcmp("sum", mInfo->name) == 0) { - STRCMP_EQUAL("sum(PDD*D)N", mInfo->descriptor); - } else if (strcmp("add", mInfo->name) == 0) { - STRCMP_EQUAL("add(PDD*D)N", mInfo->descriptor); - } else if (strcmp("sqrt", mInfo->name) == 0) { - STRCMP_EQUAL("sqrt(PD*D)N", mInfo->descriptor); - } - } - - dynInterface_destroy(intf); - } - - static void complex(void) { - dyn_interface_type *intf = createInterfaceInfo("schemas/complex.avpr"); - - int count = countMethodInfos(intf); - CHECK_EQUAL(1, count); - - method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos); - STRCMP_EQUAL("stats", mInfo->name); - STRCMP_EQUAL("stats(P[D*LStatResult;)N", mInfo->descriptor); - - count = countTypeInfos(intf); - CHECK_EQUAL(1, count); - - type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos); - STRCMP_EQUAL("StatResult", tInfo->name); - STRCMP_EQUAL("{DDD[D sum min max input}", tInfo->descriptor); - - dynInterface_destroy(intf); - } - - static void invalid(const char *file) { - char *schema = readSchema(file); - dyn_interface_type *ift= NULL; - - int status = descriptorTranslator_translate(schema, &ift); - CHECK(status != 0); - - free(schema); - } -} - -TEST_GROUP(AvroDescTranslatorTest) { - void setup() { - descriptorTranslator_logSetup(stdLog, NULL, 3); - dynInterface_logSetup(stdLog, NULL, 3); - dynType_logSetup(stdLog, NULL, 3); - dynCommon_logSetup(stdLog, NULL, 3); - } -}; - -TEST(AvroDescTranslatorTest, simple) { - simple(); -} - -TEST(AvroDescTranslatorTest, complex) { - complex(); -} - -TEST(AvroDescTranslatorTest, invalid1) { - invalid("schemas/invalid1.avpr"); -} - -TEST(AvroDescTranslatorTest, invalid2) { - invalid("schemas/invalid2.avpr"); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_closure_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_closure_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_closure_tests.cpp deleted file mode 100644 index b2b11d7..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_closure_tests.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - */ -#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 int g_count; - -static void stdLog(void *handle, 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"); -} - -#define EXAMPLE1_DESCRIPTOR "example(III)I" -static void example1_binding(void *userData, void* args[], void *out) { - int32_t a = *((int32_t *)args[0]); - int32_t b = *((int32_t *)args[1]); - int32_t c = *((int32_t *)args[2]); - int32_t *ret = (int32_t *)out; - *ret = a + b + c; - g_count += 1; -} - -#define EXAMPLE2_DESCRIPTOR "example(I{DDD val1 val2 val3}I)D" -struct example2_arg2 { - double val1; - double val2; - double val3; -}; -void example2_binding(void *userData, void* args[], void *out) { - int32_t a = *((int32_t *)args[0]); - struct example2_arg2 b = *((struct example2_arg2 *)args[1]); - int32_t c = *((int32_t *)args[2]); - double *ret = (double *)out; - *ret = a + b.val1 + b.val2 + b.val3 + c; - g_count += 1; -} - - -#define EXAMPLE3_DESCRIPTOR "example(III){III sum max min}" -struct example3_ret { - int32_t sum; - int32_t max; - int32_t min; -}; - -static void example3_binding(void *userData, void* args[], void *out) { - int32_t a = *((int32_t *)args[0]); - int32_t b = *((int32_t *)args[1]); - int32_t c = *((int32_t *)args[2]); - struct example3_ret *result = (struct example3_ret *)calloc(1,sizeof(struct example3_ret)); - result->sum = a + b + c; - result->min = a <= b ? a : b; - result->max = a >= b ? a : b; - result->min = result->min <= c ? result->min : c; - result->max = result->max >= c ? result->max : c; - - struct example3_ret **ret = (struct example3_ret **)out; - (*ret) = result; - g_count += 1; -} - -static void tests() { - dyn_function_type *dynFunction = NULL; - int rc = 0; - - { - int32_t (*func)(int32_t a, int32_t b, int32_t c) = NULL; - rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunction); - CHECK_EQUAL(0, rc); - rc = dynFunction_createClosure(dynFunction, example1_binding, NULL, (void(**)(void))&func); - CHECK_EQUAL(0, rc); - int32_t ret = func(2,3,4); - CHECK_EQUAL(1, g_count); - CHECK_EQUAL(9, ret); - dynFunction_destroy(dynFunction); - } - - { - double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL; - double (*func2)(int32_t a, struct example2_arg2 b, int32_t c) = NULL; - dynFunction = NULL; - rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunction); - CHECK_EQUAL(0, rc); - rc = dynFunction_createClosure(dynFunction, example2_binding, NULL, (void(**)(void))&func); - CHECK_EQUAL(0, rc); - rc = dynFunction_getFnPointer(dynFunction, (void(**)(void))&func2); - CHECK_EQUAL(0, rc); - CHECK(func == func2); - struct example2_arg2 b; - b.val1 = 1.0; - b.val2 = 1.5; - b.val3 = 2.0; - double ret = func(2,b,4); - CHECK_EQUAL(2, g_count); - CHECK_EQUAL(10.5, ret); - dynFunction_destroy(dynFunction); - } - - { - struct example3_ret * (*func)(int32_t a, int32_t b, int32_t c) = NULL; - dynFunction = NULL; - rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunction); - CHECK_EQUAL(0, rc); - rc = dynFunction_createClosure(dynFunction, example3_binding, NULL, (void(**)(void))&func); - CHECK_EQUAL(0, rc); - struct example3_ret *ret = func(2,8,4); - CHECK_EQUAL(3, g_count); - CHECK_EQUAL(14, ret->sum); - dynFunction_destroy(dynFunction); - free(ret); - } -} - -} - - -TEST_GROUP(DynClosureTests) { - void setup() { - dynFunction_logSetup(stdLog, NULL, 3); - dynType_logSetup(stdLog, NULL, 3); - //TODO dynType_logSetup(stdLog, NULL, 4); - dynCommon_logSetup(stdLog, NULL, 3); - g_count = 0; - } -}; - -TEST(DynClosureTests, DynCLosureTest1) { - //TODO split up - tests(); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_function_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_function_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_function_tests.cpp deleted file mode 100644 index cb4e13b..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_function_tests.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - */ -#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 *handle, 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"); - } - - #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; - 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; - rc = dynFunction_call(dynFunc, fp, &rVal, args); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(4.0, result); - free(inMemResult); - - dynFunction_destroy(dynFunc); - } - - void test_meta(void) { - int rc; - dyn_function_type *func = NULL; - - const char *descriptor1 = "sqrt(D^*D~**D#P)V"; - rc = dynFunction_parseWithStr(descriptor1, NULL, &func); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(DYN_FUNCTION_ARG_META_INPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 0)); - CHECK_EQUAL(DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 1)); - CHECK_EQUAL(DYN_FUNCTION_ARG_META_OUTPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 2)); - CHECK_EQUAL(DYN_FUNCTION_ARG_META_HANDLE_TYPE, dynFunction_argumentMetaInfoForIndex(func, 3)); - CHECK_EQUAL(DYN_FUNCTION_ARG_META_UNKNOWN_TYPE, dynFunction_argumentMetaInfoForIndex(func, 4)); - dynFunction_destroy(func); - - const char *descriptor2 = "sqrt(D~*D)V"; - rc = dynFunction_parseWithStr(descriptor2, NULL, &func); - CHECK(rc != 0); - - const char *descriptor3 = "sqrt(D~***D)V"; - rc = dynFunction_parseWithStr(descriptor3, NULL, &func); - CHECK_EQUAL(0, rc); - dynFunction_destroy(func); - - - const char *descriptor4 = "sqrt(D^D)V"; - rc = dynFunction_parseWithStr(descriptor4, NULL, &func); - CHECK(rc != 0); - - const char *descriptor5 = "sqrt(D^***D)V"; - rc = dynFunction_parseWithStr(descriptor5, NULL, &func); - CHECK_EQUAL(0, rc); - dynFunction_destroy(func); - } -} - -TEST_GROUP(DynFunctionTests) { - void setup() { - dynFunction_logSetup(stdLog, NULL, 3); - dynType_logSetup(stdLog, NULL, 3); - dynCommon_logSetup(stdLog, NULL, 3); - } -}; - -TEST(DynFunctionTests, DynFuncTest1) { - test_example1(); -} - -TEST(DynFunctionTests, DynFuncTest2) { - test_example2(); -} - -TEST(DynFunctionTests, DynFuncAccTest) { - test_access_functions(); -} - -TEST(DynFunctionTests, DynFuncTest3) { - test_example3(); -} - -TEST(DynFunctionTests, DynFuncTestMeta) { - test_meta(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_interface_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_interface_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_interface_tests.cpp deleted file mode 100644 index 679260f..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_interface_tests.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - */ -#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 *handle, 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"); - } - - 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); - } - -} - - -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(); -} http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_type_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_type_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_type_tests.cpp deleted file mode 100644 index 96f64fa..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_type_tests.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - */ -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -extern "C" { - #include <string.h> - #include <stdarg.h> - - #include "dyn_common.h" - #include "dyn_type.h" - - static void stdLog(void *handle, 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"); - } - - static void runTest(const char *descriptorStr, const char *exName) { - dyn_type *type; - int i; - 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); - - 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, 0); - } -}; - -#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 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) - -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); -} - http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp deleted file mode 100644 index 5ee71ac..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/** - * Licensed under Apache License v2. See LICENSE for more information. - */ -#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 *handle, 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"); -} - -/*********** 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 4 ************************/ -/** 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 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); -} - -const char *write_example1_descriptor = "{BSIJsijFDN a b c d e f g h i j}"; - -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; -}; - -void writeTest1(void) { - struct write_example1 ex1 = {.a=1, .b=2, .c=3, .d=4, .e=5, .f=6, .g=7, .h=8.8f, .i=9.9, .j=10}; - 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); - //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 = { .a = 1, .b = 2 }; - struct write_example2 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 = {.name = "John", .age = 33}; - struct write_example3_person p2 = {.name = "Peter", .age = 44}; - struct write_example3_person p3 = {.name = "Carol", .age = 55}; - struct write_example3_person p4 = {.name = "Elton", .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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/run_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/run_tests.cpp deleted file mode 100644 index f405c9f..0000000 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/run_tests.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - */ -#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/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt new file mode 100644 index 0000000..50325ab --- /dev/null +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# Licensed under Apache License v2. See LICENSE for more information. +# +include_directories( + ../dynamic_function_interface +) + +add_executable(test_dfi + dyn_type_tests.cpp + dyn_function_tests.cpp + dyn_closure_tests.cpp + dyn_interface_tests.cpp + json_serializer_tests.cpp + run_tests.cpp +) +target_link_libraries(test_dfi dfi ${CPPUTEST_LIBRARY}) + +add_custom_target(copy-input + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/schemas schemas + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/descriptors descriptors +) +add_dependencies(test_dfi copy-input) + +add_test(NAME run_test_dfi COMMAND test_dfi) +SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/dfi) + http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp new file mode 100644 index 0000000..63401e5 --- /dev/null +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp @@ -0,0 +1,164 @@ +/** + * Licensed under Apache License v2. See LICENSE for more information. + */ +#include <CppUTest/TestHarness.h> +#include "CppUTest/CommandLineTestRunner.h" + +extern "C" { + +#include <stdio.h> +#include <assert.h> +#include <string.h> + +#include "dyn_common.h" +#include "descriptor_translator.h" + +#if defined(BSD) || defined(__APPLE__) +#include "open_memstream.h" +#include "fmemopen.h" +#endif + + static void stdLog(void *handle, 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"); + } + + + static char *readSchema(const char *file) { + size_t size = 0; + char *ptr = NULL; + + FILE *schema = fopen(file, "r"); + FILE *stream = open_memstream(&ptr, &size); + + assert(schema != NULL); + assert(stream != NULL); + + int c = fgetc(schema); + while (c != EOF ) { + fputc(c, stream); + c = fgetc(schema); + } + fclose(schema); + fclose(stream); + + assert(ptr != NULL); + return ptr; + } + + static dyn_interface_type *createInterfaceInfo(const char *schemaFile) { + char *schema = readSchema(schemaFile); + dyn_interface_type *ift= NULL; + + int status = descriptorTranslator_translate(schema, &ift); + CHECK_EQUAL(0, status); + + free(schema); + return ift; + } + + static int countMethodInfos(dyn_interface_type *info) { + int count = 0; + method_info_type *mInfo = NULL; + TAILQ_FOREACH(mInfo, &info->methodInfos, entries) { + count +=1; + } + return count; + } + + static int countTypeInfos(dyn_interface_type *info) { + int count = 0; + type_info_type *tInfo = NULL; + TAILQ_FOREACH(tInfo, &info->typeInfos, entries) { + count +=1; + } + return count; + } + + static void simple(void) { + //first argument void *handle, last argument output pointer for result and return int with status for exception handling + //sum(DD)D -> sum(PDD*D)N + //sub(DD)D -> sub(PDD*D)N + //sqrt(D)D -> sqrt(PD*D)N + + dyn_interface_type *intf = createInterfaceInfo("schemas/simple.avpr"); + + int count = countMethodInfos(intf); + CHECK_EQUAL(3, count); + + count = countTypeInfos(intf); + CHECK_EQUAL(0, count); + + method_info_type *mInfo = NULL; + TAILQ_FOREACH(mInfo, &intf->methodInfos, entries) { + if (strcmp("sum", mInfo->name) == 0) { + STRCMP_EQUAL("sum(PDD*D)N", mInfo->descriptor); + } else if (strcmp("add", mInfo->name) == 0) { + STRCMP_EQUAL("add(PDD*D)N", mInfo->descriptor); + } else if (strcmp("sqrt", mInfo->name) == 0) { + STRCMP_EQUAL("sqrt(PD*D)N", mInfo->descriptor); + } + } + + dynInterface_destroy(intf); + } + + static void complex(void) { + dyn_interface_type *intf = createInterfaceInfo("schemas/complex.avpr"); + + int count = countMethodInfos(intf); + CHECK_EQUAL(1, count); + + method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos); + STRCMP_EQUAL("stats", mInfo->name); + STRCMP_EQUAL("stats(P[D*LStatResult;)N", mInfo->descriptor); + + count = countTypeInfos(intf); + CHECK_EQUAL(1, count); + + type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos); + STRCMP_EQUAL("StatResult", tInfo->name); + STRCMP_EQUAL("{DDD[D sum min max input}", tInfo->descriptor); + + dynInterface_destroy(intf); + } + + static void invalid(const char *file) { + char *schema = readSchema(file); + dyn_interface_type *ift= NULL; + + int status = descriptorTranslator_translate(schema, &ift); + CHECK(status != 0); + + free(schema); + } +} + +TEST_GROUP(AvroDescTranslatorTest) { + void setup() { + descriptorTranslator_logSetup(stdLog, NULL, 3); + dynInterface_logSetup(stdLog, NULL, 3); + dynType_logSetup(stdLog, NULL, 3); + dynCommon_logSetup(stdLog, NULL, 3); + } +}; + +TEST(AvroDescTranslatorTest, simple) { + simple(); +} + +TEST(AvroDescTranslatorTest, complex) { + complex(); +} + +TEST(AvroDescTranslatorTest, invalid1) { + invalid("schemas/invalid1.avpr"); +} + +TEST(AvroDescTranslatorTest, invalid2) { + invalid("schemas/invalid2.avpr"); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor new file mode 100644 index 0000000..97b1df8 --- /dev/null +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor @@ -0,0 +1,13 @@ +:header +type=interface +name=calculator +version=1.0.0 +:annotations +classname=org.example.Calculator +:types +StatsResult={DDD[D average min max input} +:methods +add(DD)D=add(PDD*D)N +sub(DD)D=sub(PDD*D)N +sqrt(D)D=sqrt(PD*D)N +stats([D)LStatsResult;=stats(P[D*LStatsResult;)N
