You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2023/12/12 10:10:25 UTC
(celix) branch feature/509-remove-avpr updated: #509 Remove avpr support from dfi.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/509-remove-avpr
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/feature/509-remove-avpr by this push:
new 7042481a #509 Remove avpr support from dfi.
7042481a is described below
commit 7042481a6305e2de5a96de5271fda4f078ba6a95
Author: PengZheng <ho...@gmail.com>
AuthorDate: Tue Dec 12 18:10:13 2023 +0800
#509 Remove avpr support from dfi.
---
.../include/pubsub_serialization_provider.h | 2 +-
.../examples/calculator_api/CMakeLists.txt | 2 +-
.../org.apache.celix.calc.api.Calculator.avpr | 44 -
.../examples/calculator_shell/CMakeLists.txt | 3 +-
.../examples/remote_example_api/CMakeLists.txt | 8 +-
.../remote_service_admin_dfi/gtest/CMakeLists.txt | 4 +-
.../src/export_registration_dfi.c | 11 -
.../src/import_registration_dfi.c | 13 +-
.../rsa_dfi_utils/gtest/CMakeLists.txt | 5 -
.../gtest/descriptors/rsa_dfi_utils_test_avpr.avpr | 21 -
.../rsa_dfi_utils/gtest/src/DfiUtilsTestSuite.cc | 6 -
.../rsa_dfi_utils/include/dfi_utils.h | 1 -
.../remote_services/rsa_dfi_utils/src/dfi_utils.c | 58 +-
.../rsa_spi/include/rsa_rpc_factory.h | 2 +-
.../topology_manager/tms_tst/bundle/CMakeLists.txt | 2 +-
.../bundle/org.apache.celix.test.MyBundle.avpr | 24 -
.../org.apache.celix.test.MyBundle.descriptor | 9 +
libs/dfi/CMakeLists.txt | 8 +-
libs/dfi/gtest/CMakeLists.txt | 8 +-
libs/dfi/gtest/schemas/complex.avdl | 30 -
libs/dfi/gtest/schemas/complex.avpr | 55 -
libs/dfi/gtest/schemas/invalid1.avpr | 48 -
libs/dfi/gtest/schemas/invalid2.avpr | 50 -
libs/dfi/gtest/schemas/simple.avdl | 25 -
libs/dfi/gtest/schemas/simple.avpr | 52 -
libs/dfi/gtest/schemas/simple_min.avpr | 20 -
.../gtest/src/avro_descriptor_translator_tests.cpp | 186 ---
libs/dfi/gtest/src/avrobin_serialization_tests.cpp | 612 ---------
libs/dfi/gtest/src/dyn_avpr_function_tests.cpp | 675 ----------
libs/dfi/gtest/src/dyn_avpr_interface_tests.cpp | 179 ---
libs/dfi/gtest/src/dyn_avpr_tests.cpp | 615 ---------
libs/dfi/gtest/src/json_rpc_avpr_tests.cpp | 391 ------
libs/dfi/gtest/src/json_serializer_tests.cpp | 796 ------------
libs/dfi/include/avrobin_serializer.h | 100 --
libs/dfi/include/dyn_function.h | 29 -
libs/dfi/include/dyn_interface.h | 23 -
libs/dfi/include/dyn_type.h | 26 -
libs/dfi/src/avrobin_serializer.c | 1368 --------------------
libs/dfi/src/dyn_avpr_function.c | 344 -----
libs/dfi/src/dyn_avpr_interface.c | 290 -----
libs/dfi/src/dyn_avpr_type.c | 1054 ---------------
libs/dfi/src/dyn_interface.c | 1 -
libs/utils/src/properties.c | 1 -
rat-excludes.txt | 3 -
44 files changed, 22 insertions(+), 7182 deletions(-)
diff --git a/bundles/pubsub/pubsub_utils/include/pubsub_serialization_provider.h b/bundles/pubsub/pubsub_utils/include/pubsub_serialization_provider.h
index a01b4c50..dc1e87d5 100644
--- a/bundles/pubsub/pubsub_utils/include/pubsub_serialization_provider.h
+++ b/bundles/pubsub/pubsub_utils/include/pubsub_serialization_provider.h
@@ -61,7 +61,7 @@ typedef struct {
*
* The provider monitors bundles and creates pubsub message serialization services for every unique descriptor found.
*
- * Descriptors can be DFI descriptors or AVPR descriptors (FIXME #158).
+ * Descriptors can be DFI descriptors.
*
* The provider will look for descriptors in META-INF/descriptors directory of every installed bundle.
* If a framework config CELIX_FRAMEWORK_EXTENDER_PATH is set, this path will also be used to search for descriptor files.
diff --git a/bundles/remote_services/examples/calculator_api/CMakeLists.txt b/bundles/remote_services/examples/calculator_api/CMakeLists.txt
index 3b0e3346..9313b9ed 100644
--- a/bundles/remote_services/examples/calculator_api/CMakeLists.txt
+++ b/bundles/remote_services/examples/calculator_api/CMakeLists.txt
@@ -19,4 +19,4 @@ add_library(calculator_api INTERFACE)
target_include_directories(calculator_api INTERFACE include)
set_target_properties(calculator_api PROPERTIES
"INTERFACE_DESCRIPTOR"
- "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.calc.api.Calculator.avpr")
+ "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.calc.api.Calculator.descriptor")
diff --git a/bundles/remote_services/examples/calculator_api/org.apache.celix.calc.api.Calculator.avpr b/bundles/remote_services/examples/calculator_api/org.apache.celix.calc.api.Calculator.avpr
deleted file mode 100644
index b20554e6..00000000
--- a/bundles/remote_services/examples/calculator_api/org.apache.celix.calc.api.Calculator.avpr
+++ /dev/null
@@ -1,44 +0,0 @@
-{
- "protocol" : "Calculator",
- "namespace" : "org.apache.celix.calc.api",
- "version" : "1.3.0",
- "types" : [ {
- "type" : "fixed",
- "name" : "Double",
- "alias": "double",
- "size" : 8
- } ] ,
- "messages" : {
- "add" : {
- "index" : 0,
- "request" : [ {
- "name" : "arg1",
- "type" : "Double"
- } , {
- "name" : "arg2",
- "type" : "Double"
- } ],
- "response" : "Double"
- },
- "sub" : {
- "index" : 1,
- "request" : [ {
- "name" : "arg1",
- "type" : "Double"
- } , {
- "name" : "arg2",
- "type" : "Double"
- } ],
- "response" : "Double"
- },
- "sqrt" : {
- "index" : 2,
- "request" : [ {
- "name" : "arg",
- "type" : "Double"
- } ],
- "response" : "Double"
- }
- }
-}
-
diff --git a/bundles/remote_services/examples/calculator_shell/CMakeLists.txt b/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
index 4bc92aa0..9a79c9e4 100644
--- a/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -28,7 +28,6 @@ target_include_directories(calculator_shell PRIVATE src)
target_link_libraries(calculator_shell PRIVATE Celix::shell_api calculator_api)
celix_bundle_files(calculator_shell
- ../calculator_api/org.apache.celix.calc.api.Calculator.avpr
- #src/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
+ ../calculator_api/org.apache.celix.calc.api.Calculator.descriptor
DESTINATION .
)
diff --git a/bundles/remote_services/examples/remote_example_api/CMakeLists.txt b/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
index 6a0db33a..a42d3f86 100644
--- a/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
+++ b/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
@@ -15,14 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-#[[
-Note use avro-tools.jar (idl command) to generate avpr from avdl
-#]]
-
add_library(remote_example_api INTERFACE)
target_include_directories(remote_example_api INTERFACE include)
set_target_properties(remote_example_api PROPERTIES
"INTERFACE_DESCRIPTOR"
- "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.RemoteExample.descriptor")
-
-#TODO use avpr instead of descriptor
+ "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.RemoteExample.descriptor")
\ No newline at end of file
diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt b/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt
index 3151f339..b291dea8 100644
--- a/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt
+++ b/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt
@@ -26,11 +26,11 @@ add_celix_bundle(rsa_dfi_tst_bundle
celix_deprecated_utils_headers(rsa_dfi_tst_bundle)
celix_deprecated_framework_headers(rsa_dfi_tst_bundle)
-#add calculator avpr
+#add calculator
get_target_property(DESCR calculator_api INTERFACE_DESCRIPTOR)
celix_bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
-#add remote example avpr
+#add remote example
get_target_property(DESCR remote_example_api INTERFACE_DESCRIPTOR)
celix_bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
index 1ff6131c..ff45b0be 100644
--- a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
+++ b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
@@ -221,17 +221,6 @@ static celix_status_t exportRegistration_findAndParseInterfaceDescriptor(celix_l
return status;
}
- status = dfi_findAvprDescriptor(context, bundle, name, &descriptor);
- if (status == CELIX_SUCCESS && descriptor != NULL) {
- *out = dynInterface_parseAvpr(descriptor);
- if (*out == NULL) {
- celix_logHelper_logTssErrors(helper, CELIX_LOG_LEVEL_WARNING);
- celix_logHelper_warning(helper, "RSA_AVPR: Error parsing avpr service descriptor for '%s'", name);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- return status;
- }
-
celix_logHelper_log(helper, CELIX_LOG_LEVEL_WARNING, "RSA: Error finding service descriptor for '%s'", name);
return CELIX_BUNDLE_EXCEPTION;
}
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
index e1a39812..5cc0327e 100644
--- a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
+++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
@@ -217,18 +217,7 @@ static celix_status_t importRegistration_findAndParseInterfaceDescriptor(celix_b
return status;
}
- status = dfi_findAvprDescriptor(context, bundle, name, &descriptor);
- if (status == CELIX_SUCCESS && descriptor != NULL) {
- *out = dynInterface_parseAvpr(descriptor);
- fclose(descriptor);
- if (*out == NULL) {
- fprintf(stderr, "RSA_AVPR: Cannot parse avpr descriptor for '%s'", name);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- return status;
- }
-
- fprintf(stdout, "RSA: Cannot find/open any valid (avpr) descriptor files for '%s'", name);
+ fprintf(stdout, "RSA: Cannot find/open any valid descriptor files for '%s'", name);
return CELIX_BUNDLE_EXCEPTION;
}
diff --git a/bundles/remote_services/rsa_dfi_utils/gtest/CMakeLists.txt b/bundles/remote_services/rsa_dfi_utils/gtest/CMakeLists.txt
index ad8c166c..3e065f74 100644
--- a/bundles/remote_services/rsa_dfi_utils/gtest/CMakeLists.txt
+++ b/bundles/remote_services/rsa_dfi_utils/gtest/CMakeLists.txt
@@ -20,11 +20,6 @@ celix_bundle_files(rsa_dfi_utils_test_descriptor
${CMAKE_CURRENT_SOURCE_DIR}/descriptors/rsa_dfi_utils_test.descriptor
DESTINATION "META-INF/descriptors"
)
-celix_bundle_files(rsa_dfi_utils_test_descriptor
- ${CMAKE_CURRENT_SOURCE_DIR}/descriptors/rsa_dfi_utils_test_avpr.avpr
- DESTINATION "META-INF/avpr"
-)
-
add_executable(test_rsa_dfi_utils
src/DfiUtilsTestSuite.cc
diff --git a/bundles/remote_services/rsa_dfi_utils/gtest/descriptors/rsa_dfi_utils_test_avpr.avpr b/bundles/remote_services/rsa_dfi_utils/gtest/descriptors/rsa_dfi_utils_test_avpr.avpr
deleted file mode 100644
index f995c18c..00000000
--- a/bundles/remote_services/rsa_dfi_utils/gtest/descriptors/rsa_dfi_utils_test_avpr.avpr
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "protocol" : "rsa_dfi_utils_test_avpr",
- "namespace" : "rsa_dfi_utils_test_avpr",
- "version" : "1.0.0",
- "types" : [ {
- "type" : "fixed",
- "name" : "Double",
- "alias": "double",
- "size" : 8
- } ] ,
- "messages" : {
- "test" : {
- "index" : 0,
- "request" : [ {
- "name" : "arg1",
- "type" : "Double"
- } ],
- "response" : "Double"
- }
- }
-}
diff --git a/bundles/remote_services/rsa_dfi_utils/gtest/src/DfiUtilsTestSuite.cc b/bundles/remote_services/rsa_dfi_utils/gtest/src/DfiUtilsTestSuite.cc
index ac23ad83..7f0f79e8 100644
--- a/bundles/remote_services/rsa_dfi_utils/gtest/src/DfiUtilsTestSuite.cc
+++ b/bundles/remote_services/rsa_dfi_utils/gtest/src/DfiUtilsTestSuite.cc
@@ -65,12 +65,6 @@ TEST_F(DfiUtilsTestSuite, ParseDescriptor) {
EXPECT_TRUE(found);
}
-TEST_F(DfiUtilsTestSuite, ParseAvprDescriptor) {
- curTestDescFile = "rsa_dfi_utils_test_avpr";
- bool found = celix_bundleContext_useBundle(ctx.get(), descBundleId, this, useBundleCallback);
- EXPECT_TRUE(found);
-}
-
TEST_F(DfiUtilsTestSuite, ParseDescriptorForFw) {
curTestDescFile = "rsa_dfi_utils_test";
bool found = celix_bundleContext_useBundle(ctx.get(), 0, this, useBundleCallback);
diff --git a/bundles/remote_services/rsa_dfi_utils/include/dfi_utils.h b/bundles/remote_services/rsa_dfi_utils/include/dfi_utils.h
index 7315bd6c..395dd6f3 100644
--- a/bundles/remote_services/rsa_dfi_utils/include/dfi_utils.h
+++ b/bundles/remote_services/rsa_dfi_utils/include/dfi_utils.h
@@ -33,7 +33,6 @@ extern "C" {
celix_status_t dfi_findDescriptor(celix_bundle_context_t *context, const celix_bundle_t *bundle, const char *name, FILE **out);
-celix_status_t dfi_findAvprDescriptor(celix_bundle_context_t *context, const celix_bundle_t *bundle, const char *name, FILE **out);
celix_status_t dfi_findAndParseInterfaceDescriptor(celix_log_helper_t *logHelper,
celix_bundle_context_t *ctx, const celix_bundle_t *svcOwner, const char *name,
diff --git a/bundles/remote_services/rsa_dfi_utils/src/dfi_utils.c b/bundles/remote_services/rsa_dfi_utils/src/dfi_utils.c
index 8bea290b..da9e7dd1 100644
--- a/bundles/remote_services/rsa_dfi_utils/src/dfi_utils.c
+++ b/bundles/remote_services/rsa_dfi_utils/src/dfi_utils.c
@@ -80,33 +80,6 @@ static celix_status_t dfi_findFileForBundle(const celix_bundle_t *bundle, const
return status;
}
-static celix_status_t dfi_findAvprFileForBundle(const celix_bundle_t *bundle, const char* fileName, FILE **out) {
- celix_status_t status = CELIX_SUCCESS;
- char* path = celix_bundle_getEntry(bundle, fileName);
-
- char metaInfFileName[512];
-
- if (path == NULL) {
- snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/avpr/%s", fileName);
- path = celix_bundle_getEntry(bundle, metaInfFileName);
- }
-
- if (path != NULL) {
- FILE *df = fopen(path, "r");
- if (df == NULL) {
- status = CELIX_FILE_IO_EXCEPTION;
- }
- else {
- *out = df;
- }
- } else {
- status = CELIX_FILE_IO_EXCEPTION;
- }
-
- free(path);
- return status;
-}
-
celix_status_t dfi_findDescriptor(celix_bundle_context_t *context, const celix_bundle_t *bundle, const char *name, FILE **out) {
char fileName[128];
snprintf(fileName, 128, "%s.descriptor", name);
@@ -125,23 +98,6 @@ celix_status_t dfi_findDescriptor(celix_bundle_context_t *context, const celix_b
return status;
}
-celix_status_t dfi_findAvprDescriptor(celix_bundle_context_t *context, const celix_bundle_t *bundle, const char *name, FILE **out) {
- char fileName[128];
- snprintf(fileName, 128, "%s.avpr", name);
- long id = celix_bundle_getId(bundle);
-
- celix_status_t status;
- if (id == 0) {
- //framework bundle
- status = dfi_findFileForFramework(context, fileName, out);
- } else {
- //normal bundle
- status = dfi_findAvprFileForBundle(bundle, fileName, out);
- }
-
- return status;
-}
-
celix_status_t dfi_findAndParseInterfaceDescriptor(celix_log_helper_t *logHelper,
celix_bundle_context_t *ctx, const celix_bundle_t *svcOwner, const char *name,
dyn_interface_type **intfOut) {
@@ -163,19 +119,7 @@ celix_status_t dfi_findAndParseInterfaceDescriptor(celix_log_helper_t *logHelper
return status;
}
- status = dfi_findAvprDescriptor(ctx, svcOwner, name, &descriptor);
- if (status == CELIX_SUCCESS && descriptor != NULL) {
- *intfOut = dynInterface_parseAvpr(descriptor);
- fclose(descriptor);
- if (*intfOut == NULL) {
- celix_logHelper_logTssErrors(logHelper, CELIX_LOG_LEVEL_ERROR);
- celix_logHelper_error(logHelper, "Cannot parse avpr descriptor for '%s'", name);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- return status;
- }
-
- celix_logHelper_error(logHelper, "Cannot find/open any valid (avpr) descriptor files for '%s'", name);
+ celix_logHelper_error(logHelper, "Cannot find/open any valid descriptor files for '%s'", name);
return CELIX_BUNDLE_EXCEPTION;
}
diff --git a/bundles/remote_services/rsa_spi/include/rsa_rpc_factory.h b/bundles/remote_services/rsa_spi/include/rsa_rpc_factory.h
index 8c902723..7534274c 100644
--- a/bundles/remote_services/rsa_spi/include/rsa_rpc_factory.h
+++ b/bundles/remote_services/rsa_spi/include/rsa_rpc_factory.h
@@ -35,7 +35,7 @@ extern "C" {
/**
* @brief The prefix for RPC type value, and the RPC type value belongs to `service.exported.configs`.
- * A whole RPC type value as follows: celix.remote.admin.rpc_type.json,celix.remote.admin.rpc_type.avpr.
+ * A whole RPC type value as follows: celix.remote.admin.rpc_type.json.
*/
#define RSA_RPC_TYPE_PREFIX "celix.remote.admin.rpc_type."
diff --git a/bundles/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt b/bundles/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
index 029e28b0..56599e27 100644
--- a/bundles/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
+++ b/bundles/remote_services/topology_manager/tms_tst/bundle/CMakeLists.txt
@@ -26,7 +26,7 @@ add_celix_bundle(topology_manager_test_bundle
tst_activator.c
)
celix_bundle_files(topology_manager_test_bundle
- org.apache.celix.test.MyBundle.avpr
+ org.apache.celix.test.MyBundle.descriptor
DESTINATION .
)
diff --git a/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.avpr b/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.avpr
deleted file mode 100644
index 3876f6ff..00000000
--- a/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.avpr
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "protocol" : "MyBundle",
- "namespace" : "org.apache.celix",
- "version" : "1.0.0",
- "types" : [ {
- "type" : "fixed",
- "name" : "Double",
- "alias": "double",
- "size" : 8
- } ] ,
- "messages" : {
- "add" : {
- "index" : 0,
- "request" : [ {
- "name" : "arg1",
- "type" : "Double"
- } , {
- "name" : "arg2",
- "type" : "Double"
- } ],
- "response" : "Double"
- }
- }
-}
diff --git a/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.descriptor b/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.descriptor
new file mode 100644
index 00000000..39b6bc92
--- /dev/null
+++ b/bundles/remote_services/topology_manager/tms_tst/bundle/org.apache.celix.test.MyBundle.descriptor
@@ -0,0 +1,9 @@
+:header
+type=interface
+name=MyBundle
+version=1.0.0
+:annotations
+classname="org.apache.celix.test.MyBundle
+:types
+:methods
+add(DD)D=add(#am=handle;PDD#am=pre;*D)N
diff --git a/libs/dfi/CMakeLists.txt b/libs/dfi/CMakeLists.txt
index cf5019e1..f82aca3a 100644
--- a/libs/dfi/CMakeLists.txt
+++ b/libs/dfi/CMakeLists.txt
@@ -24,16 +24,12 @@ if (CELIX_DFI)
src/dyn_common.c
src/dyn_type_common.c
src/dyn_type.c
- src/dyn_avpr_type.c
- src/dyn_function.c
- src/dyn_avpr_function.c
+ src/dyn_function.c
src/dyn_interface.c
- src/dyn_avpr_interface.c
src/dyn_message.c
src/json_serializer.c
src/json_rpc.c
- src/avrobin_serializer.c
- )
+ )
add_library(dfi SHARED ${SOURCES})
target_include_directories(dfi PUBLIC
diff --git a/libs/dfi/gtest/CMakeLists.txt b/libs/dfi/gtest/CMakeLists.txt
index 83e30adc..e0206df1 100644
--- a/libs/dfi/gtest/CMakeLists.txt
+++ b/libs/dfi/gtest/CMakeLists.txt
@@ -18,18 +18,13 @@
add_executable(test_dfi
src/dyn_example_functions.c
- src/dyn_avpr_tests.cpp
- src/dyn_type_tests.cpp
+ src/dyn_type_tests.cpp
src/dyn_function_tests.cpp
src/dyn_closure_tests.cpp
- src/dyn_avpr_function_tests.cpp
src/dyn_interface_tests.cpp
- src/dyn_avpr_interface_tests.cpp
src/dyn_message_tests.cpp
src/json_serializer_tests.cpp
src/json_rpc_tests.cpp
- src/json_rpc_avpr_tests.cpp
- src/avrobin_serialization_tests.cpp
)
@@ -37,7 +32,6 @@ target_include_directories(test_dfi PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src)
target_link_libraries(test_dfi PRIVATE Celix::dfi Celix::utils libffi::libffi jansson::jansson GTest::gtest GTest::gtest_main)
celix_deprecated_utils_headers(test_dfi)
-file(COPY ${CMAKE_CURRENT_LIST_DIR}/schemas DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_LIST_DIR}/descriptors DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME run_test_dfi COMMAND test_dfi)
diff --git a/libs/dfi/gtest/schemas/complex.avdl b/libs/dfi/gtest/schemas/complex.avdl
deleted file mode 100644
index b9e17484..00000000
--- a/libs/dfi/gtest/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);
-}
diff --git a/libs/dfi/gtest/schemas/complex.avpr b/libs/dfi/gtest/schemas/complex.avpr
deleted file mode 100644
index f4124270..00000000
--- a/libs/dfi/gtest/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
diff --git a/libs/dfi/gtest/schemas/invalid1.avpr b/libs/dfi/gtest/schemas/invalid1.avpr
deleted file mode 100644
index b447ff03..00000000
--- a/libs/dfi/gtest/schemas/invalid1.avpr
+++ /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.
- */
-
-{
- "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"
- }
- }
-}
diff --git a/libs/dfi/gtest/schemas/invalid2.avpr b/libs/dfi/gtest/schemas/invalid2.avpr
deleted file mode 100644
index 8487d9bb..00000000
--- a/libs/dfi/gtest/schemas/invalid2.avpr
+++ /dev/null
@@ -1,50 +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"
- }
- }
-}
diff --git a/libs/dfi/gtest/schemas/simple.avdl b/libs/dfi/gtest/schemas/simple.avdl
deleted file mode 100644
index ac6c1789..00000000
--- a/libs/dfi/gtest/schemas/simple.avdl
+++ /dev/null
@@ -1,25 +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);
-}
diff --git a/libs/dfi/gtest/schemas/simple.avpr b/libs/dfi/gtest/schemas/simple.avpr
deleted file mode 100644
index 3303683c..00000000
--- a/libs/dfi/gtest/schemas/simple.avpr
+++ /dev/null
@@ -1,52 +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"
- }
- }
-}
diff --git a/libs/dfi/gtest/schemas/simple_min.avpr b/libs/dfi/gtest/schemas/simple_min.avpr
deleted file mode 100644
index 58bcce0c..00000000
--- a/libs/dfi/gtest/schemas/simple_min.avpr
+++ /dev/null
@@ -1,20 +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
diff --git a/libs/dfi/gtest/src/avro_descriptor_translator_tests.cpp b/libs/dfi/gtest/src/avro_descriptor_translator_tests.cpp
deleted file mode 100644
index 12e6aba2..00000000
--- a/libs/dfi/gtest/src/avro_descriptor_translator_tests.cpp
+++ /dev/null
@@ -1,186 +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 "gtest/gtest.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");
- va_end(ap);
- }
-
-
- 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);
- }
-}
-
-class AvroDescTranslatorTest : public ::testing::Test {
-public:
- AvroDescTranslatorTest() {
- descriptorTranslator_logSetup(stdLog, NULL, 3);
- dynInterface_logSetup(stdLog, NULL, 3);
- dynType_logSetup(stdLog, NULL, 3);
- dynCommon_logSetup(stdLog, NULL, 3);
- }
- ~AvroDescTranslatorTest() override {
- }
-
-};
-
-
-TEST_F(AvroDescTranslatorTest, simple) {
- simple();
-}
-
-TEST_F(AvroDescTranslatorTest, complex) {
- complex();
-}
-
-TEST_F(AvroDescTranslatorTest, invalid1) {
- invalid("schemas/invalid1.avpr");
-}
-
-TEST_F(AvroDescTranslatorTest, invalid2) {
- invalid("schemas/invalid2.avpr");
-}
-
diff --git a/libs/dfi/gtest/src/avrobin_serialization_tests.cpp b/libs/dfi/gtest/src/avrobin_serialization_tests.cpp
deleted file mode 100644
index 0a0ebdf3..00000000
--- a/libs/dfi/gtest/src/avrobin_serialization_tests.cpp
+++ /dev/null
@@ -1,612 +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 "gtest/gtest.h"
-
-#include <stdarg.h>
-
-
-extern "C" {
-#include "avrobin_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);
-}
-
-static const char *test1_descriptor = "I";
-
-static const char *test2_descriptor = "{IIII a b c d}";
-
-struct test2_type {
- int32_t a;
- int32_t b;
- int32_t c;
- int32_t d;
-};
-
-static const char *test3_descriptor = "{{I a}{I b} c d}";
-
-struct test3_type_subtype1 {
- int32_t a;
-};
-
-struct test3_type_subtype2 {
- int32_t b;
-};
-
-struct test3_type {
- struct test3_type_subtype1 c;
- struct test3_type_subtype2 d;
-};
-
-static const char *test4_descriptor = "F";
-
-static const char *test5_descriptor = "D";
-
-static const char *test6_descriptor = "t";
-
-static const char *test7_descriptor = "[I";
-
-struct test7_type {
- uint32_t cap;
- uint32_t len;
- int32_t *buf;
-};
-
-static const char *test8_descriptor = "[{DD one two}";
-
-struct test8_subtype {
- double one;
- double two;
-};
-
-struct test8_type {
- uint32_t cap;
- uint32_t len;
- struct test8_subtype *buf;
-};
-
-static const char *test9_descriptor = "[[F";
-
-struct test9_subtype {
- uint32_t cap;
- uint32_t len;
- float *buf;
-};
-
-struct test9_type {
- uint32_t cap;
- uint32_t len;
- struct test9_subtype *buf;
-};
-
-static const char *test10_descriptor = "*I";
-
-static const char *test11_descriptor = "{*{DD a b} c}";
-
-struct test11_subtype {
- double a;
- double b;
-};
-
-struct test11_type {
- struct test11_subtype *c;
-};
-
-static const char *test12_descriptor = "#OK=2;#NOK=4;#MAYBE=8;E";
-
-enum test12_enum {
- TEST12_ENUM_OK = 2,
- TEST12_ENUM_NOK = 4,
- TEST12_ENUM_MAYBE = 8
-};
-
-static void generalTests() {
- dyn_type *type;
- void *inst;
- uint8_t *serdata;
- size_t serdatalen;
- char *schema;
- int rc;
-
- int32_t test1_val = -444;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test1_descriptor, "test1", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test1_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(-444,*(int32_t*)inst);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test1.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- struct test2_type test2_val;
- test2_val.a = 10000;
- test2_val.b = 20000;
- test2_val.c = -30000;
- test2_val.d = -40000;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test2_descriptor, "test2", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test2_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(10000,(*(struct test2_type*)inst).a);
- ASSERT_EQ(20000,(*(struct test2_type*)inst).b);
- ASSERT_EQ(-30000,(*(struct test2_type*)inst).c);
- ASSERT_EQ(-40000,(*(struct test2_type*)inst).d);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test2.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- struct test3_type test3_val;
- test3_val.c.a = 101;
- test3_val.d.b = 99;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test3_descriptor, "test3", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test3_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(101,(*(struct test3_type*)inst).c.a);
- ASSERT_EQ(99,(*(struct test3_type*)inst).d.b);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test3.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- float test4_val = 1.234f;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test4_descriptor, "test4", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test4_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(1.234f,*(float*)inst);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test4.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- double test5_val = 2.345678;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test5_descriptor, "test5", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test5_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(2.345678,*(double*)inst);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test5.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- const char *test6_val = "This is a string.";
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test6_descriptor, "test6", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test6_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_STREQ("This is a string.",*(const char**)inst);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test6.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- struct test7_type test7_val;
- test7_val.cap = 8;
- test7_val.len = 8;
- test7_val.buf = (int32_t*)malloc(sizeof(int32_t) * test7_val.cap);
- for (unsigned int i=0; i<test7_val.len; i++) {
- test7_val.buf[i] = i;
- }
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test7_descriptor, "test7", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test7_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(8, (*(struct test7_type*)inst).cap);
- ASSERT_EQ(8, (*(struct test7_type*)inst).len);
- if ((*(struct test7_type*)inst).cap == 8 && (*(struct test7_type*)inst).len == 8) {
- for (int i=0; i<8; i++) {
- ASSERT_EQ(i, (*(struct test7_type*)inst).buf[i]);
- }
- }
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test7.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- free(test7_val.buf);
-
- struct test8_type test8_val;
- test8_val.cap = 128;
- test8_val.len = 64;
- test8_val.buf = (struct test8_subtype*)malloc(sizeof(struct test8_subtype) * test8_val.cap);
- for (int i=0; i<64; i++) {
- (test8_val.buf[i]).one = i * 3.333;
- (test8_val.buf[i]).two = i * 4.444;
- }
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test8_descriptor, "test8", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test8_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(64, (*(struct test8_type*)inst).cap);
- ASSERT_EQ(64, (*(struct test8_type*)inst).len);
- if ((*(struct test8_type*)inst).cap == 64 && (*(struct test8_type*)inst).len == 64) {
- for (int i=0; i<64; i++) {
- ASSERT_EQ( i * 3.333 , ((*(struct test8_type*)inst).buf[i]).one );
- ASSERT_EQ( i * 4.444 , ((*(struct test8_type*)inst).buf[i]).two );
- }
- }
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test8.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- free(test8_val.buf);
-
- struct test9_type test9_val;
- test9_val.cap = 64;
- test9_val.len = 64;
- test9_val.buf = (struct test9_subtype*)malloc(sizeof(struct test9_subtype) * test9_val.cap);
- for (int i=0; i<64; i++) {
- (test9_val.buf[i]).cap = 8;
- (test9_val.buf[i]).len = 8;
- (test9_val.buf[i]).buf = (float*)malloc(sizeof(float) * 8);
- for (int j=0; j<8; j++) {
- (test9_val.buf[i]).buf[j] = j * 1.234f;
- }
- }
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test9_descriptor, "test9", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test9_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(64, (*(struct test9_type*)inst).cap);
- ASSERT_EQ(64, (*(struct test9_type*)inst).len);
- if ((*(struct test9_type*)inst).cap == 64 && (*(struct test9_type*)inst).len == 64) {
- for (int i=0; i<64; i++) {
- ASSERT_EQ(8, ((*(struct test9_type*)inst).buf[i]).cap);
- ASSERT_EQ(8, ((*(struct test9_type*)inst).buf[i]).len);
- if ( ((*(struct test9_type*)inst).buf[i]).cap == 8 && ((*(struct test9_type*)inst).buf[i]).len == 8 ) {
- for (int j=0; j<8; j++) {
- ASSERT_EQ(j*1.234f, ((*(struct test9_type*)inst).buf[i]).buf[j]);
- }
- }
- }
- }
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test9.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- for (int i=0; i<64; i++) {
- free((test9_val.buf[i]).buf);
- }
- free(test9_val.buf);
-
- int32_t *test10_val = (int32_t*)malloc(sizeof(int32_t));
- *test10_val = 8765;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test10_descriptor, "test10", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test10_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(8765,*(*(int32_t**)inst));
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test10.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- free(test10_val);
-
- struct test11_type test11_val;
- test11_val.c = (struct test11_subtype *)malloc(sizeof(struct test11_subtype));
- test11_val.c->a = 1.234;
- test11_val.c->b = 2.345;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test11_descriptor, "test11", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test11_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(1.234,(*(struct test11_type *)inst).c->a);
- ASSERT_EQ(2.345,(*(struct test11_type *)inst).c->b);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test11.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-
- free(test11_val.c);
-
- enum test12_enum test12_val = TEST12_ENUM_NOK;
-
- type = NULL;
- inst = NULL;
- serdata = NULL;
- serdatalen = 0;
- schema = NULL;
- rc = dynType_parseWithStr(test12_descriptor, "test12", NULL, &type);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_serialize(type, &test12_val, &serdata, &serdatalen);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- rc = avrobinSerializer_deserialize(type, serdata, serdatalen, &inst);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- ASSERT_EQ(TEST12_ENUM_NOK,*(enum test12_enum*)inst);
- rc = avrobinSerializer_generateSchema(type, &schema);
- ASSERT_EQ(0, rc);
- if (rc == 0) {
- printf("%s\n", schema);
- rc = avrobinSerializer_saveFile("test12.avro", schema, serdata, serdatalen);
- ASSERT_EQ(0, rc);
- free(schema);
- }
- dynType_free(type, inst);
- }
- free(serdata);
- }
- dynType_destroy(type);
- }
-}
-
-}
-
-
-class AvrobinSerializerTests : public ::testing::Test {
-public:
- AvrobinSerializerTests() {
- int lvl = 1;
- avrobinSerializer_logSetup(stdLog, NULL, lvl);
- }
- ~AvrobinSerializerTests() override {
- }
-
-};
-
-TEST_F(AvrobinSerializerTests, GeneralTests) {
- generalTests();
-}
diff --git a/libs/dfi/gtest/src/dyn_avpr_function_tests.cpp b/libs/dfi/gtest/src/dyn_avpr_function_tests.cpp
deleted file mode 100644
index 6401aca6..00000000
--- a/libs/dfi/gtest/src/dyn_avpr_function_tests.cpp
+++ /dev/null
@@ -1,675 +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 "gtest/gtest.h"
-
-#include <celix_utils.h>
-#include <celix_compiler.h>
-#include <ffi.h>
-
-extern "C" {
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdarg.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);
- }
-}
-
-const char* theAvprFile = "{ \
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Void\", \
- \"alias\" : \"void\", \
- \"size\" : 4 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"VoidPtr\", \
- \"alias\" : \"void_ptr\", \
- \"size\" : 4 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"NativeInt\", \
- \"size\" : 4, \
- \"alias\" : \"native_int\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"String\", \
- \"alias\" : \"string\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"alias\" : \"double\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"StructString\", \
- \"fields\" : [ { \
- \"name\" : \"name\", \
- \"type\" : \"String\" \
- } , { \
- \"name\" : \"id\", \
- \"type\" : \"Sint\" \
- } ] \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"AStruct\", \
- \"namespace\" : \"nested.test.dt\", \
- \"fields\" : [ { \
- \"name\" : \"val1\", \
- \"type\" : \"test.dt.Sint\" \
- } , { \
- \"name\" : \"val2\", \
- \"type\" : \"test.dt.Sint\" \
- } , { \
- \"name\" : \"val3\", \
- \"type\" : \"test.dt.Double\" \
- } ] \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"MArray\", \
- \"fields\" : [ { \
- \"name\" : \"array\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"Double\"\
- } \
- } ] \
- } ] ,\
- \"messages\" : { \
- \"simpleFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Sint\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"Sint\" \
- } , { \
- \"name\" : \"arg3\", \
- \"type\" : \"Sint\" \
- } ],\
- \"response\" : \"Sint\" \
- }, \
- \"structFunc\" : {\
- \"namespace\" : \"nested.test.dt\", \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"test.dt.Sint\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"AStruct\" \
- } , { \
- \"name\" : \"arg3\", \
- \"type\" : \"test.dt.Double\" \
- } ],\
- \"response\" : \"test.dt.Double\" \
- }, \
- \"accessFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"nested.test.dt.AStruct\" \
- } , { \
- \"name\" : \"arg3\", \
- \"type\" : \"Double\" \
- } ],\
- \"response\" : \"test.dt.Void\" \
- }, \
- \"outFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"VoidPtr\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"arg3\", \
- \"type\" : \"Double\", \
- \"ptr\" : true \
- } ],\
- \"response\" : \"NativeInt\" \
- }, \
- \"seqFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"MArray\" \
- } ],\
- \"response\" : \"Void\" \
- }, \
- \"infoFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"int\" \
- } ],\
- \"response\" : \"Double\" \
- }, \
- \"arrayInFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"Double\" \
- } \
- } ],\
- \"response\" : \"Double\" \
- }, \
- \"arrayOutFunc\" : {\
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Double\" \
- } ],\
- \"response\" : { \
- \"type\" : \"array\",\
- \"items\" : \"Double\" \
- } \
- }, \
- \"stringOutFunc\" : {\
- \"request\" : [ ],\
- \"response\" : \"string\" \
- }, \
- \"structStringOutFunc\" : {\
- \"request\" : [ ],\
- \"response\" : \"StructString\" \
- }, \
- \"stringInFunc\" : {\
- \"request\" : [{\
- \"name\" : \"arg1\",\
- \"type\" : \"string\" \
- } ],\
- \"response\" : \"Void\"\
- }\
- }\
- }";
-
-
-class DynAvprFunctionTests : public ::testing::Test {
-public:
- DynAvprFunctionTests() {
- int lvl = 1;
- dynAvprFunction_logSetup(stdLog, nullptr, lvl);
- dynAvprType_logSetup(stdLog, nullptr, lvl);
- }
- ~DynAvprFunctionTests() override {
- }
-
-};
-
-// Test 1, simple function with three arguments and a return type
-static int avpr_example1(CELIX_UNUSED void* handle, int32_t a, int32_t b, int32_t c, int32_t * out) {
- EXPECT_EQ(2, a);
- EXPECT_EQ(4, b);
- EXPECT_EQ(8, c);
- *out = 1;
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example1) {
- auto fp = (void (*)()) avpr_example1;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.simpleFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
- int32_t a = 2;
- int32_t b = 4;
- int32_t c = 8;
- int32_t out = 0;
- int32_t * p_out = &out;
- void *values[5];
- values[0] = &handle_ptr;
- values[1] = &a;
- values[2] = &b;
- values[3] = &c;
- values[4] = &p_out;
- ffi_sarg rVal = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, values);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(1, out);
- ASSERT_EQ(0, rVal);
- dynFunction_destroy(dynFunc);
-}
-
-
-// Test 2, function with complex argument
-struct avpr_example2_arg2 {
- int32_t val1;
- int32_t val2;
- double val3;
-};
-
-static int avpr_example2(CELIX_UNUSED void* handle, int32_t arg1, struct avpr_example2_arg2 arg2, double arg3, double* out) {
- EXPECT_EQ(2, arg1);
- EXPECT_EQ(2, arg2.val1);
- EXPECT_EQ(3, arg2.val2);
- EXPECT_EQ(4.1, arg2.val3);
- EXPECT_EQ(8.1, arg3);
- *out = 2.2;
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example2) {
- auto fp = (void (*)()) avpr_example2;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "nested.test.dt.structFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
- int32_t a = 2;
- avpr_example2_arg2 arg2 {2, 3, 4.1};
-
- double c = 8.1;
- double out = 0.0;
- double* p_out = &out;
- void *values[5];
- values[0] = &handle_ptr;
- values[1] = &a;
- values[2] = &arg2;
- values[3] = &c;
- values[4] = &p_out;
- ffi_sarg rVal = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, values);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(0, rVal);
- ASSERT_EQ(2.2, out);
- dynFunction_destroy(dynFunc);
-}
-
-// Test 3, Test access of functions, see if arguments and result type can be accessed
-TEST_F(DynAvprFunctionTests, Example3) {
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.accessFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int nrOfArgs = dynFunction_nrOfArguments(dynFunc);
- ASSERT_EQ(3+1+1, nrOfArgs);
-
- dyn_type *arg1 = dynFunction_argumentTypeForIndex(dynFunc, 2);
- ASSERT_TRUE(arg1 != nullptr);
- ASSERT_EQ('{', (char) dynType_descriptorType(arg1));
-
- dyn_type *nonExist = dynFunction_argumentTypeForIndex(dynFunc, 10);
- ASSERT_TRUE(nonExist == nullptr);
-
- dyn_type *returnType = dynFunction_returnType(dynFunc);
- ASSERT_EQ('N', (char) dynType_descriptorType(returnType));
-
- dynFunction_destroy(dynFunc);
-}
-
-
-// Test 4, with void pointer and native output
-/*
-static int avpr_example4(CELIX_UNUSED void *handle, void *ptr, double a, double *out, int *out_2) {
- auto b = (double *)ptr;
- ASSERT_EQ(2.0, *b);
- ASSERT_EQ(2.0, a);
- *out = *b * a; // => out parameter
- *out_2 = 3;
- return 0;
-}
-
-TEST(DynAvprFunctionTests, Example4) {
- auto fp = (void(*)()) avpr_example4;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.outFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
- double result = -1.0;
- double *input = &result;
- double a = 2.0;
- void *ptr = &a;
- void *args[5];
- int out = 0;
- int* out_ptr = &out;
- args[0] = &handle_ptr;
- args[1] = &ptr;
- args[2] = &a;
- args[3] = &input;
- args[4] = &out_ptr;
- ffi_sarg rVal = 1;
- int rc = dynFunction_call(dynFunc, fp, &rVal, args);
-
- ASSERT_EQ(0, rc);
- ASSERT_EQ(4.0, result);
- ASSERT_EQ(3, out);
-
- auto inMemResult = (double *)calloc(1, sizeof(double));
- a = 2.0;
- ptr = &a;
- args[1] = &ptr;
- args[2] = &a;
- args[3] = &inMemResult;
- rVal = 0;
- rc = dynFunction_call(dynFunc, fp, &rVal, args);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(4.0, result);
- free(inMemResult);
- dynFunction_destroy(dynFunc);
-}
-*/
-
-// Test5, testing with sequence as argument
-struct tst_seq {
- uint32_t cap;
- uint32_t len;
- double *buf;
-};
-
-static int avpr_example5(CELIX_UNUSED void* handle, struct tst_seq seq, CELIX_UNUSED void* out) {
- EXPECT_EQ(4, seq.cap);
- EXPECT_EQ(2, seq.len);
- EXPECT_EQ(1.1, seq.buf[0]);
- EXPECT_EQ(2.2, seq.buf[1]);
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example5) {
- auto fp = (void(*)()) avpr_example5;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.seqFunc");
-
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
- double buf[4];
- buf[0] = 1.1;
- buf[1] = 2.2;
- struct tst_seq seq {4, 2, buf};
- int out = 0;
- int* out_ptr = &out;
-
- void *args[3];
- args[0] = &handle_ptr;
- args[1] = &seq;
- args[2] = &out_ptr;
- ffi_sarg retArg = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &retArg, args);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(0, retArg);
-
- dynFunction_destroy(dynFunc);
-}
-
-// Test 6, Test data accessible with handle
-struct info {
- char * name;
- int id;
-};
-
-static int avpr_example6(void *handle, int32_t id_modifier, double* out) {
- auto fake_this = (struct info *) handle;
- EXPECT_TRUE(fake_this != nullptr);
- EXPECT_TRUE(fake_this->name != nullptr);
- EXPECT_EQ(0, strcmp(fake_this->name, "test_name"));
- EXPECT_EQ(42, fake_this->id);
- *out = (double)(fake_this->id + id_modifier);
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example6) {
- auto fp = (void(*)()) avpr_example6;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.infoFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- info handle {strdup("test_name"), 42};
- ASSERT_TRUE(handle.name != nullptr);
-
- struct info * handle_ptr = &handle;
- int32_t argument = 58;
- double out = 0.0;
- double * out_ptr = &out;
-
- void *values[3];
- values[0] = &handle_ptr;
- values[1] = &argument;
- values[2] = &out_ptr;
- ffi_sarg rVal = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, values);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(100.0, out);
- ASSERT_EQ(0, rVal);
- dynFunction_destroy(dynFunc);
- free(handle.name);
-}
-
-//Test 7, Test function with array as parameter
-struct double_seq {
- uint32_t cap;
- uint32_t len;
- double *buf;
-};
-
-static int avpr_example7(CELIX_UNUSED void *handle, struct double_seq seq_in, double* out) {
- EXPECT_EQ(2, seq_in.cap);
- EXPECT_EQ(2, seq_in.len);
- *out = seq_in.buf[0] + seq_in.buf[1];
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example7) {
- auto fp = (void(*)()) avpr_example7;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.arrayInFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
-
- double buf[2];
- buf[0] = 1.101;
- buf[1] = 2.202;
- double_seq s_seq {2, 2, buf};
-
- double out = 0.0;
- double *out_ptr = &out;
-
- void *args[3];
- args[0] = &handle_ptr;
- args[1] = &s_seq;
- args[2] = &out_ptr;
- ffi_sarg rVal = 0;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, args);
- ASSERT_EQ(0, rc);
- ASSERT_NEAR(3.303, out, 0.001);
-
- dynFunction_destroy(dynFunc);
-}
-
-//Test 8, Test function with array as return value
-static int avpr_example8(CELIX_UNUSED void *handle, double arg1, struct double_seq** out) {
- EXPECT_NEAR(2.0, arg1, 0.001);
- EXPECT_EQ(3, (*out)->cap);
- (*out)->buf[0] = 0.0;
- (*out)->buf[1] = 1.1;
- (*out)->buf[2] = 2.2;
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example8) {
- auto fp = (void(*)()) avpr_example8;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.arrayOutFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
-
- double arg1 = 2.0;
-
- double buf[3];
- buf[0] = -1.1;
- buf[1] = 0.0;
- buf[2] = 0.0;
- double_seq dseq {3, 3, buf};
- struct double_seq * out_ptr = &dseq;
- struct double_seq ** out_ptr_ptr = &out_ptr;
-
- void *args[3];
- args[0] = &handle_ptr;
- args[1] = &arg1;
- args[2] = &out_ptr_ptr;
- ffi_sarg rVal = 0;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, args);
- ASSERT_EQ(0, rc);
- ASSERT_NEAR(0.0, buf[0], 0.001);
- ASSERT_NEAR(1.1, buf[1], 0.001);
- ASSERT_NEAR(2.2, buf[2], 0.001);
-
- dynFunction_destroy(dynFunc);
-}
-
-// Test 9, Test function with string as return value
-static int avpr_example9(CELIX_UNUSED void *handle, char** out) {
- *out = strdup("result_out");
- EXPECT_TRUE(*out != nullptr);
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example9) {
- auto fp = (void(*)()) avpr_example9;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.stringOutFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
-
- char * out = nullptr;
- char ** out_ptr = &out;
-
- void *args[2];
- args[0] = &handle_ptr;
- args[1] = &out_ptr;
- ffi_sarg rVal = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, args);
- ASSERT_EQ(0, rc);
- ASSERT_STREQ("result_out", out);
-
- free(out);
- dynFunction_destroy(dynFunc);
-}
-
-// Test 10, Test function with object with string as return value
-extern "C" {
- struct tst_10 {
- char * name;
- int32_t id;
- };
-}
-
-static int avpr_example10(CELIX_UNUSED void *handle, struct tst_10 ** out) {
- (*out)->name = strdup("my_new_char");
- EXPECT_TRUE((*out)->name != nullptr);
- (*out)->id = 132;
- return 0;
-}
-
-TEST_F(DynAvprFunctionTests, Example10) {
- auto fp = (void(*)()) avpr_example10;
- dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.structStringOutFunc");
- ASSERT_TRUE(dynFunc != nullptr);
-
- int handle = 0;
- int* handle_ptr = &handle;
-
- tst_10 out {nullptr, 0};
- struct tst_10 * out_ptr = &out;
- struct tst_10 ** out_ptr_ptr = &out_ptr;
-
- void *args[2];
- args[0] = &handle_ptr;
- args[1] = &out_ptr_ptr;
- ffi_sarg rVal = 1;
-
- int rc = dynFunction_call(dynFunc, fp, &rVal, args);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(132, out.id);
- ASSERT_STREQ("my_new_char", out.name);
-
- free(out.name);
- dynFunction_destroy(dynFunc);
-}
-
-//FIXME issue #179
-//extern "C" {
-//static int avpr_example11(void *handle, char *arg1) {
-// if (handle != nullptr && strncmp("input string test", arg1, 1024) == 0) {
-// return 0;
-// }
-// return 1;
-//}
-//
-//static bool test_example11() {
-// auto fp = (void(*)()) avpr_example11;
-// dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.stringInFunc");
-//
-// int handle = 0;
-// void* handle_ptr = &handle;
-//
-// char *input = celix_utils_strdup("input string test");
-//
-// void *args[2];
-// args[0] = &handle_ptr;
-// args[1]= &input;
-// int rVal = 1;
-//
-// int rc = 0;
-// if (dynFunc != nullptr) {
-// rc = dynFunction_call(dynFunc, fp, &rVal, args);
-// dynFunction_destroy(dynFunc);
-// }
-// free(input);
-//
-// return dynFunc != nullptr && rc == 0 && rVal == 0;
-//}
-//}
-//
-//TEST_F(DynAvprFunctionTests, Example11) {
-// //NOTE only using libffi with extern C, because combining libffi with EXPECT_*/ASSERT_* call leads to
-// //corrupted memory. Note that libffi is a function for interfacing with C not C++
-// EXPECT_TRUE(test_example11());
-//}
diff --git a/libs/dfi/gtest/src/dyn_avpr_interface_tests.cpp b/libs/dfi/gtest/src/dyn_avpr_interface_tests.cpp
deleted file mode 100644
index 32d13995..00000000
--- a/libs/dfi/gtest/src/dyn_avpr_interface_tests.cpp
+++ /dev/null
@@ -1,179 +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 "gtest/gtest.h"
-#include "version.h"
-
-extern "C" {
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdarg.h>
-
- #include "dyn_common.h"
- #include "dyn_interface.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);
- }
-}
-
-const char* theInvalidAvprFile = "{ \
- \"protocol\" : \"the_interface\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.1.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- } ] ,\
- \"messages\" : { \
- \"aFunc\" : {\
- \"request\" : [ ],\
- \"response\" : \"Sint\" \
- } \
- } \
- }";
-
-const char* theBigAvprFile = "{ \
- \"protocol\" : \"the_interface\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.1.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- } , { \
- \"type\" : \"fixed\", \
- \"namespace\" : \"nested\", \
- \"name\" : \"Double\", \
- \"alias\": \"double\", \
- \"size\" : 8 \
- } ] ,\
- \"messages\" : { \
- \"simpleFunc\" : {\
- \"index\" : 0, \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Sint\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"Sint\" \
- } , { \
- \"name\" : \"arg3\", \
- \"type\" : \"Sint\", \
- \"ptr\" : true \
- } ],\
- \"response\" : \"Sint\" \
- }, \
- \"aFunc\" : {\
- \"index\" : 1, \
- \"request\" : [ {\
- \"name\" : \"m_arg\", \
- \"type\" : \"Sint\" \
- } ],\
- \"response\" : \"Sint\" \
- } \
- } \
- }";
-
-
-class DynAvprInterfaceTests : public ::testing::Test {
-public:
- DynAvprInterfaceTests() {
- int lvl = 1;
- dynAvprInterface_logSetup(stdLog, nullptr, lvl);
- dynAvprFunction_logSetup(stdLog, nullptr, lvl);
- dynAvprType_logSetup(stdLog, nullptr, lvl);
- }
- ~DynAvprInterfaceTests() override {
- }
-
-};
-
-static void checkInterfaceVersion(dyn_interface_type* dynIntf, const char* v) {
- int status;
-
- char *version = nullptr;
- status = dynInterface_getVersionString(dynIntf, &version);
- ASSERT_EQ(0, status);
- ASSERT_STREQ(v, version);
- version_pt msgVersion = nullptr, localMsgVersion = nullptr;
- int cmpVersion = -1;
- version_createVersionFromString(version, &localMsgVersion);
- status = dynInterface_getVersion(dynIntf, &msgVersion);
- ASSERT_EQ(0, status);
- version_compareTo(msgVersion, localMsgVersion, &cmpVersion);
- ASSERT_EQ(cmpVersion, 0);
- version_destroy(localMsgVersion);
-}
-
-// Test 1, simply see if parsing works and if parsed correctly
-TEST_F(DynAvprInterfaceTests, Example1) {
- dyn_interface_type *dynIntf = dynInterface_parseAvprWithStr(theBigAvprFile);
- ASSERT_TRUE(dynIntf != nullptr);
-
- // Check version
- checkInterfaceVersion(dynIntf, "1.1.0");
-
- // Check name
- char *name = nullptr;
- dynInterface_getName(dynIntf, &name);
- ASSERT_TRUE(name != nullptr);
- ASSERT_STREQ("the_interface", name);
-
- // Check annotation (namespace)
- char *annVal = nullptr;
- dynInterface_getAnnotationEntry(dynIntf, "namespace", &annVal);
- ASSERT_TRUE(annVal != nullptr);
- ASSERT_STREQ("test.dt", annVal);
-
- // Check nonexisting
- char *nonExist = nullptr;
- dynInterface_getHeaderEntry(dynIntf, "nonExisting", &nonExist);
- ASSERT_TRUE(nonExist == nullptr);
-
- // Get lists of methods
- struct methods_head *list = nullptr;
- int status = dynInterface_methods(dynIntf, &list);
- ASSERT_TRUE(status == 0);
- ASSERT_TRUE(list != nullptr);
-
- int count = dynInterface_nrOfMethods(dynIntf);
- ASSERT_EQ(2, count);
-
- dynInterface_destroy(dynIntf);
-}
-
-// Invalid tests
-TEST_F(DynAvprInterfaceTests, InvalidExample) {
- dyn_interface_type *dynIntf = dynInterface_parseAvprWithStr(theInvalidAvprFile);
- ASSERT_TRUE(dynIntf == nullptr);
-}
-
diff --git a/libs/dfi/gtest/src/dyn_avpr_tests.cpp b/libs/dfi/gtest/src/dyn_avpr_tests.cpp
deleted file mode 100644
index cdb12d74..00000000
--- a/libs/dfi/gtest/src/dyn_avpr_tests.cpp
+++ /dev/null
@@ -1,615 +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 "gtest/gtest.h"
-
-#include <stdarg.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-
-static void stdLogA(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 runTestA(const char *descriptorStr, const char *exName, int expectedType) {
- dyn_type *type;
- type = dynType_parseAvprWithStr(descriptorStr, exName);
-
- if (type != nullptr) {
- ASSERT_EQ(expectedType, dynType_type(type));
- dynType_destroy(type);
- } else {
- ASSERT_EQ(1, 0);
- }
-}
-
-const char* theTestCase = "{ \
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.1.9\", \
- \"CpfCInclude\" : \"time.h\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"uint\", \
- \"version\" : \"2.1.9\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"ulong\", \
- \"size\" : 8, \
- \"namespace\" : \"blah.test.dt\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"double\", \
- \"alias\" : \"double\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"B\", \
- \"fields\" : [ \
- { \
- \"name\" : \"aa\", \
- \"type\" : \"uint\" \
- }, { \
- \"name\" : \"bb\", \
- \"type\" : \"uint\" \
- }, { \
- \"name\" : \"cc\", \
- \"type\" : \"double\" \
- }] \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Alias\", \
- \"alias\" : \"other.dt.long\", \
- \"size\" : 7 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"long\", \
- \"size\" : 8, \
- \"namespace\" : \"other.dt\", \
- \"signed\" : true \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"A\", \
- \"namespace\" : \"blah.test.dt\", \
- \"fields\" : [\
- { \
- \"name\" : \"x\", \
- \"type\" : \"test.dt.B\" \
- },\
- { \
- \"name\" : \"y\", \
- \"type\" : \"ulong\" \
- }\
- ] \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"V\", \
- \"fields\" : [\
- {\
- \"name\" : \"elem\", \
- \"type\" : {\
- \"type\" : \"array\",\
- \"items\" : \"uint\",\
- \"static\" : 3\
- }\
- }\
- ]\
- }, { \
- \"type\" : \"enum\", \
- \"name\" : \"EnumWithValue\", \
- \"EnumValues\" : [ \"A = 3\", \"B= 1234\" ],\
- \"symbols\" : [\"A\", \"B\"]\
- }, { \
- \"type\" : \"enum\", \
- \"name\" : \"EnumWithoutValue\", \
- \"symbols\" : [\"A\", \"B\"]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"RecordWithSimpleTypes\", \
- \"fields\" : [ {\
- \"name\" : \"data\", \
- \"type\" :\"int\" \
- } ]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"Anne\", \
- \"alias\" : \"CoolType\", \
- \"MsgId\" : 1000, \
- \"Invalid\" : {}, \
- \"fields\" : [ {\
- \"name\" : \"data\", \
- \"type\" :\"test.dt.double\" \
- } ]\
- }, { \
- \"type\" : \"record\", \
- \"namespace\" : \"N\", \
- \"name\" : \"Node\", \
- \"fields\" : [ {\
- \"name\" : \"data\", \
- \"type\" :\"test.dt.double\" \
- }, {\
- \"name\" : \"ne_elem_left\", \
- \"type\" : \"Node\", \
- \"ptr\" : true \
- }, {\
- \"name\" : \"ne_elem_right\", \
- \"type\" : \"Node\", \
- \"ptr\" : true \
- } ]\
- } ] ,\
- \"messages\" : {} \
- }";
-
-const char* nestedArray = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"uint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"NA\", \
- \"fields\" : [\
- { \
- \"name\" : \"members\", \
- \"type\" : {\
- \"type\" : \"array\",\
- \"items\" : {\
- \"type\" : \"array\",\
- \"items\" : \"uint\",\
- \"static\" : 3\
- },\
- \"static\" : 3\
- }\
- } ] \
- }] , \
- \"messages\" : {} \
- }";
-
-const char* referenceTestCase = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.dt\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"uint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"X\", \
- \"fields\" : [\
- { \
- \"name\" : \"xx\", \
- \"type\" : \"uint\" \
- }, { \
- \"name\" : \"level_a\", \
- \"type\" : \"X\", \
- \"ptr\" : true \
- }, { \
- \"name\" : \"level_b\", \
- \"type\" : \"X\", \
- \"ptr\" : true \
- } ] \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"R\", \
- \"fields\" : [\
- { \
- \"name\" : \"data\", \
- \"type\" : \"X\", \
- \"ptr\" : true \
- } ] \
- }] , \
- \"messages\" : {} \
- }";
-
-const char* aliasTestCase = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"common.dt\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Rad\", \
- \"size\" : 4, \
- \"alias\" : \"common.dt.Float\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Float\", \
- \"size\" : 4, \
- \"alias\" : \"float\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"Polar_2d\", \
- \"fields\" : [ { \
- \"name\" : \"range\", \
- \"type\" : \"Float\" \
- }, { \
- \"name\" : \"azimuth\", \
- \"type\" : \"Rad\" \
- } ] \
- } ] , \
- \"messages\" : {} \
- }";
-
-const char* arrayIntTestCase = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"common.dt\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"record\", \
- \"name\" : \"SimpleArray\", \
- \"fields\" : [ { \
- \"name\" : \"array\", \
- \"type\" : {\
- \"type\" : \"array\",\
- \"items\" : \"int\" \
- } \
- } ] \
- } ] , \
- \"messages\" : {} \
- }";
-
-
-/*********************************************************************************
- * Type building tests
- */
-
-class DynAvprTypeTests : public ::testing::Test {
-public:
- DynAvprTypeTests() {
- dynAvprType_logSetup(stdLogA, nullptr, 1);
- }
- ~DynAvprTypeTests() override {
- }
-
-};
-
-TEST_F(DynAvprTypeTests, SimpleTest) {
- runTestA(theTestCase, "test.dt.uint", DYN_TYPE_SIMPLE);
-}
-
-TEST_F(DynAvprTypeTests, SimpleSimpleTest) {
- runTestA(theTestCase, "test.dt.RecordWithSimpleTypes", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, ComplexTest) {
- runTestA(theTestCase, "blah.test.dt.A", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, EnumTest2) {
- runTestA(theTestCase, "test.dt.EnumWithValue", DYN_TYPE_SIMPLE);
-}
-
-TEST_F(DynAvprTypeTests, EnumTest) {
- runTestA(theTestCase, "test.dt.EnumWithoutValue", DYN_TYPE_SIMPLE);
-}
-
-TEST_F(DynAvprTypeTests, ArrayTest) {
- runTestA(theTestCase, "test.dt.V", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, NestedArrayTest) {
- runTestA(nestedArray, "test.dt.NA", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, ComplexComplexTest) {
- runTestA(theTestCase, "test.dt.B", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, ReferenceTest) {
- runTestA(referenceTestCase, "test.dt.R", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, AliasTest) {
- runTestA(theTestCase, "test.dt.Alias", DYN_TYPE_SIMPLE);
-}
-
-TEST_F(DynAvprTypeTests, ComplexAliasTest) {
- runTestA(aliasTestCase, "common.dt.Polar_2d", DYN_TYPE_COMPLEX);
-}
-
-TEST_F(DynAvprTypeTests, ArrayWithSimpleTest) { //TODO: fix this testcase
- runTestA(arrayIntTestCase, "common.dt.SimpleArray", DYN_TYPE_COMPLEX);
-}
-
-/*********************************************************************************
- * Assignment tests + version testing
- */
-
-void test_version(dyn_type* type, const std::string& version_string) {
- struct meta_entry *entry = nullptr;
- struct meta_properties_head *entries = nullptr;
- ASSERT_EQ(0, dynType_metaEntries(type, &entries));
- ASSERT_FALSE(TAILQ_EMPTY(entries));
-
- const std::string entry_value {"version"};
- bool compared = false;
- TAILQ_FOREACH(entry, entries, entries) {
- if (entry_value == entry->name) {
- ASSERT_STREQ(version_string.c_str(), entry->value);
- compared = true;
- }
- }
- ASSERT_TRUE(compared); //"Expect a comparison, otherwise no version meta info is available");
-}
-
-class DynAvprAssignTests : public ::testing::Test {
-public:
- DynAvprAssignTests() {
- dynAvprType_logSetup(stdLogA, nullptr, 1);
- }
- ~DynAvprAssignTests() override {
- }
-
-};
-
-TEST_F(DynAvprAssignTests, AssignSimpleTest) {
- // Build type
- dyn_type* type = dynType_parseAvprWithStr(theTestCase, "test.dt.uint");
- ASSERT_TRUE(type != nullptr);
-
- // set value
- uint32_t simple = 0;
- uint32_t nv = 42;
- dynType_simple_setValue(type, &simple, &nv);
-
- ASSERT_EQ(42, simple);
- test_version(type, "2.1.9");
- dynType_destroy(type);
-}
-
-TEST_F(DynAvprAssignTests, AssignComplexTest) {
- // Build type
- struct exA {
- struct {
- uint32_t aa;
- uint32_t bb;
- double cc;
- } x;
- uint64_t y;
- };
-
-
- dyn_type *type = dynType_parseAvprWithStr(theTestCase, "blah.test.dt.A");
- ASSERT_TRUE(type != nullptr);
-
- // set example values
- uint32_t a_x_aa = 52;
- uint32_t a_x_bb = 42;
- double a_x_cc = 31.13;
- uint64_t a_y = 1001001;
-
- // Simple element in complex
- exA inst {{0, 0, 0.0}, 0};
- dynType_complex_setValueAt(type, 1, &inst, &a_y);
- ASSERT_EQ(1001001, inst.y);
-
- // Complex element in complex type, first acquire subtype, then check similar to simple type
- void *loc = nullptr;
- dyn_type *subType = nullptr;
- dynType_complex_valLocAt(type, 0, static_cast<void*>(&inst), &loc);
- dynType_complex_dynTypeAt(type, 0, &subType);
-
- dynType_complex_setValueAt(subType, 0, &inst.x, &a_x_aa);
- ASSERT_EQ(52, inst.x.aa);
-
- dynType_complex_setValueAt(subType, 1, &inst.x, &a_x_bb);
- ASSERT_EQ(42, inst.x.bb);
- dynType_complex_setValueAt(subType, 2, &inst.x, &a_x_cc);
- ASSERT_EQ(31.13, inst.x.cc);
-
- test_version(type, "1.1.9");
- dynType_destroy(type);
-}
-
-TEST_F(DynAvprAssignTests, AssignComplexSimpleTest) {
- // Build type
- struct exB {
- int32_t b;
- };
-
- dyn_type *type = dynType_parseAvprWithStr(theTestCase, "test.dt.RecordWithSimpleTypes");
- ASSERT_TRUE(type != nullptr);
-
- // set example values
- int32_t b_b = 5301;
-
- exB inst {0};
- dynType_complex_setValueAt(type, 0, &inst, &b_b);
- ASSERT_EQ(5301, inst.b);
-
- test_version(type, "1.1.9");
- dynType_destroy(type);
-}
-
-
-TEST_F(DynAvprAssignTests, AssignPtrTest) {
- // Build type
-
- struct exNode {
- double data;
- exNode *ne_elem_left;
- exNode *ne_elem_right;
- };
-
- dyn_type* type = dynType_parseAvprWithStr(theTestCase, "N.Node");
- ASSERT_TRUE(type != nullptr);
-
- // right tree
- exNode rightrightright {2.0, nullptr, nullptr};
- exNode rightleft {0.5, nullptr, nullptr};
- exNode rightright {1.5, nullptr, &rightrightright};
- exNode right {1.0, &rightleft, &rightright};
-
- // left tree
- exNode leftleft {-1.5, nullptr, nullptr};
- exNode leftright {-0.5, nullptr, nullptr};
- exNode left {-1.0, &leftleft, &leftright};
-
- // Base
- exNode base {0.0, &left, &right};
-
- double nv = 101.101;
- dynType_complex_setValueAt(type, 0, &base, &nv);
- ASSERT_EQ(101.101, base.data);
-
- test_version(type, "1.1.9");
- dynType_destroy(type);
-}
-
-TEST_F(DynAvprAssignTests, AssignEnumTest) {
- // Build type
- dyn_type* type = dynType_parseAvprWithStr(theTestCase, "test.dt.EnumWithValue");
- dyn_type* type_2 = dynType_parseAvprWithStr(theTestCase, "test.dt.EnumWithoutValue");
- ASSERT_TRUE(type != nullptr);
- ASSERT_TRUE(type_2 != nullptr);
-
- // Print type
- dynType_print(type, stdout);
- dynType_print(type_2, stdout);
-
- // set value
- enum exEnumV {A=3, B=1234};
- enum exEnumV mEnum = B;
- enum exEnumV nv = A;
-
- dynType_simple_setValue(type, &mEnum, &nv);
-
- ASSERT_EQ(A, mEnum);
- test_version(type, "1.1.9");
- dynType_destroy(type);
- dynType_destroy(type_2);
-}
-
-TEST_F(DynAvprAssignTests, AssignArrayTest) {
- // Build type
- struct exV_sequence {
- uint32_t cap;
- uint32_t len;
- uint32_t **buf;
- };
-
- struct exV {
- struct exV_sequence elem;
- };
-
- exV inst {exV_sequence{0,0, nullptr}};
- exV_sequence *s = &inst.elem;
-
- dyn_type* type = dynType_parseAvprWithStr(theTestCase, "test.dt.V");
- ASSERT_TRUE(type != nullptr);
-
- // set value
- void *loc = nullptr;
- dyn_type *subType = nullptr;
- dynType_complex_valLocAt(type, 0, static_cast<void*>(&inst), &loc);
- dynType_complex_dynTypeAt(type, 0, &subType);
- int res = dynType_alloc(subType, reinterpret_cast<void**>(&s));
- ASSERT_EQ(0, res);
- ASSERT_TRUE(s != nullptr);
-
- dynType_free(type, s);
- test_version(type, "1.1.9");
- dynType_destroy(type);
-}
-
-TEST_F(DynAvprAssignTests, AnnotationTest) {
- dyn_type* type = dynType_parseAvprWithStr(theTestCase, "test.dt.Anne");
- ASSERT_TRUE(type != nullptr);
-
- // get value for meta entry
- struct meta_entry *entry = nullptr;
- struct meta_properties_head *entries = nullptr;
- ASSERT_EQ(0, dynType_metaEntries(type, &entries));
- ASSERT_FALSE(TAILQ_EMPTY(entries));
-
- const std::string msg_id_entry {"MsgId"};
- bool compared = false;
-
- TAILQ_FOREACH(entry, entries, entries) {
- printf("Got an entry: %s\n", entry->name);
- if (msg_id_entry == entry->name) {
- ASSERT_STREQ("1000", entry->value);
- compared = true;
- }
- }
- ASSERT_TRUE(compared); //"Expect a comparison, otherwise no msg id entry available");
-
- dynType_destroy(type);
-}
-
-/*********************************************************************************
- * Invalid tests
- */
-
-class DynAvprInvalidTests : public ::testing::Test {
-public:
- DynAvprInvalidTests() {
- dynAvprType_logSetup(stdLogA, nullptr, 1);
- }
- ~DynAvprInvalidTests() override {
- }
-
-};
-
-TEST_F(DynAvprInvalidTests, InvalidJson) {
- dyn_type* type = dynType_parseAvprWithStr("{", "test.invalid.type"); // Json error
- ASSERT_TRUE(type == nullptr);
-}
-
-TEST_F(DynAvprInvalidTests, InvalidJsonObject) {
- dyn_type* type = dynType_parseAvprWithStr("[]", "test.invalid.type"); // Root should be object not list
- ASSERT_TRUE(type == nullptr);
- type = dynType_parseAvprWithStr("{}", "test.invalid.type"); // Root should have a namespace
- ASSERT_TRUE(type == nullptr);
- type = dynType_parseAvprWithStr(R"({"namespace":"nested"})", "test.invalid.type"); // Root should have types array
- ASSERT_TRUE(type == nullptr);
- type = dynType_parseAvprWithStr(
- R"({"namespace":"nested", "types" : [] })"
- , "test.invalid.type"); // types is empty, so not found
- ASSERT_TRUE(type == nullptr);
- type = dynType_parseAvprWithStr(
- "{\"namespace\":\"nested\", \"types\" : [\
- { \"type\" : \"record\", \"name\" : \"IncompleteStruct\", \"fields\" : [\
- { \"name\" : \"Field1\", \"type\" : \"NonExisting\" } ] } \
- ] }"
- , "nested.IncompleteStruct"); // struct misses definition
- ASSERT_TRUE(type == nullptr);
- type = dynType_parseAvprWithStr(
- "{\"namespace\":\"nested\", \"types\" : [\
- { \"type\" : \"record\", \"name\" : \"IncompleteStruct\", \"fields\" : [\
- { \"name\" : \"Field1\" } ] } \
- ] }"
- , "nested.IncompleteStruct"); // struct entry misses type
- ASSERT_TRUE(type == nullptr);
- // None of the above testcases should crash the parser
-}
\ No newline at end of file
diff --git a/libs/dfi/gtest/src/json_rpc_avpr_tests.cpp b/libs/dfi/gtest/src/json_rpc_avpr_tests.cpp
deleted file mode 100644
index fb9c66b4..00000000
--- a/libs/dfi/gtest/src/json_rpc_avpr_tests.cpp
+++ /dev/null
@@ -1,391 +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 "gtest/gtest.h"
-
-extern "C" {
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdarg.h>
- #include <assert.h>
- #include <float.h>
-
- #include <ffi.h>
-
- #include "dyn_common.h"
- #include "dyn_type.h"
- #include "dyn_interface.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);
- }
-}
-
-extern "C" {
- const char* sourceAvprFile = "{ \
- \"protocol\" : \"calculator\", \
- \"namespace\" : \"test.rpc\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"alias\": \"double\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"String\", \
- \"alias\": \"string\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"TwoDoubles\", \
- \"fields\" : [ { \
- \"name\" : \"a\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"b\", \
- \"type\" : \"Double\" \
- } ] \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"StatsResult\", \
- \"fields\" : [ { \
- \"name\" : \"average\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"min\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"max\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"input\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"Double\"\
- } \
- } ] \
- } ] ,\
- \"messages\" : { \
- \"add\" : {\
- \"index\" : 0, \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"Double\" \
- } ],\
- \"response\" : \"Double\" \
- }, \
- \"sub\" : {\
- \"index\" : 1, \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Double\" \
- } , { \
- \"name\" : \"arg2\", \
- \"type\" : \"Double\" \
- } ],\
- \"response\" : \"Double\" \
- }, \
- \"sqrt\" : {\
- \"index\" : 2, \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : \"Double\" \
- } ],\
- \"response\" : \"Double\" \
- }, \
- \"stats\" : {\
- \"index\" : 3, \
- \"request\" : [ {\
- \"name\" : \"arg1\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"Double\"\
- } \
- } ],\
- \"response\" : \"StatsResult\" \
- }, \
- \"retArray\" : {\
- \"index\" : 0, \
- \"request\" : [ ],\
- \"response\" : { \
- \"type\" : \"array\",\
- \"items\" : \"TwoDoubles\"\
- } \
- }, \
- \"getName\" : {\
- \"index\" : 0, \
- \"request\" : [ ],\
- \"response\" : \"String\" \
- } \
- } \
- }";
-}
-
-class JsonAvprRpcTests : public ::testing::Test {
-public:
- JsonAvprRpcTests() {
- int lvl = 1;
- dynCommon_logSetup(stdLog, nullptr, lvl);
- dynType_logSetup(stdLog, nullptr,lvl);
- dynFunction_logSetup(stdLog, nullptr,lvl);
- dynInterface_logSetup(stdLog, nullptr,lvl);
- jsonSerializer_logSetup(stdLog, nullptr, lvl);
- jsonRpc_logSetup(stdLog, nullptr, lvl);
- }
- ~JsonAvprRpcTests() override {
- }
-
-};
-
-TEST_F(JsonAvprRpcTests, prep) {
- dyn_function_type * func = dynFunction_parseAvprWithStr(sourceAvprFile, "test.rpc.add");
- ASSERT_TRUE(func != nullptr);
- int nof_args = dynFunction_nrOfArguments(func);
- ASSERT_EQ(4, nof_args);
-
- // Msg
- char *result = nullptr;
- void *handle = nullptr;
-
- double arg1 = 1.0;
- double arg2 = 2.0;
-
- void *args[4];
- args[0] = &handle;
- args[1] = &arg1;
- args[2] = &arg2;
-
- int rc = jsonRpc_prepareInvokeRequest(func, "add", args, &result);
- ASSERT_EQ(0, rc);
-
- ASSERT_TRUE(strstr(result, "\"add\"") != nullptr);
- ASSERT_TRUE(strstr(result, "1.0") != nullptr);
- ASSERT_TRUE(strstr(result, "2.0") != nullptr);
-
- // Reply
- const char *reply = "{\"r\": 2.2}";
- double calc_result = -1.0;
- double *out = &calc_result;
- //double **out_ptr = &out;
- args[3] = &out;
-
- int rsErrno = 0;
- rc = jsonRpc_handleReply(func, reply, args, &rsErrno);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(0, rsErrno);
- ASSERT_NEAR(2.2, calc_result, 0.001);
-
- free(result);
- dynFunction_destroy(func);
-}
-
-// Test handle out
-extern "C" {
- struct tst_seq {
- uint32_t cap;
- uint32_t len;
- double *buf;
- };
-
- struct tst_StatsResult {
- double average;
- double min;
- double max;
- tst_seq input;
- };
-}
-
-TEST_F(JsonAvprRpcTests, handle_out) {
- dyn_interface_type * intf = dynInterface_parseAvprWithStr(sourceAvprFile);
- ASSERT_TRUE(intf != nullptr);
-
- methods_head *head;
- dynInterface_methods(intf, &head);
-
- dyn_function_type *func = nullptr;
- method_entry *entry = nullptr;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(entry->name, "stats") == 0) {
- func = entry->dynFunc;
- break;
- }
- }
- ASSERT_TRUE(func != nullptr);
- int nof_args = dynFunction_nrOfArguments(func);
- ASSERT_EQ(3, nof_args);
-
- const char *reply = R"({"r":{"input":[1.0,2.0],"max":2.0,"average":1.5,"min":1.0}})";
-
- void *args[3];
- args[0] = nullptr;
- args[1] = nullptr;
- args[2] = nullptr;
-
- struct tst_StatsResult *result = nullptr;
- void *out = &result;
- args[2] = &out;
-
- int rsErrno = 0;
- int rc = jsonRpc_handleReply(func, reply, args, &rsErrno);
- ASSERT_EQ(0, rc);
- ASSERT_EQ(0, rsErrno);
- ASSERT_TRUE(result != nullptr);
- ASSERT_EQ(1.5, result->average);
-
- free(result->input.buf);
- free(result);
- dynInterface_destroy(intf);
-}
-
-
-// Test pre allocated
-
-extern "C" {
- 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 *, tst_seq, tst_StatsResult **);
- };
-
- int xadd(void*, double a, double b, double *result) {
- *result = a + b;
- return 0;
- }
-}
-
-TEST_F(JsonAvprRpcTests, preallocated) {
- dyn_interface_type * intf = dynInterface_parseAvprWithStr(sourceAvprFile);
- ASSERT_TRUE(intf != nullptr);
-
- char *result = nullptr;
- tst_serv serv {nullptr, xadd, nullptr, nullptr, nullptr};
-
- int rc = jsonRpc_call(intf, &serv, R"({"m": "add", "a": [1.0,2.0]})", &result);
- ASSERT_EQ(0, rc);
- ASSERT_TRUE(result != nullptr);
- ASSERT_TRUE(strstr(result, "3.0") != nullptr);
-
- free(result);
- dynInterface_destroy(intf);
-}
-
-
-// Test output
-extern "C" {
- int xstats(void*, struct tst_seq input, struct tst_StatsResult **out) {
- assert(out != nullptr);
- assert(*out == nullptr);
- double total = 0.0;
- unsigned int count = 0;
- auto max = DBL_MIN;
- auto 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];
- }
- }
-
- auto result = static_cast<tst_StatsResult *>(calloc(1, sizeof(tst_StatsResult)));
- EXPECT_TRUE(result != nullptr);
- if (count>0) {
- result->average = total / count;
- }
- result->min = min;
- result->max = max;
- auto buf = static_cast<double *>(calloc(input.len, sizeof(double)));
- EXPECT_TRUE(buf != nullptr);
- 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;
- }
-}
-
-TEST_F(JsonAvprRpcTests, output) {
- dyn_interface_type * intf = dynInterface_parseAvprWithStr(sourceAvprFile);
- ASSERT_TRUE(intf != nullptr);
-
- char *result = nullptr;
- tst_serv serv {nullptr, nullptr, nullptr, nullptr, xstats};
-
- int rc = jsonRpc_call(intf, &serv, R"({"m":"stats", "a": [[1.0, 2.0]]})", &result);
- ASSERT_EQ(0, rc);
- ASSERT_TRUE(strstr(result, "1.5") != nullptr);
-
- free(result);
- dynInterface_destroy(intf);
-}
-
-// Test char array as output
-extern "C" {
- struct tst_service_ex_output_char {
- void *handle;
- int (*getName_x)(void *, char ** result);
- };
-
- int getName_ex(void*, char** result) {
- *result = strdup("allocatedInFunction");
- return 0;
- }
-}
-
-TEST_F(JsonAvprRpcTests, output_char) {
- dyn_interface_type * intf = dynInterface_parseAvprWithStr(sourceAvprFile);
- ASSERT_TRUE(intf != nullptr);
-
- char *result = nullptr;
- tst_service_ex_output_char serv {nullptr, getName_ex};
-
- int rc = jsonRpc_call(intf, &serv, R"({"m" : "getName", "a": []})", &result);
- ASSERT_EQ(0, rc);
-
- ASSERT_TRUE(strstr(result, "allocatedInFunction") != nullptr);
-
- free(result);
- dynInterface_destroy(intf);
-}
-
diff --git a/libs/dfi/gtest/src/json_serializer_tests.cpp b/libs/dfi/gtest/src/json_serializer_tests.cpp
index ccfcedf9..6aeb5ec3 100644
--- a/libs/dfi/gtest/src/json_serializer_tests.cpp
+++ b/libs/dfi/gtest/src/json_serializer_tests.cpp
@@ -48,60 +48,6 @@ static void stdLog(void*, int level, const char *file, int line, const char *msg
/** struct type ******************************/
const char *example1_descriptor = "{DJISF a b c d e}";
-static const char *avpr_example1_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"size\" : 8, \
- \"alias\" : \"double\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Slong\", \
- \"size\" : 8, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Short\", \
- \"size\" : 2, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Float\", \
- \"size\" : 4, \
- \"alias\" : \"float\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structA\", \
- \"fields\" : [{\
- \"name\" : \"a\", \
- \"type\" : \"Double\" \
- }, {\
- \"name\" : \"b\", \
- \"type\" : \"Slong\" \
- }, {\
- \"name\" : \"c\", \
- \"type\" : \"Sint\" \
- }, {\
- \"name\" : \"d\", \
- \"type\" : \"Short\" \
- }, {\
- \"name\" : \"e\", \
- \"type\" : \"Float\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example1_fqn = "test.ns.structA";
-
const char *example1_input = "{ \
\"a\" : 1.0, \
\"b\" : 22, \
@@ -130,58 +76,6 @@ static void check_example1(void *data) {
/*********** example 2 ************************/
const char *example2_descriptor = "{BJJDFD byte long1 long2 double1 float1 double2}";
-static const char *avpr_example2_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Byte\", \
- \"size\" : 1, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Slong\", \
- \"size\" : 8, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"size\" : 8, \
- \"alias\" : \"double\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Float\", \
- \"size\" : 4, \
- \"alias\" : \"float\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structB\", \
- \"fields\" : [{\
- \"name\" : \"byte\", \
- \"type\" : \"Byte\" \
- }, {\
- \"name\" : \"long1\", \
- \"type\" : \"Slong\" \
- }, {\
- \"name\" : \"long2\", \
- \"type\" : \"Slong\" \
- }, {\
- \"name\" : \"double1\", \
- \"type\" : \"Double\" \
- }, {\
- \"name\" : \"float1\", \
- \"type\" : \"Float\" \
- }, {\
- \"name\" : \"double2\", \
- \"type\" : \"Double\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example2_fqn = "test.ns.structB";
-
const char *example2_input = "{ \
\"byte\" : 42, \
\"long1\" : 232, \
@@ -215,32 +109,6 @@ static void check_example2(void *data) {
/** sequence with a simple type **************/
const char *example3_descriptor = "{[I numbers}";
-static const char *avpr_example3_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structC\", \
- \"fields\" : [{\
- \"name\" : \"numbers\", \
- \"type\" : {\
- \"type\" : \"array\", \
- \"items\" : \"Sint\", \
- \"static\" : 3 \
- }\
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example3_fqn = "test.ns.structC";
-
const char *example3_input = "{ \
\"numbers\" : [22,32,42] \
}";
@@ -265,50 +133,6 @@ static void check_example3(void *data) {
/** structs within a struct (by reference)*******/
const char *example4_descriptor = "{{IDD index val1 val2}{IDD index val1 val2} left right}";
-static const char *avpr_example4_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Int32\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"size\" : 8, \
- \"alias\" : \"double\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"leaf\", \
- \"namespace\" : \"details\", \
- \"fields\" : [{\
- \"name\" : \"index\", \
- \"type\" : \"test.ns.Int32\" \
- }, {\
- \"name\" : \"val1\", \
- \"type\" : \"test.ns.Double\" \
- }, {\
- \"name\" : \"val2\", \
- \"type\" : \"test.ns.Double\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structD\", \
- \"fields\" : [{\
- \"name\" : \"left\", \
- \"type\" : \"details.leaf\" \
- }, {\
- \"name\" : \"right\", \
- \"type\" : \"details.leaf\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example4_fqn = "test.ns.structD";
-
static const char *example4_input = "{ \
\"left\" : {\"index\":1, \"val1\":1.0, \"val2\":2.0 }, \
\"right\" : {\"index\":2, \"val1\":5.0, \"val2\":4.0 } \
@@ -340,60 +164,6 @@ static void check_example4(void *data) {
/** 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 *avpr_example5_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Char\", \
- \"size\" : 2 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Str\", \
- \"size\" : 8, \
- \"alias\" : \"string\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"leaf\", \
- \"namespace\" : \"details\", \
- \"fields\" : [{\
- \"name\" : \"name\", \
- \"type\" : \"test.ns.Str\" \
- }, {\
- \"name\" : \"age\", \
- \"type\" : \"test.ns.Char\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"node\", \
- \"fields\" : [{\
- \"name\" : \"left\", \
- \"type\" : \"node\", \
- \"ptr\" : true \
- }, {\
- \"name\" : \"right\", \
- \"type\" : \"node\", \
- \"ptr\" : true \
- }, {\
- \"name\" : \"value\", \
- \"type\" : \"details.leaf\", \
- \"ptr\" : true \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structE\", \
- \"fields\" : [{\
- \"name\" : \"head\", \
- \"type\" : \"node\", \
- \"ptr\" : true \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example5_fqn = "test.ns.structE";
-
static const char *example5_input = "{ \
\"head\" : {\
\"left\" : {\
@@ -457,44 +227,7 @@ static void check_example5(void *data) {
/*********** example 6 ************************/
static const char *example6_descriptor = "Tsample={DD v1 v2};[lsample;";
-static const char *avpr_example6_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"alias\" : \"double\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"sample\", \
- \"fields\" : [{\
- \"name\" : \"v1\", \
- \"type\" : \"Double\" \
- }, {\
- \"name\" : \"v2\", \
- \"type\" : \"Double\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structF\", \
- \"fields\" : [{\
- \"name\" : \"samples\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"sample\"\
- }\
- }]\
- }], \
- \"messages\" : {} \
- }";
-static const char *avpr_example6_fqn = "test.ns.structF";
-
static const char *example6_input = R"([{"v1":0.1,"v2":0.2},{"v1":1.1,"v2":1.2},{"v1":2.1,"v2":2.2}])";
-static const char *avpr_example6_input = R"({
- "samples" : [{"v1":0.1,"v2":0.2},{"v1":1.1,"v2":1.2},{"v1":2.1,"v2":2.2}]
-})";
struct ex6_sample {
double v1;
@@ -507,10 +240,6 @@ struct ex6_sequence {
struct ex6_sample *buf;
};
-struct ex6_avpr_struct {
- struct ex6_sequence samples;
-};
-
static void check_example6(struct ex6_sequence seq) {
ASSERT_EQ(3, seq.cap);
ASSERT_EQ(3, seq.len);
@@ -522,44 +251,9 @@ static void check_example6(struct ex6_sequence seq) {
ASSERT_EQ(2.2, seq.buf[2].v2);
}
-static void check_example6_avpr(void *data) {
- auto ex = static_cast<ex6_avpr_struct*>(data);
- ASSERT_EQ(3, ex->samples.cap);
- ASSERT_EQ(3, ex->samples.len);
- ASSERT_EQ(0.1, ex->samples.buf[0].v1);
- ASSERT_EQ(0.2, ex->samples.buf[0].v2);
- ASSERT_EQ(1.1, ex->samples.buf[1].v1);
- ASSERT_EQ(1.2, ex->samples.buf[1].v2);
- ASSERT_EQ(2.1, ex->samples.buf[2].v1);
- ASSERT_EQ(2.2, ex->samples.buf[2].v2);
-}
-
/*********** example 7 ************************/
const char *example7_descriptor = "{t a}";
-static const char *avpr_example7_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Str\", \
- \"size\" : 8, \
- \"alias\" : \"string\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structG\", \
- \"fields\" : [{\
- \"name\" : \"a\", \
- \"type\" : \"Str\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-
-static const char *avpr_example7_fqn = "test.ns.structG";
-
const char *example7_input = "{ \
\"a\" : \"apache celix\" \
}";
@@ -578,66 +272,6 @@ static void check_example7(void *data) {
const char *example8_descriptor = "{ZbijNP a b c d e f}";
-static const char *avpr_example8_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Bool\", \
- \"alias\" : \"boolean\", \
- \"size\" : 1 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"UChar\", \
- \"size\" : 1 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Uint\", \
- \"size\" : 4 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Ulong\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"VoidPtr\", \
- \"size\" : 1, \
- \"alias\" : \"void_ptr\" \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structH\", \
- \"fields\" : [{\
- \"name\" : \"a\", \
- \"type\" : \"Bool\" \
- }, {\
- \"name\" : \"b\", \
- \"type\" : \"UChar\" \
- }, {\
- \"name\" : \"c\", \
- \"type\" : \"Uint\" \
- }, {\
- \"name\" : \"d\", \
- \"type\" : \"Ulong\" \
- }, {\
- \"name\" : \"e\", \
- \"type\" : \"Sint\" \
- }, {\
- \"name\" : \"f\", \
- \"type\" : \"VoidPtr\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-
-static const char *avpr_example8_fqn = "test.ns.structH";
-
const char *example8_input = "{ \
\"a\" : true, \
\"b\" : 4, \
@@ -668,44 +302,6 @@ static void check_example8(void *data) {
/*********** example 9 ************************/
const char *example9_descriptor = "{It#OK=0;#NOK=1;#MAYBE=2;E id name result}";
-static const char *avpr_example9_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"2.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"String\", \
- \"alias\" : \"string\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"enum\", \
- \"name\" : \"ResultEnum\", \
- \"EnumValues\" : [ \"OK = 0\", \"NOK= 1\", \"MAYBE =2\" ],\
- \"symbols\" : [\"OK\", \"NOK\", \"MAYBE\" ]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structI\", \
- \"fields\" : [{\
- \"name\" : \"id\", \
- \"type\" : \"Sint\" \
- }, {\
- \"name\" : \"name\", \
- \"type\" : \"String\" \
- }, {\
- \"name\" : \"result\", \
- \"type\" : \"ResultEnum\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-static const char *avpr_example9_fqn = "test.ns.structI";
-
const char *example9_input_1 = "{\
\"id\" : 1000, \
\"name\" : \"my_name\", \
@@ -751,12 +347,6 @@ static void check_example9_2(void *data) {
ASSERT_EQ(RE_MAYBE, ex->result);
}
-static void check_example9_3(void *data) {
- auto ex = static_cast<example9*>(data);
- ASSERT_EQ(1001, ex->id);
- ASSERT_STREQ("your_name", ex->name);
- ASSERT_EQ(RE_OK, ex->result);
-}
/*********** example A ************************/
const char *exampleA_descriptor = "TPoint={DD x y};{lPoint;lPoint;t point_a point_b name}";
@@ -788,102 +378,6 @@ static void check_exampleA(void *data) {
}
-static void parseAvprTests() {
- dyn_type *type;
- void *inst;
- int rc;
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example1_descriptor, avpr_example1_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example1_input, strlen(example1_input), &inst);
- ASSERT_EQ(0, rc);
- check_example1(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example2_descriptor, avpr_example2_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example2_input, strlen(example2_input), &inst);
- ASSERT_EQ(0, rc);
- check_example2(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example3_descriptor, avpr_example3_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example3_input, strlen(example3_input), &inst);
- ASSERT_EQ(0, rc);
- check_example3(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example4_descriptor, avpr_example4_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example4_input, strlen(example4_input), &inst);
- ASSERT_EQ(0, rc);
- check_example4(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example5_descriptor, avpr_example5_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example5_input, strlen(example5_input), &inst);
- ASSERT_EQ(0, rc);
- check_example5(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- // Test 6 has custom checker because avdl does not allow an array to be a type on its own
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example6_descriptor, avpr_example6_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, avpr_example6_input, strlen(avpr_example6_input), &inst);
- ASSERT_EQ(0, rc);
- check_example6_avpr(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example7_descriptor, avpr_example7_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example7_input, strlen(example7_input), &inst);
- ASSERT_EQ(0, rc);
- check_example7(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example8_descriptor, avpr_example8_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example8_input, strlen(example8_input), &inst);
- ASSERT_EQ(0, rc);
- check_example8(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- inst = nullptr;
- type = dynType_parseAvprWithStr(avpr_example9_descriptor, avpr_example9_fqn);
- ASSERT_TRUE(type != nullptr);
- rc = jsonSerializer_deserialize(type, example9_input_1, strlen(example9_input_1), &inst);
- ASSERT_EQ(0, rc);
- check_example9_1(inst);
- dynType_free(type, inst);
- rc = jsonSerializer_deserialize(type, example9_input_2, strlen(example9_input_2), &inst);
- ASSERT_EQ(0, rc);
- check_example9_2(inst);
- dynType_free(type, inst);
- rc = jsonSerializer_deserialize(type, example9_input_3, strlen(example9_input_3), &inst);
- ASSERT_EQ(0, rc);
- check_example9_3(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-}
-
static void parseTests() {
dyn_type *type;
void *inst;
@@ -1080,112 +574,6 @@ static void parseTests() {
/*********** write example 1 ************************/
const char *write_example1_descriptor = "{BSIJsijFDNZb a b c d e f g h i j k l}";
-const char *avpr_write_example1_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"SChar\", \
- \"signed\" : true, \
- \"size\" : 1 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Short\", \
- \"size\" : 2, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Sint\", \
- \"size\" : 4, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Slong\", \
- \"size\" : 8, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"UShort\", \
- \"size\" : 2 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Uint\", \
- \"size\" : 4 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Ulong\", \
- \"size\" : 8 \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Float\", \
- \"size\" : 4, \
- \"alias\" : \"float\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Double\", \
- \"size\" : 8, \
- \"alias\" : \"double\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"NativeInt\", \
- \"size\" : 4, \
- \"alias\" : \"native_int\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Bool\", \
- \"size\" : 1, \
- \"alias\" : \"boolean\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"UChar\", \
- \"size\" : 1 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structAW\", \
- \"fields\" : [{\
- \"name\" : \"a\", \
- \"type\" : \"SChar\" \
- }, {\
- \"name\" : \"b\", \
- \"type\" : \"Short\" \
- }, {\
- \"name\" : \"c\", \
- \"type\" : \"Sint\" \
- }, {\
- \"name\" : \"d\", \
- \"type\" : \"Slong\" \
- }, {\
- \"name\" : \"e\", \
- \"type\" : \"UShort\" \
- }, {\
- \"name\" : \"f\", \
- \"type\" : \"Uint\" \
- }, {\
- \"name\" : \"g\", \
- \"type\" : \"Ulong\" \
- }, {\
- \"name\" : \"h\", \
- \"type\" : \"Float\" \
- }, {\
- \"name\" : \"i\", \
- \"type\" : \"Double\" \
- }, {\
- \"name\" : \"j\", \
- \"type\" : \"NativeInt\" \
- }, {\
- \"name\" : \"k\", \
- \"type\" : \"Bool\" \
- }, {\
- \"name\" : \"l\", \
- \"type\" : \"UChar\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-const char *avpr_write_example1_fqn = "test.ns.structAW";
-
struct write_example1 {
char a;
int16_t b;
@@ -1227,87 +615,9 @@ void writeTest1(void) {
free(result);
}
-void writeAvprTest1(void) {
- write_example1 ex1 {1,2,3,4,5,6,7,8.8f,9.9,10,true,12};
-
- char *result = nullptr;
- dyn_type *type = dynType_parseAvprWithStr(avpr_write_example1_descriptor, avpr_write_example1_fqn);
- ASSERT_TRUE(type != nullptr);
-
- int rc = jsonSerializer_serialize(type, &ex1, &result);
- ASSERT_EQ(0, rc);
-
- ASSERT_TRUE(strstr(result, R"("a":1)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("b":2)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("c":3)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("d":4)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("e":5)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("f":6)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("g":7)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("h":8.8)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("i":9.9)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("j":10)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("k":true)") != nullptr);
- ASSERT_TRUE(strstr(result, R"("l":12)") != nullptr);
-
- dynType_destroy(type);
- free(result);
-}
-
/*********** write example 2 ************************/
const char *write_example2_descriptor = "{*{JJ a b}{SS c d} sub1 sub2}";
-const char *avpr_write_example2_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Short\", \
- \"size\" : 2, \
- \"signed\" : true \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Slong\", \
- \"size\" : 8, \
- \"signed\" : true \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"SubPtr\", \
- \"fields\" : [{\
- \"name\" : \"a\", \
- \"type\" : \"Slong\" \
- }, {\
- \"name\" : \"b\", \
- \"type\" : \"Slong\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"Sub\", \
- \"fields\" : [{\
- \"name\" : \"c\", \
- \"type\" : \"Short\" \
- }, {\
- \"name\" : \"d\", \
- \"type\" : \"Short\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structBW\", \
- \"fields\" : [{\
- \"name\" : \"sub1\", \
- \"ptr\" : true, \
- \"type\" : \"SubPtr\" \
- }, {\
- \"name\" : \"sub2\", \
- \"type\" : \"Sub\" \
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-const char *avpr_write_example2_fqn = "test.ns.structBW";
-
struct write_example2_sub {
int64_t a;
int64_t b;
@@ -1340,78 +650,9 @@ void writeTest2(void) {
free(result);
}
-void writeAvprTest2(void) {
- write_example2_sub sub1 {0,0};
- write_example2 ex {&sub1, {3, 4}};
- ex.sub1->a = 1;
- ex.sub1->b = 2;
-
- char *result = nullptr;
- dyn_type *type = dynType_parseAvprWithStr(avpr_write_example2_descriptor, avpr_write_example2_fqn);
- ASSERT_TRUE(type != nullptr);
-
- int rc = jsonSerializer_serialize(type, &ex, &result);
- ASSERT_EQ(0, rc);
-
- ASSERT_TRUE(strstr(result, "\"a\":1") != nullptr);
- ASSERT_TRUE(strstr(result, "\"b\":2") != nullptr);
- ASSERT_TRUE(strstr(result, "\"c\":3") != nullptr);
- ASSERT_TRUE(strstr(result, "\"d\":4") != nullptr);
-
- dynType_destroy(type);
- free(result);
-}
-
/*********** write example 3 ************************/
const char *write_example3_descriptor = "Tperson={ti name age};[Lperson;";
-const char *avpr_write_example3_descriptor = "{\
- \"protocol\" : \"types\", \
- \"namespace\" : \"test.ns\", \
- \"version\" : \"1.0.0\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"Str\", \
- \"size\" : 8, \
- \"alias\" : \"string\" \
- }, { \
- \"type\" : \"fixed\", \
- \"name\" : \"Uint\", \
- \"size\" : 4 \
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"PersonPtr\", \
- \"fields\" : [{\
- \"name\" : \"p\", \
- \"type\" : \"Person\", \
- \"ptr\" : true \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"Person\", \
- \"fields\" : [{\
- \"name\" : \"name\", \
- \"type\" : \"Str\" \
- }, {\
- \"name\" : \"age\", \
- \"type\" : \"Uint\" \
- }]\
- }, { \
- \"type\" : \"record\", \
- \"name\" : \"structCW\", \
- \"fields\" : [{\
- \"name\" : \"persons\", \
- \"type\" : { \
- \"type\" : \"array\",\
- \"items\" : \"PersonPtr\"\
- }\
- }]\
- }], \
- \"messages\" : {} \
- }";
-
-const char *avpr_write_example3_fqn = "test.ns.structCW";
-
struct write_example3_person {
const char *name;
uint32_t age;
@@ -1451,35 +692,6 @@ void writeTest3(void) {
free(result);
}
-void writeAvprTest3(void) {
- write_example3_person p1 {"John", 33};
- write_example3_person p2 {"Peter", 44};
- write_example3_person p3 {"Carol", 55};
- write_example3_person p4 {"Elton", 66};
-
- write_example3 seq {4, 4, (write_example3_person **) calloc(4, sizeof(void *))};
- seq.buf[0] = &p1;
- seq.buf[1] = &p2;
- seq.buf[2] = &p3;
- seq.buf[3] = &p4;
-
- char *result = nullptr;
- dyn_type *type = dynType_parseAvprWithStr(avpr_write_example3_descriptor, avpr_write_example3_fqn);
- ASSERT_TRUE(type != nullptr);
-
- int rc = jsonSerializer_serialize(type, &seq, &result);
- ASSERT_EQ(0, rc);
-
- ASSERT_TRUE(strstr(result, "\"age\":33") != nullptr);
- ASSERT_TRUE(strstr(result, "\"age\":44") != nullptr);
- ASSERT_TRUE(strstr(result, "\"age\":55") != nullptr);
- ASSERT_TRUE(strstr(result, "\"age\":66") != nullptr);
-
- free(seq.buf);
- dynType_destroy(type);
- free(result);
-}
-
void writeEnum(void) {
dyn_type *type = nullptr;
char *result = nullptr;
@@ -1571,7 +783,6 @@ public:
int lvl = 1;
dynCommon_logSetup(stdLog, nullptr, lvl);
dynType_logSetup(stdLog, nullptr,lvl);
- dynAvprType_logSetup(stdLog, nullptr,lvl);
dynTypeCommon_logSetup(stdLog, nullptr,lvl);
jsonSerializer_logSetup(stdLog, nullptr, lvl);
}
@@ -1584,23 +795,16 @@ TEST_F(JsonSerializerTests, ParseTests) {
parseTests();
}
-TEST_F(JsonSerializerTests, ParseAvprTests) {
- parseAvprTests();
-}
-
TEST_F(JsonSerializerTests, WriteTest1) {
writeTest1();
- writeAvprTest1();
}
TEST_F(JsonSerializerTests, WriteTest2) {
writeTest2();
- writeAvprTest2();
}
TEST_F(JsonSerializerTests, WriteTest3) {
writeTest3();
- writeAvprTest3();
}
TEST_F(JsonSerializerTests, WriteEnum) {
diff --git a/libs/dfi/include/avrobin_serializer.h b/libs/dfi/include/avrobin_serializer.h
deleted file mode 100644
index aeafd751..00000000
--- a/libs/dfi/include/avrobin_serializer.h
+++ /dev/null
@@ -1,100 +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 __AVROBIN_SERIALIZER_H_
-#define __AVROBIN_SERIALIZER_H_
-
-#include "dfi_log_util.h"
-#include "dyn_type.h"
-#include "dyn_function.h"
-#include "dyn_interface.h"
-#include "celix_dfi_export.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//logging
-DFI_SETUP_LOG_HEADER(avrobinSerializer);
-
-/**
- * @brief Deserialize data in AVRO format.
- *
- * The caller is the owner of the deserialized data and use `dynType_free` deallocate the memory.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] type The dynamic type for the input data.
- * @param[in] input The input data in AVRO format.
- * @param[in] inlen The length of the input data.
- * @param[out] result The deserialized data.
- * @return 0 if successful, otherwise 1.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT int avrobinSerializer_deserialize(dyn_type *type, const uint8_t *input, size_t inlen, void **result);
-
-/**
- * @brief Serialize data to AVRO format.
- *
- * The caller is the owner of the serialized data and use `free` deallocate the memory.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] type The dynamic type for the input data.
- * @param[in] input The input data.
- * @param[out] output The serialized data in AVRO format.
- * @param[out] outlen The length of the serialized data.
- * @return 0 if successful, otherwise 1.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT int avrobinSerializer_serialize(dyn_type *type, const void *input, uint8_t **output, size_t *outlen);
-
-
-/**
- * @brief Generate a AVRO schema for a given Dynamic Type.
- *
- * The caller is the owner of the generated schema and use `free` deallocate the memory.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] type The dynamic type for which a schema should be generated.
- * @param[out] output The generated schema.
- * @return 0 if successful, otherwise 1.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT int avrobinSerializer_generateSchema(dyn_type *type, char **output);
-
-/**
- * @brief Save a serialized data to a file.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] filename The name of the file.
- * @param[in] schema The schema of the serialized data.
- * @param[in] serdata The serialized data.
- * @param[in] serdatalen The length of the serialized data.
- * @return 0 if successful, otherwise 1.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT int avrobinSerializer_saveFile(const char *filename, const char *schema, const uint8_t *serdata, size_t serdatalen);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/libs/dfi/include/dyn_function.h b/libs/dfi/include/dyn_function.h
index 65fa6734..e812eeaf 100644
--- a/libs/dfi/include/dyn_function.h
+++ b/libs/dfi/include/dyn_function.h
@@ -46,7 +46,6 @@ extern "C" {
typedef struct _dyn_function_type dyn_function_type;
DFI_SETUP_LOG_HEADER(dynFunction);
-DFI_SETUP_LOG_HEADER(dynAvprFunction);
enum dyn_function_argument_meta {
DYN_FUNCTION_ARGUMENT_META__STD = 0,
@@ -159,34 +158,6 @@ CELIX_DFI_EXPORT int dynFunction_getFnPointer(dyn_function_type *func, void (**f
*/
CELIX_DFI_EXPORT bool dynFunction_hasReturn(dyn_function_type *dynFunction);
-/**
- * @brief Creates a dyn_function_type according to the given avpr descriptor string.
- *
- * The caller is the owner of the dynFunc and the dynFunc should be freed using dynFunction_destroy.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avpr The string containing the avpr descriptor.
- * @param[in] fqn The fully qualified name of the function.
- * @return The dynamic type instance for function or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_function_type * dynFunction_parseAvprWithStr(const char * avpr, const char * fqn);
-
-/**
- * @brief Creates a dyn_function_type according to the given avpr descriptor stream.
- *
- * The caller is the owner of the dynFunc and the dynFunc should be freed using dynFunction_destroy.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avprStream The stream containing the avpr descriptor.
- * @param[in] fqn The fully qualified name of the function.
- * @return The dynamic type instance for function or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_function_type * dynFunction_parseAvpr(FILE * avprStream, const char * fqn);
-
#ifdef __cplusplus
}
#endif
diff --git a/libs/dfi/include/dyn_interface.h b/libs/dfi/include/dyn_interface.h
index c362b281..0f80bec2 100644
--- a/libs/dfi/include/dyn_interface.h
+++ b/libs/dfi/include/dyn_interface.h
@@ -33,7 +33,6 @@ extern "C" {
#endif
DFI_SETUP_LOG_HEADER(dynInterface);
-DFI_SETUP_LOG_HEADER(dynAvprInterface);
/* Description string
*
@@ -163,28 +162,6 @@ CELIX_DFI_EXPORT int dynInterface_methods(dyn_interface_type *intf, struct metho
CELIX_DFI_EXPORT int dynInterface_nrOfMethods(dyn_interface_type *intf);
-/**
- * @brief Creates a dynamic interface type instance according to the given avpr interface descriptor string.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avpr The avpr interface descriptor string.
- * @return The dynamic interface type instance or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_interface_type * dynInterface_parseAvprWithStr(const char * avpr);
-
-/**
- * @brief Creates a dynamic interface type instance according to the given avpr interface descriptor stream.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avprStream The avpr interface descriptor stream.
- * @return The dynamic interface type instance or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_interface_type * dynInterface_parseAvpr(FILE * avprStream);
-
#ifdef __cplusplus
}
#endif
diff --git a/libs/dfi/include/dyn_type.h b/libs/dfi/include/dyn_type.h
index 5bacaa4c..c8a963ea 100644
--- a/libs/dfi/include/dyn_type.h
+++ b/libs/dfi/include/dyn_type.h
@@ -137,7 +137,6 @@ struct meta_entry {
//logging
DFI_SETUP_LOG_HEADER(dynType);
-DFI_SETUP_LOG_HEADER(dynAvprType);
/**
* Parses a descriptor stream and creates a dyn_type (dynamic type).
@@ -374,31 +373,6 @@ CELIX_DFI_EXPORT int dynType_text_allocAndInit(dyn_type *type, void *textLoc, co
*/
CELIX_DFI_EXPORT void dynType_simple_setValue(dyn_type *type, void *inst, void *in);
-/**
- * @brief Creates a dyn type for a given avpr stream.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avprStream The avpr stream.
- * @param[in] fqn The fully qualified name of the type.
- * @return The dynamic type instance or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_type * dynType_parseAvpr(FILE *avprStream, const char *fqn);
-
-/**
- * @brief Creates a dyn type for a given avpr string.
- *
- * In case of an error, an error message is added to celix_err.
- *
- * @param[in] avpr The avpr string.
- * @param[in] fqn The fully qualified name of the type.
- * @return The dynamic type instance or NULL if the avpr could not be parsed.
- * @deprecated AVRO is deprecated and will be removed in the future.
- */
-CELIX_DFI_DEPRECATED_EXPORT dyn_type * dynType_parseAvprWithStr(const char *avpr, const char *fqn);
-
-
#ifdef __cplusplus
}
#endif
diff --git a/libs/dfi/src/avrobin_serializer.c b/libs/dfi/src/avrobin_serializer.c
deleted file mode 100644
index eeb47804..00000000
--- a/libs/dfi/src/avrobin_serializer.c
+++ /dev/null
@@ -1,1368 +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 "avrobin_serializer.h"
-#include "dyn_type_common.h"
-#include "celix_err.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <jansson.h>
-#include <inttypes.h>
-
-#define MAX_VARINT_BUF_SIZE 10
-
-static int generate_sync(uint8_t **result);
-static int generate_record_name(char **result);
-
-static int avrobin_read_boolean(FILE *stream,bool *val);
-static int avrobin_read_int(FILE *stream,int32_t *val);
-static int avrobin_read_long(FILE *stream,int64_t *val);
-static int avrobin_read_float(FILE *stream,float *val);
-static int avrobin_read_double(FILE *stream,double *val);
-static int avrobin_read_string(FILE *stream,char **val);
-
-static int avrobin_write_boolean(FILE *stream,bool val);
-static int avrobin_write_int(FILE *stream,int32_t val);
-static int avrobin_write_long(FILE *stream,int64_t val);
-static int avrobin_write_float(FILE *stream,float val);
-static int avrobin_write_double(FILE *stream,double val);
-static int avrobin_write_string(FILE *stream,const char *val);
-
-static int avrobin_schema_primitive(const char *tname, json_t **output);
-
-static int avrobinSerializer_createType(dyn_type *type, FILE *stream, void **result);
-static int avrobinSerializer_parseAny(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_parseComplex(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_parseSequence(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_parseEnum(dyn_type *type, void *loc, FILE *stream);
-
-static int avrobinSerializer_writeAny(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_writeComplex(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_writeSequence(dyn_type *type, void *loc, FILE *stream);
-static int avrobinSerializer_writeEnum(dyn_type *type, void *loc, FILE *stream);
-
-static int avrobinSerializer_generateAny(dyn_type *type, json_t **output);
-static int avrobinSerializer_generateComplex(dyn_type *type, json_t **output);
-static int avrobinSerializer_generateSequence(dyn_type *type, json_t **output);
-static int avrobinSerializer_generateEnum(dyn_type *type, json_t **output);
-
-static const int OK = 0;
-static const int ERROR = 1;
-
-static uint32_t record_name_counter;
-
-DFI_SETUP_LOG(avrobinSerializer);
-
-int avrobinSerializer_deserialize(dyn_type *type, const uint8_t *input, size_t inlen, void **result) {
- int status = OK;
-
- FILE *stream = fmemopen((void*)input, inlen, "rb");
-
- if (stream != NULL) {
- status = avrobinSerializer_createType(type, stream, result);
-
- fclose(stream);
-
- if (status != OK) {
- LOG_ERROR("Error cannot deserialize avrobin.");
- }
- } else {
- status = ERROR;
- LOG_ERROR("Error initializing memory stream for reading. Length was %zu.", inlen);
- }
-
- return status;
-}
-
-int avrobinSerializer_serialize(dyn_type *type, const void *input, uint8_t **output, size_t *outlen) {
- int status = OK;
-
- FILE *stream = open_memstream((char**)output, outlen);
-
- if (stream != NULL) {
- status = avrobinSerializer_writeAny(type, (void*)input, stream);
-
- fclose(stream);
-
- if (status != OK) {
- free(*output);
-
- LOG_ERROR("Error cannot serialize avrobin.");
- }
- } else {
- status = ERROR;
- LOG_ERROR("Error initializing memory stream for writing.");
- }
-
- return status;
-}
-
-int avrobinSerializer_generateSchema(dyn_type *type, char **output) {
- int status = OK;
-
- record_name_counter = 1;
-
- json_t *root = NULL;
- status = avrobinSerializer_generateAny(type, &root);
-
- if (status == OK) {
- *output = json_dumps(root, JSON_COMPACT | JSON_PRESERVE_ORDER);
-
- if (*output == NULL) {
- status = ERROR;
- }
-
- json_decref(root);
- }
-
- return status;
-}
-
-int avrobinSerializer_saveFile(const char *filename, const char *schema, const uint8_t *serdata, size_t serdatalen) {
- int status = OK;
-
- FILE *file = fopen(filename, "wb");
-
- if (file != NULL) {
- if (status == OK) {
- if (fputc('O', file) == EOF) {
- status = ERROR;
- }
- }
- if (status == OK) {
- if (fputc('b', file) == EOF) {
- status = ERROR;
- }
- }
- if (status == OK) {
- if (fputc('j', file) == EOF) {
- status = ERROR;
- }
- }
- if (status == OK) {
- if (fputc(1, file) == EOF) {
- status = ERROR;
- }
- }
- if (status == OK) {
- status = avrobin_write_long(file, 1);
- }
- if (status == OK) {
- status = avrobin_write_string(file, "avro.schema");
- }
- if (status == OK) {
- status = avrobin_write_string(file, schema);
- }
- if (status == OK) {
- status = avrobin_write_long(file, 0);
- }
- if (status == OK) {
- uint8_t *sync = NULL;
- status = generate_sync(&sync);
- if (status == OK) {
- for (int i=0; i<16; i++) {
- if (status == OK) {
- if (fputc(sync[i], file) == EOF) {
- status = ERROR;
- }
- }
- if (status != OK) break;
- }
- if (status == OK) {
- status = avrobin_write_long(file, 1);
- }
- if (status == OK) {
- status = avrobin_write_long(file, serdatalen);
- }
- if (status == OK) {
- for (int i=0; i<serdatalen; i++) {
- if (status == OK) {
- if (fputc(serdata[i], file) == EOF) {
- status = ERROR;
- }
- }
- if (status != OK) break;
- }
- }
- for (int i=0; i<16; i++) {
- if (status == OK) {
- if (fputc(sync[i], file) == EOF) {
- status = ERROR;
- }
- }
- if (status != OK) break;
- }
-
- free(sync);
- }
- }
-
- fclose(file);
- } else {
- status = ERROR;
- }
-
- return status;
-}
-
-static int avrobinSerializer_createType(dyn_type *type, FILE *stream, void **result) {
- int status = OK;
- void *inst = NULL;
-
- status = dynType_alloc(type, &inst);
-
- if (status == OK) {
- assert(inst != NULL);
- status = avrobinSerializer_parseAny(type, inst, stream);
-
- if (status == OK) {
- *result = inst;
- }
- else {
- dynType_free(type, inst);
- }
- }
-
- return status;
-}
-
-static int avrobinSerializer_parseAny(dyn_type *type, void *loc, FILE *stream) {
- int status = OK;
-
- dyn_type *subType = NULL;
- char c = dynType_descriptorType(type);
-
- bool *z; //Z
- float *f; //F
- double *d; //D
- char *b; //B
- int *n; //N
- int16_t *s; //S
- int32_t *i; //I
- int64_t *l; //J
- uint8_t *ub; //b
- uint16_t *us; //s
- uint32_t *ui; //i
- uint64_t *ul; //j
-
- bool avro_boolean;
- int32_t avro_int;
- int64_t avro_long;
- float avro_float;
- double avro_double;
- char *avro_string;
-
- switch (c) {
- case 'Z' :
- z = loc;
- status = avrobin_read_boolean(stream,&avro_boolean);
- if (status == OK) {
- *z = avro_boolean;
- }
- break;
- case 'F' :
- f = loc;
- status = avrobin_read_float(stream,&avro_float);
- if (status == OK) {
- *f = avro_float;
- }
- break;
- case 'D' :
- d = loc;
- status = avrobin_read_double(stream,&avro_double);
- if (status == OK) {
- *d = avro_double;
- }
- break;
- case 'N' :
- n = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *n = (int)avro_int;
- }
- break;
- case 'B' :
- b = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *b = (char)avro_int;
- }
- break;
- case 'S' :
- s = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *s = (int16_t)avro_int;
- }
- break;
- case 'I' :
- i = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *i = avro_int;
- }
- break;
- case 'J' :
- l = loc;
- status = avrobin_read_long(stream,&avro_long);
- if (status == OK) {
- *l = avro_long;
- }
- break;
- case 'b' :
- ub = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *ub = (uint8_t)avro_int;
- }
- break;
- case 's' :
- us = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *us = (uint16_t)avro_int;
- }
- break;
- case 'i' :
- ui = loc;
- status = avrobin_read_int(stream,&avro_int);
- if (status == OK) {
- *ui = (uint32_t)avro_int;
- }
- break;
- case 'j' :
- ul = loc;
- status = avrobin_read_long(stream,&avro_long);
- if (status == OK) {
- *ul = (uint64_t)avro_long;
- }
- break;
- case 't' :
- status = avrobin_read_string(stream,&avro_string);
- if (status == OK) {
- status = dynType_text_allocAndInit(type, loc, avro_string);
- free(avro_string);
- }
- break;
- case '[' :
- if (status == OK) {
- status = avrobinSerializer_parseSequence(type, loc, stream);
- }
- break;
- case '{' :
- if (status == OK) {
- status = avrobinSerializer_parseComplex(type, loc, stream);
- }
- break;
- case '*' :
- status = dynType_typedPointer_getTypedType(type, &subType);
- if (status == OK) {
- status = avrobinSerializer_createType(subType, stream, (void**)loc);
- }
- break;
- case 'E' :
- if (status == OK) {
- status = avrobinSerializer_parseEnum(type, loc, stream);
- }
- break;
- case 'l':
- status = avrobinSerializer_parseAny(type->ref.ref, loc, stream);
- break;
- case 'P' :
- status = ERROR;
- LOG_ERROR("Untyped pointers are not supported for serialization.");
- break;
- default :
- status = ERROR;
- LOG_ERROR("Error provided type '%c' not supported for AVRO.", dynType_descriptorType(type));
- break;
- }
-
- return status;
-}
-
-static int avrobinSerializer_parseComplex(dyn_type *type, void *loc, FILE *stream) {
- int status = OK;
-
- struct complex_type_entry *entry = NULL;
- struct complex_type_entries_head *entries = NULL;
- dyn_type *subType = NULL;
- void *subLoc = NULL;
- int index = -1;
-
- status = dynType_complex_entries(type, &entries);
-
- if (status == OK) {
- TAILQ_FOREACH(entry, entries, entries) {
- index = dynType_complex_indexForName(type, entry->name);
-
- if (index < 0) {
- status = ERROR;
- LOG_ERROR("Cannot find index for member '%s'.", entry->name);
- }
-
- if (status == OK) {
- status = dynType_complex_dynTypeAt(type, index, &subType);
- }
-
- if (status == OK) {
- status = dynType_complex_valLocAt(type, index, loc, &subLoc);
- }
-
- if (status == OK) {
- status = avrobinSerializer_parseAny(subType, subLoc, stream);
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- return status;
-}
-
-static int avrobinSerializer_parseSequence(dyn_type *type, void *loc, FILE *stream) {
- /* Avro 1.8.1 Specification
- * Arrays
- * Arrays are encoded as a series of blocks. Each block consists of a long count value, followed by that many array items. A block with count zero indicates the end of the array. Each item is encoded per the array's item schema.
- * If a block's count is negative, its absolute value is used, and the count is followed immediately by a long block size indicating the number of bytes in the block. This block size permits fast skipping through data, e.g., when projecting a record to a subset of its fields.
- * For example, the array schema
- * {"type": "array", "items": "long"}
- * an array containing the items 3 and 27 could be encoded as the long value 2 (encoded as hex 04) followed by long values 3 and 27 (encoded as hex 06 36) terminated by zero:
- * 04 06 36 00
- * The blocked representation permits one to read and write arrays larger than can be buffered in memory, since one can start writing items without knowing the full length of the array.
- */
-
- dynType_sequence_init(type, loc);
- int status = 0;
- dyn_type *itemType = dynType_sequence_itemType(type);
- size_t itemSize = (int64_t)dynType_size(itemType);
- uint32_t cap = 0;
-
- int64_t blockCount = 0;
- int64_t blockSize = 0;
-
- do {
- status = avrobin_read_long(stream, &blockCount);
- if (status != OK) {
- break;
- } else if (blockCount < 0) {
- blockSize = blockCount * -1; //found a block of blockSize bytes
- blockCount = blockSize / itemSize;
- int64_t rest = blockSize % itemSize;
- if (rest != 0) {
- LOG_ERROR("Found block size (%"PRId64") is not a multitude of the item size (%zu)", blockSize, itemSize);
- status = ERROR;
- break;
- }
- }
- if (blockCount > 0) {
- cap += blockCount;
- dynType_sequence_reserve(type, loc, cap);
- for (int64_t i = 0; i < blockCount; ++i) {
- void* itemLoc = NULL;
- status = dynType_sequence_increaseLengthAndReturnLastLoc(type, loc, &itemLoc);
- if (status != OK) {
- break;
- }
- avrobinSerializer_parseAny(itemType, itemLoc, stream);
- }
- if (status != OK) {
- break;
- }
- }
- } while (blockCount != 0);
-
- if (status != OK) {
- dynType_free(type, loc);
- }
- return status;
-}
-
-static int avrobinSerializer_parseEnum(dyn_type *type, void *loc, FILE *stream) {
- int32_t index;
- if (avrobin_read_int(stream, &index) != OK) {
- return ERROR;
- }
- if (index < 0) {
- return ERROR;
- }
-
- struct meta_entry *entry = NULL;
- int32_t curr_index = 0;
-
- TAILQ_FOREACH(entry, &type->metaProperties, entries) {
- if (curr_index == index) {
- *(int32_t*)loc = atoi(entry->value);
- return OK;
- }
- curr_index++;
- }
-
- return ERROR;
-}
-
-static int avrobinSerializer_writeAny(dyn_type *type, void *loc, FILE *stream) {
- int status = OK;
-
- int descriptor = dynType_descriptorType(type);
- dyn_type *subType = NULL;
-
- bool *z; //Z
- float *f; //F
- double *d; //D
- char *b; //B
- int *n; //N
- int16_t *s; //S
- int32_t *i; //I
- int64_t *l; //J
- uint8_t *ub; //b
- uint16_t *us; //s
- uint32_t *ui; //i
- uint64_t *ul; //j
-
- switch (descriptor) {
- case 'Z' :
- z = loc;
- status = avrobin_write_boolean(stream,*z);
- break;
- case 'B' :
- b = loc;
- status = avrobin_write_int(stream,(int32_t)*b);
- break;
- case 'S' :
- s = loc;
- status = avrobin_write_int(stream,(int32_t)*s);
- break;
- case 'I' :
- i = loc;
- status = avrobin_write_int(stream,*i);
- break;
- case 'J' :
- l = loc;
- status = avrobin_write_long(stream,*l);
- break;
- case 'b' :
- ub = loc;
- status = avrobin_write_int(stream,(int32_t)*ub);
- break;
- case 's' :
- us = loc;
- status = avrobin_write_int(stream,(int32_t)*us);
- break;
- case 'i' :
- ui = loc;
- status = avrobin_write_int(stream,(int32_t)*ui);
- break;
- case 'j' :
- ul = loc;
- status = avrobin_write_long(stream,(int64_t)*ul);
- break;
- case 'N' :
- n = loc;
- status = avrobin_write_int(stream,(int32_t)*n);
- break;
- case 'F' :
- f = loc;
- status = avrobin_write_float(stream,*f);
- break;
- case 'D' :
- d = loc;
- status = avrobin_write_double(stream,*d);
- break;
- case 't' :
- status = avrobin_write_string(stream,*(const char**)loc);
- break;
- case '*' :
- status = dynType_typedPointer_getTypedType(type, &subType);
- if (status == OK) {
- status = avrobinSerializer_writeAny(subType, *(void**)loc, stream);
- }
- break;
- case '{' :
- status = avrobinSerializer_writeComplex(type, loc, stream);
- break;
- case '[' :
- status = avrobinSerializer_writeSequence(type, loc, stream);
- break;
- case 'E' :
- status = avrobinSerializer_writeEnum(type, loc, stream);
- break;
- case 'l':
- status = avrobinSerializer_writeAny(type->ref.ref, loc, stream);
- break;
- case 'P' :
- status = ERROR;
- LOG_ERROR("Untyped pointers are not supported for serialization.");
- break;
- default :
- status = ERROR;
- LOG_ERROR("Unsupported descriptor '%c'.", descriptor);
- break;
- }
-
- return status;
-}
-
-static int avrobinSerializer_writeComplex(dyn_type *type, void *loc, FILE *stream) {
- int status = OK;
-
- struct complex_type_entry *entry = NULL;
- struct complex_type_entries_head *entries = NULL;
- dyn_type *subType = NULL;
- void *subLoc = NULL;
- int index = -1;
-
- status = dynType_complex_entries(type, &entries);
-
- if (status == OK) {
- TAILQ_FOREACH(entry, entries, entries) {
- index = dynType_complex_indexForName(type, entry->name);
-
- if (index < 0) {
- status = ERROR;
- LOG_ERROR("Cannot find index for member '%s'.", entry->name);
- }
-
- if (status == OK) {
- status = dynType_complex_dynTypeAt(type, index, &subType);
- }
-
- if (status == OK) {
- status = dynType_complex_valLocAt(type, index, loc, &subLoc);
- }
-
- if (status == OK) {
- status = avrobinSerializer_writeAny(subType, subLoc, stream);
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- return status;
-}
-
-static int avrobinSerializer_writeSequence(dyn_type *type, void *loc, FILE *stream) {
- uint32_t arrayLen = dynType_sequence_length(loc);
-
- dyn_type *itemType = dynType_sequence_itemType(type);
- void *itemLoc = NULL;
-
- if (avrobin_write_long(stream, arrayLen) != OK) {
- LOG_ERROR("Failed to write array block count.");
- return ERROR;
- }
-
- for (int i=0; i<arrayLen; i++) {
- if (dynType_sequence_locForIndex(type, loc, i, &itemLoc)) {
- return ERROR;
- }
- if (avrobinSerializer_writeAny(itemType, itemLoc, stream) != OK) {
- return ERROR;
- }
- }
-
- if (avrobin_write_long(stream, 0) != OK) {
- LOG_ERROR("Failed to write array block count.");
- return ERROR;
- }
-
- return OK;
-}
-
-static int avrobinSerializer_writeEnum(dyn_type *type, void *loc, FILE *stream) {
- char enum_value_str[16];
- int rc = snprintf(enum_value_str, sizeof(enum_value_str), "%d", *(int32_t*)loc);
- if (rc >= sizeof(enum_value_str) || rc < 0) {
- return ERROR;
- }
-
- struct meta_entry *entry = NULL;
- int32_t index = 0;
-
- TAILQ_FOREACH(entry, &type->metaProperties, entries) {
- if (0 == strcmp(enum_value_str, entry->value)) {
- return avrobin_write_int(stream, index);
- }
- index++;
- }
-
- LOG_ERROR("Could not find Enum value %s in enum type.", enum_value_str);
- return ERROR;
-}
-
-static int avrobinSerializer_generateAny(dyn_type *type, json_t **output) {
- int status = OK;
-
- int descriptor = dynType_descriptorType(type);
- dyn_type *subType = NULL;
- json_t *schema = NULL;
-
- switch (descriptor) {
- case 'Z' :
- status = avrobin_schema_primitive("boolean", &schema);
- break;
- case 'B' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'S' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'I' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'J' :
- status = avrobin_schema_primitive("long", &schema);
- break;
- case 'b' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 's' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'i' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'j' :
- status = avrobin_schema_primitive("long", &schema);
- break;
- case 'N' :
- status = avrobin_schema_primitive("int", &schema);
- break;
- case 'F' :
- status = avrobin_schema_primitive("float", &schema);
- break;
- case 'D' :
- status = avrobin_schema_primitive("double", &schema);
- break;
- case 't' :
- status = avrobin_schema_primitive("string", &schema);
- break;
- case '*' :
- status = dynType_typedPointer_getTypedType(type, &subType);
- if (status == OK) {
- status = avrobinSerializer_generateAny(subType, &schema);
- }
- break;
- case '{' :
- status = avrobinSerializer_generateComplex(type, &schema);
- break;
- case '[' :
- status = avrobinSerializer_generateSequence(type, &schema);
- break;
- case 'E' :
- status = avrobinSerializer_generateEnum(type, &schema);
- break;
- case 'P' :
- status = ERROR;
- LOG_ERROR("Untyped pointers are not supported for serialization.");
- break;
- default :
- status = ERROR;
- LOG_ERROR("Unsupported descriptor '%c'.", descriptor);
- break;
- }
-
- if (status == OK && schema != NULL) {
- *output = schema;
- }
-
- return status;
-}
-
-static int avrobinSerializer_generateComplex(dyn_type *type, json_t **output) {
- int status = OK;
-
- struct complex_type_entry *entry = NULL;
- struct complex_type_entries_head *entries = NULL;
- dyn_type *subType = NULL;
- int index = -1;
-
- json_t *record_object = json_object();
- if (record_object == NULL) {
- return ERROR;
- }
-
- json_t *record_string = json_string_nocheck("record");
- if (record_string == NULL) {
- json_decref(record_object);
- return ERROR;
- }
-
- char *gen_str = NULL;
- if (generate_record_name(&gen_str) != OK) {
- json_decref(record_object);
- json_decref(record_string);
- return ERROR;
- }
-
- json_t *name_string = json_string(gen_str);
- free(gen_str);
- if (name_string == NULL) {
- json_decref(record_object);
- json_decref(record_string);
- return ERROR;
- }
-
- json_t *record_fields = json_array();
- if (record_fields == NULL) {
- json_decref(record_object);
- json_decref(record_string);
- json_decref(name_string);
- return ERROR;
- }
-
- json_t *field_object = NULL;
- json_t *field_name = NULL;
- json_t *field_schema = NULL;
-
- status = dynType_complex_entries(type, &entries);
-
- if (status == OK) {
- TAILQ_FOREACH(entry, entries, entries) {
- index = dynType_complex_indexForName(type, entry->name);
-
- if (index < 0) {
- status = ERROR;
- LOG_ERROR("Cannot find index for member '%s'.", entry->name);
- }
-
- if (status == OK) {
- status = dynType_complex_dynTypeAt(type, index, &subType);
- }
-
- if (status == OK) {
- field_object = json_object();
- if (field_object == NULL) {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- field_name = json_string(entry->name);
- if (field_name == NULL) {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- status = avrobinSerializer_generateAny(subType, &field_schema);
- }
-
- if (status == OK) {
- if (json_object_set_new_nocheck(field_object, "name", field_name) == 0) {
- field_name = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- if (json_object_set_new_nocheck(field_object, "type", field_schema) == 0) {
- field_schema = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- if (json_array_append_new(record_fields, field_object) == 0) {
- field_object = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (field_object != NULL) {
- json_decref(field_object);
- field_object = NULL;
- }
-
- if (field_name != NULL) {
- json_decref(field_name);
- field_name = NULL;
- }
-
- if (field_schema != NULL) {
- json_decref(field_schema);
- field_schema = NULL;
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- if (status == OK) {
- if (json_object_set_new_nocheck(record_object, "type", record_string) == 0) {
- record_string = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- if (json_object_set_new_nocheck(record_object, "name", name_string) == 0) {
- name_string = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (status == OK) {
- if (json_object_set_new_nocheck(record_object, "fields", record_fields) == 0) {
- record_fields = NULL;
- } else {
- status = ERROR;
- }
- }
-
- if (record_string != NULL) {
- json_decref(record_string);
- record_string = NULL;
- }
-
- if (name_string != NULL) {
- json_decref(name_string);
- name_string = NULL;
- }
-
- if (record_fields != NULL) {
- json_decref(record_fields);
- record_fields = NULL;
- }
-
- if (status == OK) {
- *output = record_object;
- } else {
- json_decref(record_object);
- record_object = NULL;
- }
-
- return status;
-}
-
-static int avrobinSerializer_generateSequence(dyn_type *type, json_t **output) {
- dyn_type *itemType = dynType_sequence_itemType(type);
-
- json_t *array_object = json_object();
- if (array_object == NULL) {
- return ERROR;
- }
-
- json_t *array_string = json_string_nocheck("array");
- if (array_string == NULL) {
- json_decref(array_object);
- return ERROR;
- }
-
- json_t *item_schema = NULL;
- if (avrobinSerializer_generateAny(itemType, &item_schema) != OK) {
- json_decref(array_object);
- json_decref(array_string);
- return ERROR;
- }
-
- if (json_object_set_new_nocheck(array_object, "type", array_string) == 0) {
- array_string = NULL;
- } else {
- json_decref(array_object);
- json_decref(array_string);
- json_decref(item_schema);
- return ERROR;
- }
-
- if (json_object_set_new_nocheck(array_object, "items", item_schema) == 0) {
- item_schema = NULL;
- } else {
- json_decref(array_object);
- json_decref(item_schema);
- return ERROR;
- }
-
- *output = array_object;
-
- return OK;
-}
-
-static int avrobinSerializer_generateEnum(dyn_type *type, json_t **output) {
- json_t *enum_object = json_object();
- if (enum_object == NULL) {
- return ERROR;
- }
-
- json_t *enum_string = json_string_nocheck("enum");
- if (enum_string == NULL) {
- json_decref(enum_object);
- return ERROR;
- }
-
- char *gen_str = NULL;
- if (generate_record_name(&gen_str) != OK) {
- json_decref(enum_object);
- json_decref(enum_string);
- return ERROR;
- }
-
- json_t *name_string = json_string(gen_str);
- free(gen_str);
- if (name_string == NULL) {
- json_decref(enum_object);
- json_decref(enum_string);
- return ERROR;
- }
-
- json_t *symbols_array = json_array();
- if (symbols_array == NULL) {
- json_decref(enum_object);
- json_decref(enum_string);
- json_decref(name_string);
- return ERROR;
- }
-
- struct meta_entry *entry = NULL;
- json_t *symbol_string = NULL;
-
- TAILQ_FOREACH(entry, &type->metaProperties, entries) {
- symbol_string = json_string(entry->name);
- if (symbol_string == NULL) {
- json_decref(enum_object);
- json_decref(enum_string);
- json_decref(name_string);
- json_decref(symbols_array);
- return ERROR;
- }
- if (json_array_append_new(symbols_array, symbol_string) != 0) {
- json_decref(enum_object);
- json_decref(enum_string);
- json_decref(name_string);
- json_decref(symbol_string);
- json_decref(symbols_array);
- return ERROR;
- }
- }
-
- if (json_object_set_new_nocheck(enum_object, "type", enum_string) != 0) {
- json_decref(enum_object);
- json_decref(enum_string);
- json_decref(name_string);
- json_decref(symbols_array);
- return ERROR;
- }
-
- if (json_object_set_new_nocheck(enum_object, "name", name_string) != 0) {
- json_decref(enum_object);
- json_decref(name_string);
- json_decref(symbols_array);
- return ERROR;
- }
-
- if (json_object_set_new_nocheck(enum_object, "symbols", symbols_array) != 0) {
- json_decref(enum_object);
- json_decref(symbols_array);
- return ERROR;
- }
-
- *output = enum_object;
-
- return OK;
-}
-
-static int generate_sync(uint8_t **result) {
- *result = (uint8_t*)malloc(sizeof(uint8_t) * 16);
- if (*result == NULL) {
- return ERROR;
- }
- for (int i=0; i<16; i++) {
- (*result)[i] = (uint8_t)(((double)rand() / (double)RAND_MAX) * 255);
- }
- return OK;
-}
-
-static int generate_record_name(char **result) {
- char num_str[16];
- int rc = snprintf(num_str, sizeof(num_str), "R%u", record_name_counter);
- if (rc >= sizeof(num_str) || rc < 0) {
- return ERROR;
- }
- size_t len = strlen(num_str);
- *result = (char*)malloc(sizeof(char) * (len + 1));
- if (*result == NULL) {
- return ERROR;
- }
- for (int i=0; i<len; i++) {
- (*result)[i] = num_str[i];
- }
- (*result)[len] = '\0';
- record_name_counter++;
- return OK;
-}
-
-static int avrobin_read_boolean(FILE *stream,bool *val) {
- int c = fgetc(stream);
- if (c == EOF) {
- LOG_ERROR("Unexpected end of file.");
- return ERROR;
- }
- if (c!=0 && c!=1) {
- LOG_ERROR("Unexpected value for boolean.");
- return ERROR;
- }
- if (c == 0) {
- *val = false;
- } else {
- *val = true;
- }
- return OK;
-}
-
-static int avrobin_read_int(FILE *stream,int32_t *val) {
- int64_t lval;
- int status = avrobin_read_long(stream,&lval);
- //TODO Do range check.
- *val = (int32_t)lval;
- return status;
-}
-
-static int avrobin_read_long(FILE *stream,int64_t *val) {
- uint64_t uval = 0;
- uint8_t b;
- int c;
- int offset = 0;
- do {
- if (offset == MAX_VARINT_BUF_SIZE) {
- LOG_ERROR("Varint too long.");
- return ERROR;
- }
- c = fgetc(stream);
- if (c == EOF) {
- LOG_ERROR("Unexpected end of file.");
- return ERROR;
- }
- b = (uint8_t)c;
- uval |= (uint64_t) (b & 0x7F) << (7 * offset);
- ++offset;
- }
- while (b & 0x80);
- *val = ((uval >> 1) ^ -(uval & 1));
- return OK;
-}
-
-static int avrobin_read_float(FILE *stream,float *val) {
- uint8_t b[4];
- int c;
- for (int i=0;i<4;i++) {
- c = fgetc(stream);
- if (c == EOF) {
- LOG_ERROR("Unexpected end of file.");
- return ERROR;
- }
- b[i] = (uint8_t)c;
- }
- union {
- float f;
- uint32_t i;
- } v;
- v.i =
- ((uint32_t)b[0] << 0) |
- ((uint32_t)b[1] << 8) |
- ((uint32_t)b[2] << 16) |
- ((uint32_t)b[3] << 24);
- *val = v.f;
- return OK;
-}
-
-static int avrobin_read_double(FILE *stream,double *val) {
- uint8_t b[8];
- int c;
- for (int i=0;i<8;i++) {
- c = fgetc(stream);
- if (c == EOF) {
- LOG_ERROR("Unexpected end of file.");
- return ERROR;
- }
- b[i] = (uint8_t)c;
- }
- union {
- double d;
- uint64_t i;
- } v;
- v.i =
- ((uint64_t)b[0] << 0) |
- ((uint64_t)b[1] << 8) |
- ((uint64_t)b[2] << 16) |
- ((uint64_t)b[3] << 24) |
- ((uint64_t)b[4] << 32) |
- ((uint64_t)b[5] << 40) |
- ((uint64_t)b[6] << 48) |
- ((uint64_t)b[7] << 56);
- *val = v.d;
- return OK;
-}
-
-static int avrobin_read_string(FILE *stream,char **val) {
- int64_t len;
- if (avrobin_read_long(stream,&len) != OK) {
- LOG_ERROR("Failed to read string length.");
- return ERROR;
- }
- if (len < 0) {
- LOG_ERROR("Negative string length.");
- return ERROR;
- }
- *val = (char*)malloc(sizeof(char) * (len+1));
- if (*val == NULL) {
- LOG_ERROR("Failed to allocate memory for avro string.");
- return ERROR;
- }
- int c;
- for (int64_t i=0;i<len;i++) {
- c = fgetc(stream);
- if (c == EOF) {
- LOG_ERROR("Unexpected end of file.");
- free(*val);
- return ERROR;
- }
- (*val)[i] = (char)c;
- }
- (*val)[len] = '\0';
- return OK;
-}
-
-static int avrobin_write_boolean(FILE *stream,bool val) {
- int r;
- if (val) {
- r = fputc(1, stream);
- } else {
- r = fputc(0, stream);
- }
- if (r == EOF) {
- LOG_ERROR("Write error.");
- return ERROR;
- }
- return OK;
-}
-
-static int avrobin_write_int(FILE *stream,int32_t val) {
- int64_t lval = val;
- return avrobin_write_long(stream,lval);
-}
-
-static int avrobin_write_long(FILE *stream,int64_t val) {
- uint64_t uval = (val << 1) ^ (val >> 63);
- uint8_t b[MAX_VARINT_BUF_SIZE];
- int bytes_written = 0;
- while (uval & ~0x7F) {
- b[bytes_written++] = (uint8_t)((uval & 0x7F) | 0x80);
- uval >>= 7;
- }
- b[bytes_written++] = (uint8_t)uval;
- for (int i=0;i<bytes_written;i++) {
- if (fputc(b[i],stream) == EOF) {
- LOG_ERROR("Write error.");
- return ERROR;
- }
- }
- return OK;
-}
-
-static int avrobin_write_float(FILE *stream,float val) {
- uint8_t b[4];
- union {
- float f;
- uint32_t i;
- } v;
- v.f = val;
- b[0] = (uint8_t)((v.i & 0x000000FF) >> 0);
- b[1] = (uint8_t)((v.i & 0x0000FF00) >> 8);
- b[2] = (uint8_t)((v.i & 0x00FF0000) >> 16);
- b[3] = (uint8_t)((v.i & 0xFF000000) >> 24);
- for (int i=0;i<4;i++) {
- if (fputc(b[i],stream) == EOF) {
- LOG_ERROR("Write error.");
- return ERROR;
- }
- }
- return OK;
-}
-
-static int avrobin_write_double(FILE *stream,double val) {
- uint8_t b[8];
- union {
- double d;
- uint64_t i;
- } v;
- v.d = val;
- b[0] = (uint8_t)((v.i & 0x00000000000000FF) >> 0);
- b[1] = (uint8_t)((v.i & 0x000000000000FF00) >> 8);
- b[2] = (uint8_t)((v.i & 0x0000000000FF0000) >> 16);
- b[3] = (uint8_t)((v.i & 0x00000000FF000000) >> 24);
- b[4] = (uint8_t)((v.i & 0x000000FF00000000) >> 32);
- b[5] = (uint8_t)((v.i & 0x0000FF0000000000) >> 40);
- b[6] = (uint8_t)((v.i & 0x00FF000000000000) >> 48);
- b[7] = (uint8_t)((v.i & 0xFF00000000000000) >> 56);
- for (int i=0;i<8;i++) {
- if (fputc(b[i],stream) == EOF) {
- LOG_ERROR("Write error.");
- return ERROR;
- }
- }
- return OK;
-}
-
-static int avrobin_write_string(FILE *stream,const char *val) {
- assert(val != NULL);
- size_t len = strlen(val);
- if (avrobin_write_long(stream, (int64_t)len) != OK) {
- LOG_ERROR("Failed to write string length.");
- return ERROR;
- }
- for (size_t i=0;i<len;i++) {
- if (fputc((unsigned char)(val[i]),stream) == EOF) {
- LOG_ERROR("Write error.");
- return ERROR;
- }
- }
- return OK;
-}
-
-static int avrobin_schema_primitive(const char *tname, json_t **output) {
- json_t *jo = json_object();
- if (jo == NULL) {
- return ERROR;
- }
- json_t *js = json_string(tname);
- if (js == NULL) {
- json_decref(jo);
- return ERROR;
- }
- if (json_object_set_new_nocheck(jo, "type", js) != 0) {
- json_decref(jo);
- json_decref(js);
- return ERROR;
- }
- *output = jo;
- return OK;
-}
diff --git a/libs/dfi/src/dyn_avpr_function.c b/libs/dfi/src/dyn_avpr_function.c
deleted file mode 100644
index e358f9a9..00000000
--- a/libs/dfi/src/dyn_avpr_function.c
+++ /dev/null
@@ -1,344 +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 "dyn_function.h"
-#include "dyn_function_common.h"
-
-#include "jansson.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-
-DFI_SETUP_LOG(dynAvprFunction)
-
-#define FQN_SIZE 256
-#define ARG_SIZE 32
-
-// Section: static function declarations
-dyn_function_type * dynAvprFunction_parseFromJson(json_t * const root, const char * fqn);
-static json_t const * const dynAvprFunction_findFunc(const char * fqn, json_t * const messagesObject, const char * parentNamespace);
-static bool dynAvprFunction_parseFunc(dyn_function_type * func, json_t const * const jsonFuncObject, json_t * const root, const char * fqn, const char * parentNamespace);
-inline static bool dynAvprFunction_parseArgument(dyn_function_type * func, size_t index, json_t const * entry, json_t * const root, const char * namespace, char * argBuffer, char * typeBuffer);
-inline static bool dynAvprFunction_parseReturn(dyn_function_type * func, size_t index, json_t const * const response_type, json_t * const root, const char * namespace, char * typeBuffer);
-inline static bool dynAvprFunction_createHandle(dyn_function_type * func);
-inline static dyn_function_argument_type * dynAvprFunction_prepareArgumentEntry(const char * name);
-inline static dyn_type * dynAvprFunction_createVoidType();
-inline static dyn_type * dynAvprFunction_createNativeType();
-inline static bool dynAvprFunction_initCif(dyn_function_type * func, size_t nofArguments);
-
-// Section: extern function definitions
-ffi_type * dynType_ffiType(dyn_type *type);
-dyn_type * dynAvprType_createNestedForFunction(dyn_type * store_type, const char* fqn);
-dyn_type * dynAvprType_parseFromTypedJson(json_t * const root, json_t const * const type_entry, const char * namespace);
-void dynAvprType_constructFqn(char *destination, size_t size, const char *possibleFqn, const char *ns);
-
-// Section: function definitions
-dyn_function_type * dynFunction_parseAvpr(FILE * avprStream, const char * fqn) {
- json_error_t error;
- json_t *root = json_loadf(avprStream, JSON_REJECT_DUPLICATES, &error);
- if (!root) {
- LOG_ERROR("function_parseAvpr: Error decoding json: line %d: %s", error.line, error.text);
- return NULL;
- }
-
- dyn_function_type * func = dynAvprFunction_parseFromJson(root, fqn);
- json_decref(root);
- return func;
-}
-
-dyn_function_type * dynFunction_parseAvprWithStr(const char * avpr, const char * fqn) {
- FILE *avprStream = fmemopen((char*)avpr, strlen(avpr), "r");
-
- if (!avprStream) {
- LOG_ERROR("function_parseAvprWithStr: Error creating mem stream for descriptor string. %s", strerror(errno));
- return NULL;
- }
-
- dyn_function_type *returnValue = dynFunction_parseAvpr(avprStream, fqn);
- fclose(avprStream);
- return returnValue;
-}
-
-dyn_function_type * dynAvprFunction_parseFromJson(json_t * const root, const char * fqn) {
- bool valid = true;
- dyn_function_type *func = calloc(1, sizeof(*func));
-
- if (!json_is_object(root)) {
- LOG_ERROR("ParseFunction: Error decoding json, root should be an object");
- valid = false;
- }
-
- // Get base namespace
- const char *parentNamespace = json_string_value(json_object_get(root, "namespace"));
- if (valid && !parentNamespace) {
- LOG_ERROR("ParseFunction: No namespace found in root, or it is null!");
- valid = false;
- }
-
- // Get messages array
- json_t * const messagesObject = json_object_get(root, "messages");
- if (valid && !json_is_object(messagesObject)) {
- LOG_ERROR("ParseFunction: No messages, or it is not an object");
- valid = false;
- }
-
- if (valid && !dynAvprFunction_parseFunc(func, dynAvprFunction_findFunc(fqn, messagesObject, parentNamespace), root, fqn, parentNamespace)) {
- LOG_ERROR("parseAvpr: Destroying incorrect result");
- dynFunction_destroy(func);
- func = NULL;
- }
-
- return func;
-}
-
-static json_t const * const dynAvprFunction_findFunc(const char * fqn, json_t * const messagesObject, const char * parentNamespace) {
- char nameBuffer[FQN_SIZE];
- const char * func_name;
- json_t const * func_entry;
- json_t const * local_ns;
- json_object_foreach(messagesObject, func_name, func_entry) {
- local_ns = json_object_get(func_entry, "namespace");
- dynAvprType_constructFqn(nameBuffer, FQN_SIZE, func_name, json_is_string(local_ns) ? json_string_value(local_ns) : parentNamespace);
-
- if (strcmp(nameBuffer, fqn) == 0) {
- return func_entry;
- }
- }
- LOG_ERROR("FindFunc: Not found function definition for %s", fqn);
- return NULL;
-}
-
-static bool dynAvprFunction_parseFunc(dyn_function_type * func, json_t const * const jsonFuncObject, json_t * const root, const char * fqn, const char * parentNamespace) {
- if (!jsonFuncObject) {
- LOG_ERROR("ParseFunc: Received NULL, function not found, nothing to parse");
- return false;
- }
-
- func->name = strdup(fqn);
- if (!func->name) {
- LOG_ERROR("ParseFunc: Error allocating memory for function name %s", fqn);
- return false;
- }
-
- json_t const * const argument_list = json_object_get(jsonFuncObject, "request");
- if (!json_is_array(argument_list)) {
- LOG_ERROR("ParseFunc: Request is not an array");
- free(func->name);
- return false;
- }
-
- json_t const * const json_function_namespace = json_object_get(jsonFuncObject, "namespace");
- const char* function_namespace = json_is_string(json_function_namespace) ? json_string_value(json_function_namespace) : parentNamespace;
-
- // Parse requests argument array
- TAILQ_INIT(&func->arguments);
- if (!dynAvprFunction_createHandle(func)) {
- LOG_ERROR("ParseFunc: Could not creat handle for %s", fqn);
- free(func->name);
- return false;
- }
- char argBuffer[ARG_SIZE];
- char typeBuffer[FQN_SIZE];
- size_t index;
- json_t const * arg_entry;
- json_array_foreach(argument_list, index, arg_entry) {
- if (!dynAvprFunction_parseArgument(func, index+1, arg_entry, root, function_namespace, argBuffer, typeBuffer)) { /* Offset index to account for the handle */
- LOG_ERROR("ParseFunc: Could not parse argument %zu for %s", index, fqn);
- return false;
- }
- }
- index++;
-
- json_t const * const response_type = json_object_get(jsonFuncObject, "response");
- if (!dynAvprFunction_parseReturn(func, index, response_type, root, function_namespace, typeBuffer)) {
- LOG_ERROR("ParseFunc: Could not parse return type for %s", fqn);
- free(func->name);
- return false;
- }
- index+=1;
-
- func->funcReturn = dynAvprFunction_createNativeType();
- if (!func->funcReturn) {
- LOG_ERROR("ParseFunc: Could not create error indicator for %s", fqn);
- return false;
- }
-
- if (!dynAvprFunction_initCif(func, index)) {
- LOG_ERROR("ParseFunc: Could not prepare cif information");
- return false;
- }
-
- // Everything successfull
- return true;
-}
-
-inline static bool dynAvprFunction_parseArgument(dyn_function_type * func, size_t index, json_t const * entry, json_t * const root, const char * namespace, char * argBuffer, char * typeBuffer) {
- const char * entry_name = json_string_value(json_object_get(entry, "name"));
- if (!entry_name) {
- snprintf(argBuffer, ARG_SIZE, "arg%04lu", (long unsigned int) index);
- entry_name = argBuffer;
- }
-
- dyn_type * entry_dyn_type = dynAvprType_parseFromTypedJson(root, json_object_get(entry, "type"), namespace);
- if (!entry_dyn_type) {
- LOG_ERROR("ParseArgument: Could not parse type for argument");
- return false;
- }
-
- if (json_is_true(json_object_get(entry, "ptr"))) {
- entry_dyn_type = dynAvprType_createNestedForFunction(entry_dyn_type, entry_name);
- if (!entry_dyn_type) {
- LOG_ERROR("ParseArgument: Could not create pointer argument for %s", entry_name);
- dynType_destroy(entry_dyn_type);
- return false;
- }
- }
-
- dyn_function_argument_type *arg = dynAvprFunction_prepareArgumentEntry(entry_name);
- if (!arg) {
- dynType_destroy(entry_dyn_type);
- return false;
- }
-
- arg->index = (int) index;
- arg->type = entry_dyn_type;
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD;
-
- TAILQ_INSERT_TAIL(&func->arguments, arg, entries);
- return true;
-}
-
-inline static bool dynAvprFunction_parseReturn(dyn_function_type * func, size_t index, json_t const * const response_type, json_t * const root, const char * namespace, char * typeBuffer) {
- dyn_type * return_dyn_type = dynAvprType_parseFromTypedJson(root, response_type, namespace);
- if (!return_dyn_type) {
- LOG_ERROR("ParseReturn: Could not parse return argument");
- return false;
- }
-
- dyn_type * out_dyn_type = dynAvprType_createNestedForFunction(return_dyn_type, "out");
- if (!out_dyn_type) {
- LOG_ERROR("ParseReturn: Could not create pointer for return type");
- dynType_destroy(return_dyn_type);
- return false;
- }
-
- dyn_function_argument_type *arg = dynAvprFunction_prepareArgumentEntry("out");
- if (!arg) {
- LOG_ERROR("ParseReturn: Could not create nested type for return type");
- dynType_destroy(out_dyn_type);
- return false;
- }
-
- arg->index = (int) index;
-
- // Check descriptor type, if it is a struct ({), sequence ([) or a string (t) an extra level of indirection is needed
- int descriptor = dynType_descriptorType(return_dyn_type);
- if (descriptor == '{' || descriptor == '[') {
- out_dyn_type = dynAvprType_createNestedForFunction(out_dyn_type, "out");
- if (!out_dyn_type) {
- LOG_ERROR("ParseReturn: Could not create nested type for return complex type");
- dynType_destroy(out_dyn_type);
- return false;
- }
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__OUTPUT;
- }
- else {
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT;
- }
-
- arg->type = out_dyn_type;
- TAILQ_INSERT_TAIL(&func->arguments, arg, entries);
- return true;
-}
-
-inline static bool dynAvprFunction_createHandle(dyn_function_type * func) {
- dyn_function_argument_type * arg = dynAvprFunction_prepareArgumentEntry("handle");
- if (!arg) {
- return false;
- }
-
- arg->index = 0;
- arg->type = dynAvprFunction_createVoidType();
- if (!arg->type) {
- free(arg);
- return false;
- }
-
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__HANDLE;
- TAILQ_INSERT_TAIL(&func->arguments, arg, entries);
- return true;
-}
-
-inline static dyn_function_argument_type * dynAvprFunction_prepareArgumentEntry(const char * name) {
- if (!name) {
- LOG_ERROR("PrepareArgumentEntry: Need name to create argument entry");
- return NULL;
- }
-
- dyn_function_argument_type *arg = calloc(1, sizeof(*arg));
- arg->name = strdup(name);
- return arg;
-}
-
-inline static dyn_type * dynAvprFunction_createVoidType() {
- const char * entry = "{ \
- \"protocol\" : \"types\", \
- \"namespace\" : \"dummy\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"VoidPtr\", \
- \"alias\" : \"void_ptr\", \
- \"size\" : 4 \
- } ] ,\
- \"messages\" : { }\
- }";
- return dynType_parseAvprWithStr(entry, "dummy.VoidPtr");
-}
-
-inline static dyn_type * dynAvprFunction_createNativeType() {
- const char * entry = "{ \
- \"protocol\" : \"types\", \
- \"namespace\" : \"dummy\", \
- \"types\" : [ { \
- \"type\" : \"fixed\", \
- \"name\" : \"NativeInt\", \
- \"alias\" : \"native_int\", \
- \"size\" : 4 \
- } ] ,\
- \"messages\" : { }\
- }";
- return dynType_parseAvprWithStr(entry, "dummy.NativeInt");
-}
-
-inline static bool dynAvprFunction_initCif(dyn_function_type * func, size_t nofArguments) {
- func->ffiArguments = calloc(nofArguments, sizeof(ffi_type*));
- dyn_function_argument_type *entry = NULL;
- TAILQ_FOREACH(entry, &func->arguments, entries) {
- func->ffiArguments[entry->index] = dynType_ffiType(entry->type);
- }
-
- ffi_type *returnType = dynType_ffiType(func->funcReturn);
- int ffi_result = ffi_prep_cif(&func->cif, FFI_DEFAULT_ABI, (int) nofArguments, returnType, func->ffiArguments);
-
- return ffi_result == FFI_OK;
-}
-
diff --git a/libs/dfi/src/dyn_avpr_interface.c b/libs/dfi/src/dyn_avpr_interface.c
deleted file mode 100644
index ececeffe..00000000
--- a/libs/dfi/src/dyn_avpr_interface.c
+++ /dev/null
@@ -1,290 +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 "dyn_interface.h"
-#include "dyn_interface_common.h"
-
-#include "jansson.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "dyn_function.h"
-
-DFI_SETUP_LOG(dynAvprInterface)
-
-#define STR_LENGTH 1024
-#define FQN_SIZE 256
-#define ARG_SIZE 32
-
-// Section: function definitions
-inline static dyn_interface_type * dynAvprInterface_initializeInterface();
-inline static bool dynAvprInterface_createHeader(dyn_interface_type* intf, json_t * const root);
-inline static bool dynAvprInterface_createAnnotations(dyn_interface_type* intf, json_t * const root);
-inline static bool dynAvprInterface_createTypes(dyn_interface_type* intf, json_t * const root, const char* parent_ns);
-inline static bool dynAvprInterface_createMethods(dyn_interface_type* intf, json_t * const root, const char* parent_ns);
-static bool dynAvprInterface_insertNamValEntry(struct namvals_head *head, const char* name, const char* value);
-static struct namval_entry * dynAvprInterface_createNamValEntry(const char* name, const char* value);
-
-// Section: extern function definitions
-ffi_type * dynType_ffiType(dyn_type *type);
-dyn_type * dynAvprType_parseFromJson(json_t * const root, const char * fqn);
-dyn_function_type * dynAvprFunction_parseFromJson(json_t * const root, const char * fqn);
-int dynInterface_checkInterface(dyn_interface_type *intf);
-void dynAvprType_constructFqn(char *destination, size_t size, const char *possibleFqn, const char *ns);
-
-// Function definitions
-dyn_interface_type * dynInterface_parseAvprWithStr(const char * avpr) {
- FILE *avprStream = fmemopen((char*)avpr, strlen(avpr), "r");
-
- if (!avprStream) {
- LOG_ERROR("interface_parseAvprWithStr: Error creating mem stream for descriptor string. %s", strerror(errno));
- return NULL;
- }
-
- dyn_interface_type *returnValue = dynInterface_parseAvpr(avprStream);
- fclose(avprStream);
- return returnValue;
-}
-
-dyn_interface_type * dynInterface_parseAvpr(FILE * avprStream) {
- dyn_interface_type *intf = NULL;
- bool valid = true;
- json_error_t error;
- json_t *root = json_loadf(avprStream, JSON_REJECT_DUPLICATES, &error);
- if (!root) {
- LOG_ERROR("interface_parseAvpr: Error decoding json: line %d: %s", error.line, error.text);
- valid = false;
- }
-
- if (valid && !json_is_object(root)) {
- LOG_ERROR("interface_parseAvpr: Error decoding json, root should be an object");
- valid = false;
- }
-
- const char *parent_ns = json_string_value(json_object_get(root, "namespace"));
- if (valid && !parent_ns) {
- LOG_ERROR("interface_parseAvpr: No namespace found in root, or it is null!");
- valid = false;
- }
-
- json_t * const messagesObject = json_object_get(root, "messages");
- if (valid && !json_is_object(messagesObject)) {
- LOG_ERROR("interface_parseAvpr: No messages, or it is not an object");
- valid = false;
- }
-
- if (valid) {
- intf = dynAvprInterface_initializeInterface();
- valid = intf != NULL;
- }
-
- valid = valid && dynAvprInterface_createHeader(intf, root);
- valid = valid && dynAvprInterface_createAnnotations(intf, root);
- valid = valid && dynAvprInterface_createTypes(intf, root, parent_ns);
- valid = valid && dynAvprInterface_createMethods(intf, root, parent_ns);
-
- valid = valid && 0 == dynInterface_checkInterface(intf);
-
- json_decref(root);
- if (valid) {
- return intf;
- }
- else {
- LOG_ERROR("Parsing of avpr interface failed");
- dynInterface_destroy(intf);
- return NULL;
- }
-}
-
-inline static dyn_interface_type * dynAvprInterface_initializeInterface() {
- dyn_interface_type *intf = calloc(1, sizeof(*intf));
-
- TAILQ_INIT(&intf->header);
- TAILQ_INIT(&intf->annotations);
- TAILQ_INIT(&intf->types);
- TAILQ_INIT(&intf->methods);
-
- return intf;
-}
-
-inline static bool dynAvprInterface_createHeader(dyn_interface_type* intf, json_t * const root) {
- // type
- if (!dynAvprInterface_insertNamValEntry(&intf->header, "type", "interface")) {
- return false;
- }
-
- // name (protocol in avpr-speak)
- if (!dynAvprInterface_insertNamValEntry(&intf->header, "name", json_string_value(json_object_get(root, "protocol")))) {
- return false;
- }
-
- // version
- if (!dynAvprInterface_insertNamValEntry(&intf->header, "version", json_string_value(json_object_get(root, "version")))) {
- return false;
- }
-
- // Also parse version in the intf->version for cel
- char* version = NULL;
- dynInterface_getVersionString(intf, &version);
- if (!version) {
- LOG_ERROR("No version string in header");
- return false;
- }
-
- intf->version = celix_version_createVersionFromString(version);
- if (intf->version == NULL) {
- LOG_ERROR("Invalid version (%s) in parsed descriptor\n", version);
- return false;
- }
-
- return true;
-}
-
-inline static bool dynAvprInterface_createAnnotations(dyn_interface_type* intf, json_t * const root) {
- // namespace
- if (!dynAvprInterface_insertNamValEntry(&intf->annotations, "namespace", json_string_value(json_object_get(root, "namespace")))) {
- return false;
- }
-
- // TODO: other annotations?
-
- return true;
-}
-
-inline static bool dynAvprInterface_createTypes(dyn_interface_type* intf, json_t * const root, const char* parent_ns) {
- json_t const * const types_array = json_object_get(root, "types");
- if (!types_array || !json_is_array(types_array)) {
- LOG_ERROR("json: types is not an array or it does not exists!");
- return false;
- }
-
- char name_buffer[FQN_SIZE];
- json_t const * entry;
- json_t const * local_ns;
- char const * name;
- size_t index;
- struct type_entry *t_entry = NULL;
- json_array_foreach(types_array, index, entry) {
- local_ns = json_object_get(entry, "namespace");
- name = json_string_value(json_object_get(entry, "name"));
- if (!name) {
- LOG_ERROR("Type entry %zu has no name", index);
- return false;
- }
- dynAvprType_constructFqn(name_buffer, FQN_SIZE, name, json_is_string(local_ns) ? json_string_value(local_ns) : parent_ns);
-
- t_entry = calloc(1, sizeof(*t_entry));
- t_entry->type = dynAvprType_parseFromJson(root, name_buffer);
- if (!t_entry->type) {
- free(t_entry);
- return false;
- }
-
- TAILQ_INSERT_TAIL(&intf->types, t_entry, entries);
- }
-
- return true;
-}
-
-inline static bool dynAvprInterface_createMethods(dyn_interface_type* intf, json_t * const root, const char* parent_ns) {
- json_t * const messages_object = json_object_get(root, "messages");
- if (!messages_object || !json_is_object(messages_object)) {
- LOG_ERROR("json: messages is not an object or it does not exist!");
- return false;
- }
-
- char name_buffer[FQN_SIZE];
- json_t const * func_entry;
- json_t const * local_ns;
- json_t const * j_index;
- char const * func_name;
- struct method_entry *m_entry = NULL;
- json_object_foreach(messages_object, func_name, func_entry) {
- local_ns = json_object_get(func_entry, "namespace");
- dynAvprType_constructFqn(name_buffer, FQN_SIZE, func_name, json_is_string(local_ns) ? json_string_value(local_ns) : parent_ns);
-
- m_entry = calloc(1, sizeof(*m_entry));
- m_entry->dynFunc = dynAvprFunction_parseFromJson(root, name_buffer);
- if (!m_entry->dynFunc) {
- free(m_entry);
- return false;
- }
-
- j_index = json_object_get(func_entry, "index");
- if (!json_is_integer(j_index)) {
- LOG_ERROR("For parsing an interface annotate all functions with an integer index");
- dynFunction_destroy(m_entry->dynFunc);
- free(m_entry);
- return false;
- }
-
- m_entry->index = json_integer_value(j_index);
- m_entry->id = strndup(func_name, STR_LENGTH);
- if (!m_entry->id) {
- LOG_ERROR("Could not allocate memory for method entry name %s", func_name);
- dynFunction_destroy(m_entry->dynFunc);
- free(m_entry);
- return false;
- }
-
- m_entry->name = strndup(func_name, STR_LENGTH); // For avpr these are the same
- if (!m_entry->id) {
- LOG_ERROR("Could not allocate memory for method entry id %s", func_name);
- dynFunction_destroy(m_entry->dynFunc);
- free(m_entry);
- return false;
- }
- TAILQ_INSERT_TAIL(&intf->methods, m_entry, entries);
- }
-
- // Parsed all methods
- return true;
-}
-
-static bool dynAvprInterface_insertNamValEntry(struct namvals_head *head, const char* name, const char* value) {
- struct namval_entry *entry = dynAvprInterface_createNamValEntry(name, value);
- if (!entry) {
- return false;
- }
- else {
- TAILQ_INSERT_TAIL(head, entry, entries);
- return true;
- }
-}
-
-static struct namval_entry * dynAvprInterface_createNamValEntry(const char* name, const char* value) {
- if (!name) {
- LOG_ERROR("Passed null-ptr to name of name-value entry creation function, unknown what type to create");
- return NULL;
- }
-
- if (!value) {
- LOG_ERROR("Received a name (%s) but no value, did the look-up for a value fail?", name);
- return NULL;
- }
-
- struct namval_entry *entry = calloc(1, sizeof(*entry));
- entry->name = strndup(name, STR_LENGTH);
- entry->value = strndup(value, STR_LENGTH);
- return entry;
-}
-
diff --git a/libs/dfi/src/dyn_avpr_type.c b/libs/dfi/src/dyn_avpr_type.c
deleted file mode 100644
index 32c41fd8..00000000
--- a/libs/dfi/src/dyn_avpr_type.c
+++ /dev/null
@@ -1,1054 +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 "dyn_type.h"
-
-#include "jansson.h"
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-#include <ffi.h>
-
-#include "dyn_type.h"
-#include "dyn_type_common.h"
-#include "celix_version.h"
-
-DFI_SETUP_LOG(dynAvprType)
-
-#define STR_LENGTH 1024
-#define FQN_SIZE 256
-
-enum JsonTypeType {INVALID=0, SIMPLE=1, ARRAY=2, REFERENCE=3, SELF_REFERENCE=4};
-
-dyn_type * dynAvprType_parseFromJson(json_t * const root, const char * fqn);
-dyn_type * dynAvprType_createNestedForFunction(dyn_type * store_type, const char* fqn);
-dyn_type * dynAvprType_parseFromTypedJson(json_t * const root, json_t const * const type_entry, const char * namespace);
-void dynAvprType_constructFqn(char *destination, size_t size, const char *possibleFqn, const char *ns);
-
-// Any
-static json_t const * dynAvprType_findType(char const * const fqn, json_t const * const array_object, const char * ns);
-static dyn_type * dynAvprType_parseAny(dyn_type * root, dyn_type * parent, json_t const * const jsonObject, json_t const * const array_object, const char * parent_ns);
-static dyn_type * dynAvprType_initializeType(dyn_type * parent);
-
-// Record
-static dyn_type * dynAvprType_parseRecord(dyn_type * root, dyn_type * parent, json_t const * const record_obj, json_t const * const array_object, const char* parent_ns);
-static inline dyn_type * dynAvprType_prepareRecord(dyn_type * parent, json_t const ** fields, json_t const * const record_obj);
-static inline bool dynAvprType_finalizeRecord(dyn_type * type, const size_t size);
-static inline struct complex_type_entry *dynAvprType_prepareRecordEntry(json_t const *const entry_object);
-static inline struct complex_type_entry *dynAvprType_parseRecordEntry(dyn_type *root, dyn_type *parent, json_t const *const entry_object, json_t const *const array_object, const char *fqn_parent, const char *parent_ns, const char *record_ns);
-static inline enum JsonTypeType dynAvprType_getRecordEntryType(json_t const * const entry_object, const char * fqn_parent, char * name_buffer, const char * namespace);
-
-// Reference
-static dyn_type * dynAvprType_parseReference(dyn_type * root, const char * name_buffer, json_t const * const array_object, const char * parent_ns);
-static dyn_type * dynAvprType_parseSelfReference(dyn_type * parent);
-static dyn_type * dynAvprType_initializeReferenceType(dyn_type * type_pointer);
-static inline struct type_entry * dynAvprType_prepareNestedEntry(dyn_type * const parent, const char * fqn, bool allocate);
-
-// Enum
-static dyn_type * dynAvprType_parseEnum(dyn_type * parent, json_t const * const enum_obj, const char * parent_ns);
-static inline struct meta_entry * dynAvprType_createMetaEntry(const char* enum_entry_name);
-static inline bool dynAvprType_metaEntrySetValue(struct meta_entry * meta_entry_ptr, json_t const * const values_array, size_t index);
-static inline void dynAvprType_parseEnumValue(char** enumvalue);
-
-// Array
-static dyn_type * dynAvprType_parseArray(dyn_type * root, dyn_type * parent, json_t const * const array_entry_obj, json_t const * const array_object, char * name_buffer, const char * parent_ns, const char * record_ns);
-
-// Fixed
-static dyn_type * dynAvprType_parseFixed(dyn_type * parent, json_t const * const fixed_object, const char * parent_ns);
-static inline char dynAvprType_fixedTypeToFfi(json_t const * const simple_obj, ffi_type ** output_ffi_type);
-
-// Simple
-static dyn_type * dynAvprType_createSimpleTypeFromName(dyn_type * parent, const char * type_name);
-static dyn_type * dynAvprType_createSimpleType(dyn_type * parent, char kind, const char * name);
-
-// General
-static char * dynAvprType_createFqnFromJson(json_t const * const jsonObject, const char * namespace);
-static inline enum JsonTypeType dynAvprType_getType(json_t const * const json_type);
-static inline void dynAvprType_createVersionMetaEntry(dyn_type * type, json_t const * const root, json_t const * const array_object, const char* parent_ns);
-static inline void dynAvprType_createAnnotationEntries(dyn_type * type, json_t const * const array_object, const char* parent_ns);
-
-// fqn = fully qualified name
-dyn_type * dynType_parseAvpr(FILE* avprStream, const char *fqn) {
- json_error_t error;
- json_t *root = json_loadf(avprStream, JSON_REJECT_DUPLICATES, &error);
- if (!root) {
- LOG_ERROR("parseAvpr: Error decoding json: line %d: %s", error.line, error.text);
- return NULL;
- }
-
- dyn_type * type = dynAvprType_parseFromJson(root, fqn);
- json_decref(root);
- return type;
-}
-
-dyn_type * dynType_parseAvprWithStr(const char* avpr, const char *fqn) {
- FILE *avprStream = fmemopen((char*)avpr, strlen(avpr), "r");
-
- if (!avprStream) {
- LOG_ERROR("parseAvprWithStr: Error creating mem stream for descriptor string. %s", strerror(errno));
- return NULL;
- }
-
- dyn_type *returnValue = dynType_parseAvpr(avprStream, fqn);
- fclose(avprStream);
- return returnValue;
-}
-
-// Based on the fqn passed in, try to find an entry in the array_object with that name, the current namespace is defined by the parameter ns
-static json_t const * dynAvprType_findType(char const * const fqn, json_t const * const array_object, const char * ns) {
- char fqn_buffer[FQN_SIZE];
- size_t index;
- json_t const * type_entry;
-
- json_array_foreach(array_object, index, type_entry) {
- const char* entry_name = json_string_value(json_object_get(type_entry, "name"));
- if (entry_name) {
- const char* entry_ns = json_string_value(json_object_get(type_entry, "namespace"));
- snprintf(fqn_buffer, FQN_SIZE, "%s.%s", entry_ns ? entry_ns : ns, entry_name);
- if (strcmp(fqn, fqn_buffer) == 0) {
- return type_entry; // Found
- }
- }
- else {
- LOG_ERROR("FindType: found a type with no name, check your json configuration, skipping this entry for now...");
- }
- }
- return NULL; // Not found
-}
-
-dyn_type * dynAvprType_parseFromJson(json_t * const root, const char * fqn) {
- // Initialize type
- bool valid = true;
- if (!json_is_object(root)) {
- LOG_ERROR("parseAvpr: Error decoding json, root should be an object");
- valid = false;
- }
-
- // Get base namespace
- const char *parent_ns = json_string_value(json_object_get(root, "namespace"));
- if (valid && !parent_ns) {
- LOG_ERROR("parseAvpr: No namespace found in root, or it is null!");
- valid = false;
- }
-
- // Get types array
- json_t* typesArrayObject = json_object_get(root, "types");
- if (valid && !json_is_array(typesArrayObject)) {
- LOG_ERROR("parseAvpr: types should be an array!");
- valid = false;
- }
-
- // Try to find the fqn and parse if it is found, if any error occurs during parsing, return NULL
- dyn_type * type = NULL;
- if (valid) {
- type = dynAvprType_parseAny(NULL, NULL, dynAvprType_findType(fqn, typesArrayObject, parent_ns), typesArrayObject, parent_ns);
- valid = type != NULL;
- }
-
- // Add version as a meta entry
- if (valid) {
- dynAvprType_createVersionMetaEntry(type, root, typesArrayObject, parent_ns);
- // Add any other annotation fields that are not in [type, name, fields, version, alias]
- dynAvprType_createAnnotationEntries(type, typesArrayObject, parent_ns);
-
- }
-
- if (!valid) {
- LOG_ERROR("Not found %s", fqn);
- }
-
- return type;
-}
-
-dyn_type * dynAvprType_createNestedForFunction(dyn_type * store_type, const char* fqn) {
- if (!store_type) {
- return NULL;
- }
-
- // Created dyn_type for reference argument in function
- dyn_type * entry_ref_type = dynAvprType_initializeType(NULL);
- if (!entry_ref_type) {
- dynType_destroy(store_type);
- return NULL;
- }
-
- // Create pointer type and enter type in nested types
- struct type_entry *entry = dynAvprType_prepareNestedEntry(entry_ref_type, fqn, false);
- if (!entry) {
- free(entry_ref_type);
- return NULL;
- }
-
- entry->type = store_type;
- entry_ref_type->type = DYN_TYPE_TYPED_POINTER;
- entry_ref_type->descriptor = '*';
- entry_ref_type->ffiType = &ffi_type_pointer;
-
- // Create reference type for the sub type
- dyn_type * sub_type = dynAvprType_initializeType(entry_ref_type);
- if (!sub_type) {
- dynType_destroy(store_type);
- free(entry_ref_type);
- free(entry);
- return NULL;
- }
-
- entry_ref_type->typedPointer.typedType = sub_type;
- sub_type->type = DYN_TYPE_REF;
- sub_type->descriptor = 'l';
- sub_type->ref.ref = entry->type;
-
- return entry_ref_type;
-}
-
-// To be used for dyn_function parsing of return and parameter arrays
-dyn_type * dynAvprType_parseFromTypedJson(json_t * const root, json_t const * const type_entry, const char * namespace) {
- if (!type_entry) {
- LOG_ERROR("Need a type entry to parse, but got a NULL pointer");
- return NULL;
- }
-
- dyn_type * ret_type = NULL;
- enum JsonTypeType elType = dynAvprType_getType(type_entry);
- char name_buffer[FQN_SIZE];
- switch (elType) {
- case SIMPLE:
- // Check if it is an internal type
- ret_type = dynAvprType_createSimpleTypeFromName(NULL, json_string_value(type_entry));
- // Otherwise full parsing
- if (!ret_type) {
- dynAvprType_constructFqn(name_buffer, FQN_SIZE, json_string_value(type_entry), namespace);
- ret_type = dynAvprType_parseFromJson(root, name_buffer);
- }
- break;
-
- case ARRAY:
- ret_type = dynAvprType_parseArray(ret_type, NULL, type_entry, json_object_get(root, "types"), name_buffer, namespace, namespace);
- if (!ret_type) {
- LOG_ERROR("Error parsing array");
- return NULL;
- }
- break;
-
- case INVALID:
- /* fall through */
- case REFERENCE:
- /* fall through */
- default:
- LOG_ERROR("ParseFromTypedJson: Received illegal type : %d", elType);
- break;
- }
-
- return ret_type;
-}
-
-void dynAvprType_constructFqn(char *destination, size_t size, const char *possibleFqn, const char *ns) {
- const bool isAlreadyFqn = strchr(possibleFqn, '.') != NULL;
- snprintf(destination, size, "%s%s%s", isAlreadyFqn ? "" : ns, isAlreadyFqn ? "" : ".", possibleFqn);
-}
-
-static dyn_type * dynAvprType_parseAny(dyn_type * root, dyn_type * parent, json_t const * const jsonObject, json_t const * const array_object, const char * parent_ns) {
- dyn_type * type = NULL;
-
- if (!jsonObject) {
- LOG_ERROR("Any: Received NULL, type not found, nothing to parse");
- return NULL;
- }
-
- // Check if type has an alias and try to find associated
- const char* alias = json_string_value(json_object_get(jsonObject, "alias"));
- if (alias) {
- type = dynAvprType_createSimpleTypeFromName(parent, alias);
-
- if (type) {
- return type;
- }
-
- char buffer[FQN_SIZE];
- dynAvprType_constructFqn(buffer, FQN_SIZE, alias, parent_ns);
- type = dynAvprType_parseAny(root, parent, dynAvprType_findType(buffer, array_object, parent_ns), array_object, parent_ns);
- if (type) {
- return type;
- }
- }
-
- // No (valid) alias, build type based on name
- const char* type_name = json_string_value(json_object_get(jsonObject, "type"));
- if (!type_name) {
- LOG_ERROR("Any: \"type\" entry is not a string or does not exist");
- return NULL;
- }
-
- if (strcmp(type_name, "record") == 0) {
- type = dynAvprType_parseRecord(root, parent, jsonObject, array_object, parent_ns);
- }
- else if (strcmp(type_name, "fixed") == 0) {
- type = dynAvprType_parseFixed(parent, jsonObject, parent_ns);
- }
- else if (strcmp(type_name, "enum") == 0) {
- type = dynAvprType_parseEnum(parent, jsonObject, parent_ns);
- }
- else {
- type = dynAvprType_createSimpleTypeFromName(parent, type_name);
-
- if (!type) {
- LOG_ERROR("Any: Unrecognized type: %s", type_name);
- }
- }
-
- return type;
-}
-
-static dyn_type * dynAvprType_initializeType(dyn_type * parent) {
- dyn_type * type = calloc(1, sizeof(*type));
- TAILQ_INIT(&type->nestedTypesHead);
- TAILQ_INIT(&type->metaProperties);
- type->parent = parent;
- return type;
-}
-
-static dyn_type * dynAvprType_parseRecord(dyn_type * root, dyn_type * parent, json_t const * const record_obj, json_t const * const array_object, const char * parent_ns) {
- json_t const * fields = NULL;
- dyn_type * type = dynAvprType_prepareRecord(parent, &fields, record_obj); // also sets fields correctly
- if (!type) {
- return NULL;
- }
-
- // Check if namespace is present, otherwise set it equal to parent
- const char* record_ns = json_string_value(json_object_get(record_obj, "namespace"));
- if (!record_ns) {
- record_ns = parent_ns;
- }
-
- // Create namespace + name for storage in type->name (to preserve namespacing)
- char fqn_buffer[FQN_SIZE];
- snprintf(fqn_buffer, FQN_SIZE, "%s.%s", record_ns, json_string_value(json_object_get(record_obj, "name")));
- type->name = strdup(fqn_buffer);
- if (!type->name) {
- LOG_ERROR("Record: failed to allocate memory for type->name");
- dynType_destroy(type);
- return NULL;
- }
-
- // If root is NULL, this is the root type
- if (!root) {
- root = type;
- }
-
- // Loop over json_fields and parse each entry
- size_t counter;
- json_t *element;
- json_array_foreach(fields, counter, element) {
- struct complex_type_entry * entry = dynAvprType_parseRecordEntry(root, type, element, array_object, fqn_buffer, parent_ns, record_ns);
- if (!entry) {
- LOG_ERROR("Record: Parsing record entry %zu failed", counter);
- dynType_destroy(type);
- return NULL;
- }
-
- TAILQ_INSERT_TAIL(&type->complex.entriesHead, entry, entries);
- }
-
- return dynAvprType_finalizeRecord(type, counter) ? type : NULL;
-}
-
-// Initializes the type pointer with the correct information for a record (complex type)
-static inline dyn_type * dynAvprType_prepareRecord(dyn_type * parent, json_t const ** fields, json_t const * const record_obj) {
- const char * name = json_string_value(json_object_get(record_obj, "name"));
- if (!name) {
- LOG_ERROR("Record: \"name\" entry is missing");
- return NULL;
- }
-
- *fields = json_object_get(record_obj, "fields");
- if (!json_is_array(*fields)) {
- LOG_ERROR("Record: \"fields\" is not an array or does not exist");
- return NULL;
- }
-
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- type->type = DYN_TYPE_COMPLEX;
- type->descriptor = '{';
- type->ffiType = &type->complex.structType;
- type->complex.structType.type = FFI_TYPE_STRUCT;
- TAILQ_INIT(&type->complex.entriesHead);
- return type;
-}
-
-// Create the ffi types for quick access and link the dyn_types
-static inline bool dynAvprType_finalizeRecord(dyn_type * type, const size_t size) {
- type->complex.structType.elements = calloc(size+1, sizeof(ffi_type*));
- type->complex.structType.elements[size] = NULL;
- struct complex_type_entry *entry = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- type->complex.structType.elements[index++] = dynType_ffiType(entry->type);
- }
-
- // set types for every element for access
- index = 0;
- type->complex.types = calloc(size, sizeof(dyn_type*));
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- type->complex.types[index++] = entry->type;
- }
-
- dynType_prepCif(type->ffiType);
- return true;
-}
-
-static inline struct complex_type_entry *dynAvprType_parseRecordEntry(dyn_type *root, dyn_type *parent, json_t const *const entry_object, json_t const *const array_object, const char *fqn_parent, const char *parent_ns, const char *record_ns) {
- struct complex_type_entry *entry = dynAvprType_prepareRecordEntry(entry_object);
- if (!entry) {
- return NULL;
- }
-
- entry->type = dynAvprType_createSimpleTypeFromName(parent, json_string_value(json_object_get(entry_object, "type")));
-
- // If it was not a simple type, do full parsing
- if (!entry->type) {
- char name_buffer[FQN_SIZE];
- switch (dynAvprType_getRecordEntryType(entry_object, fqn_parent, name_buffer, record_ns)) {
- case SIMPLE:
- entry->type = dynAvprType_parseAny(root, parent, dynAvprType_findType(name_buffer, array_object, parent_ns), array_object, parent_ns);
- break;
-
- case REFERENCE:
- entry->type = dynAvprType_parseReference(root, name_buffer, array_object, parent_ns);
- break;
-
- case SELF_REFERENCE:
- entry->type = dynAvprType_parseSelfReference(parent);
- break;
-
- case ARRAY:
- entry->type = dynAvprType_parseArray(root, parent, json_object_get(entry_object, "type"), array_object, name_buffer, parent_ns, record_ns);
- break;
-
- case INVALID:
- /* fall through */
- default:
- LOG_ERROR("RecordEntry: Illegal record entry for %s", json_string_value(json_object_get(entry_object, "name")));
- entry->type = NULL;
- break;
- }
- }
-
- if (entry->type) {
- return entry;
- }
- else {
- LOG_ERROR("RecordEntry: Failed to create type for %s", json_string_value(json_object_get(entry_object, "type")));
- free(entry->name);
- free(entry);
- return NULL;
- }
-}
-
-static inline struct complex_type_entry *dynAvprType_prepareRecordEntry(json_t const *const entry_object) {
- struct complex_type_entry *entry = NULL;
-
- const char * entry_name = json_string_value(json_object_get(entry_object, "name"));
- if (!entry_name) {
- LOG_ERROR("Could not find name in entry");
- return NULL;
- }
-
- entry = calloc(1, sizeof(*entry));
- entry->name = strdup(entry_name);
- return entry;
-}
-
-// Returns correct type and sets the fqn in the buffer if it is a simple type (not for array because arrays can be nested
-static inline enum JsonTypeType dynAvprType_getRecordEntryType(json_t const * const entry_object, const char * fqn_parent, char * name_buffer, const char * namespace) {
- json_t const * const json_type = json_object_get(entry_object, "type");
- if (!json_type) {
- LOG_ERROR("RecordEntry: No type entry");
- return INVALID;
- }
-
- enum JsonTypeType elType = dynAvprType_getType(json_type);
- if (elType == SIMPLE) {
- dynAvprType_constructFqn(name_buffer, FQN_SIZE, json_string_value(json_type), namespace);
- if (strcmp(name_buffer, fqn_parent) == 0) {
- elType = SELF_REFERENCE;
- }
- else if (json_is_true(json_object_get(entry_object, "ptr"))) {
- elType = REFERENCE;
- }
- }
-
- return elType;
-}
-
-static dyn_type * dynAvprType_parseReference(dyn_type * root, const char * name_buffer, json_t const * const array_object, const char * parent_ns) {
- dyn_type * type = dynAvprType_initializeType(NULL);
- if (!type) {
- return NULL;
- }
-
- dyn_type *subType = dynAvprType_initializeReferenceType(type);
- if (!subType) {
- free(type);
- return NULL;
- }
-
- // First try to find if it already exists
- dyn_type *ref = dynType_findType(root, (char*) name_buffer);
- if (ref) {
- if (ref->type == DYN_TYPE_INVALID) {
- LOG_ERROR("Reference: found incomplete type");
- free(type);
- return NULL;
- }
- else {
- subType->ref.ref = ref;
- return type;
- }
- }
-
- // if not found, Generate the reference type in root
- json_t const * const refType = dynAvprType_findType(name_buffer, array_object, parent_ns);
- if (!refType) {
- LOG_ERROR("ParseReference: Could not find %s", name_buffer);
- free(subType);
- free(type);
- return NULL;
- }
-
- bool success = true;
- struct type_entry *entry = dynAvprType_prepareNestedEntry(root, name_buffer, true);
- dyn_type * tmp = entry->type;
-
- entry->type = dynAvprType_parseAny(root, NULL, refType, array_object, parent_ns);
- if (!entry->type) {
- free(entry);
- success = false;
- }
-
- free(tmp->name);
- free(tmp);
-
- if (success) {
- subType->ref.ref = entry->type;
- return type;
- }
- else {
- LOG_ERROR("ParseReference: Failed to add new type to root:");
- dynType_destroy(subType);
- dynType_destroy(type);
- return NULL;
- }
-}
-
-static dyn_type * dynAvprType_parseSelfReference(dyn_type * parent) {
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- dyn_type * sub_type = dynAvprType_initializeReferenceType(type);
- if (!sub_type) {
- free(type);
- return NULL;
- }
-
- sub_type->ref.ref = parent;
- return type;
-}
-
-// Assumes type_pointer is already present and alloc'd!
-static dyn_type * dynAvprType_initializeReferenceType(dyn_type * type_pointer) {
- type_pointer->type = DYN_TYPE_TYPED_POINTER;
- type_pointer->descriptor = '*';
- type_pointer->ffiType = &ffi_type_pointer;
-
- dyn_type *sub_type = dynAvprType_initializeType(type_pointer);
- if (!sub_type) {
- LOG_ERROR("Could not create reference type");
- return NULL;
- }
-
- type_pointer->typedPointer.typedType = sub_type;
- sub_type->type = DYN_TYPE_REF;
- sub_type->descriptor = 'l';
- return sub_type;
-
-}
-
-static inline struct type_entry * dynAvprType_prepareNestedEntry(dyn_type * const parent, const char * fqn, bool allocate) {
- struct type_entry *entry = calloc(1, sizeof(*entry));
- if (allocate) {
- entry->type = calloc(1, sizeof(*entry->type));
- entry->type->name = strdup(fqn);
-
- // Initialize information
- entry->type->parent = parent;
- entry->type->type = DYN_TYPE_INVALID;
- TAILQ_INIT(&entry->type->nestedTypesHead);
- TAILQ_INIT(&entry->type->metaProperties);
- }
-
- TAILQ_INSERT_TAIL(&parent->nestedTypesHead, entry, entries);
- return entry;
-}
-
-static dyn_type * dynAvprType_parseEnum(dyn_type * parent, json_t const * const enum_obj, const char * parent_ns) {
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- char * fqn = dynAvprType_createFqnFromJson(enum_obj, parent_ns);
- if (!fqn) {
- free(type);
- return NULL;
- }
-
- json_t * symbolArray = json_object_get(enum_obj, "symbols");
- if (!json_is_array(symbolArray)) {
- LOG_ERROR("Expected \"symbols\" to be an array for enum %s", fqn);
- free(fqn);
- free(type);
- return NULL;
- }
-
- json_t * values_array = json_object_get(enum_obj, "EnumValues");
- if (json_is_array(values_array) && json_array_size(values_array) != json_array_size(symbolArray)) {
- LOG_ERROR("Expected \"symbols\" and \"EnumValues\" arrays to be of the same size");
- free(fqn);
- free(type);
- return NULL;
- }
-
- const size_t max = json_array_size(symbolArray);
- bool valid = true;
- size_t counter = 0;
- json_t *enumeta_entry_ptr;
- for (; valid && counter < max && (enumeta_entry_ptr = json_array_get(symbolArray, counter)); counter++) {
- struct meta_entry * meta_entry_ptr = dynAvprType_createMetaEntry(json_string_value(enumeta_entry_ptr));
- if (meta_entry_ptr && dynAvprType_metaEntrySetValue(meta_entry_ptr, values_array, counter)) {
- TAILQ_INSERT_TAIL(&type->metaProperties, meta_entry_ptr, entries);
- }
- else {
- valid = false;
- }
- }
-
- if (valid) {
- type->name = fqn;
- type->type = DYN_TYPE_SIMPLE;
- type->descriptor = 'E';
- type->ffiType = &ffi_type_sint32;
- return type;
- }
- else {
- LOG_ERROR("ParseEnum: Failed to parse %s", fqn);
- free(fqn);
- dynType_destroy(type);
- return NULL;
- }
-}
-
-static inline struct meta_entry * dynAvprType_createMetaEntry(const char* enum_entry_name) {
- if (!enum_entry_name) {
- LOG_ERROR("CreateMetaEntry: passed null pointer, no name present?");
- return NULL;
- }
-
- struct meta_entry *entry = calloc(1, sizeof(*entry));
- entry->name = strdup(enum_entry_name);
- return entry;
-}
-
-static inline bool dynAvprType_metaEntrySetValue(struct meta_entry * meta_entry_ptr, json_t const * const values_array, size_t index) {
- if (!meta_entry_ptr) {
- return false;
- }
-
- if (values_array) {
- const char* enumValue = json_string_value(json_array_get(values_array, index));
- if (!enumValue) {
- LOG_ERROR("MetaEntrySetValue: could not get the enum value from the \"EnumValues\" list at index %zu", index);
- return false;
- }
-
- meta_entry_ptr->value = strdup(enumValue);
- if (!meta_entry_ptr->value) {
- LOG_ERROR("MetaEntrySetValue: could not allocate memory for meta_entry->value");
- return false;
- }
- dynAvprType_parseEnumValue(&meta_entry_ptr->value);
- }
- else {
- const size_t bufsize = sizeof(index) * CHAR_BIT + 1;
- meta_entry_ptr->value = calloc(bufsize, sizeof(char));
-
- snprintf(meta_entry_ptr->value, bufsize, "%zu", index);
- }
-
- return true;
-}
-
-static inline void dynAvprType_parseEnumValue(char** enumvalue) {
- char* str = *enumvalue;
- if (!str) {
- LOG_ERROR("Do not pass null pointer to this function");
- return;
- }
-
- // Remove whitespace
- int i, j = 0;
- for (i = 0; str[i] != '\0'; i++) {
- if (!isspace((unsigned char) str[i])) {
- str[j++] = str[i];
- }
- }
- str[j] = '\0';
-
- //create the substring if an equals sign is found
- char* equalssign = strrchr(str, '=');
- if (equalssign) {
- memmove(str, equalssign+1, strlen(equalssign-1));
- }
-}
-
-static ffi_type* seq_types[] = {&ffi_type_uint32, &ffi_type_uint32, &ffi_type_pointer, NULL};
-
-static dyn_type* dynAvprType_parseArray(dyn_type * root, dyn_type * parent, json_t const * const array_entry_obj, json_t const * const array_object, char * name_buffer, const char * parent_ns, const char * record_ns) {
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- type->type = DYN_TYPE_SEQUENCE;
- type->descriptor = '[';
-
- type->sequence.seqType.elements = seq_types;
- type->sequence.seqType.type = FFI_TYPE_STRUCT;
- type->sequence.seqType.size = 0;
- type->sequence.seqType.alignment = 0;
- type->sequence.itemType = NULL;
-
- json_t const * const itemsEntry = json_object_get(array_entry_obj, "items");
- if (json_is_object(itemsEntry)) { // is nested?
- json_t const * const nested_array_object = json_object_get(array_entry_obj, "items");
- type->sequence.itemType = dynAvprType_parseArray(root, type, nested_array_object, array_object, name_buffer, parent_ns, record_ns);
- }
- else if (json_is_string(itemsEntry)) { // is a named item?
- type->sequence.itemType = dynAvprType_createSimpleTypeFromName(type, json_string_value(itemsEntry));
- if (!type->sequence.itemType) {
- dynAvprType_constructFqn(name_buffer, FQN_SIZE, json_string_value(itemsEntry), record_ns);
- type->sequence.itemType = dynAvprType_parseAny(root, type, dynAvprType_findType(name_buffer, array_object, parent_ns), array_object, parent_ns);
- }
-
- }
- else {
- LOG_ERROR("ParseArray: Unrecognized array structure: \"items\" is neither a nested array nor a type");
- }
-
- if (type->sequence.itemType) {
- type->ffiType = &type->sequence.seqType;
- dynType_prepCif(&type->sequence.seqType);
- }
- else {
- LOG_ERROR("ParseArray: Failed to parse array item type");
- free(type);
- type = NULL;
- }
-
- return type;
-}
-
-static dyn_type * dynAvprType_parseFixed(dyn_type * parent, json_t const * const fixed_object, const char * parent_ns) {
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- ffi_type * ffiType = NULL;
- char descriptor = dynAvprType_fixedTypeToFfi(fixed_object, &ffiType);
-
- if (!ffiType || descriptor == '0') {
- LOG_ERROR("Invalid simple type, received wrong ffi type!");
- free(type);
- return NULL;
- }
-
- if (!json_is_string(json_object_get(fixed_object, "name"))) {
- LOG_ERROR("Invalid simple type, need a name");
- free(type);
- return NULL;
- }
-
- type->name = dynAvprType_createFqnFromJson(fixed_object, parent_ns);
- if (!type->name) {
- free(type);
- return NULL;
- }
-
- type->type = (descriptor == 't') ? DYN_TYPE_TEXT : DYN_TYPE_SIMPLE;
- type->descriptor = descriptor;
- type->ffiType = ffiType;
- return type;
-}
-
-static inline char dynAvprType_fixedTypeToFfi(json_t const * const simple_obj, ffi_type ** output_ffi_type) {
- const json_int_t size = json_integer_value(json_object_get(simple_obj, "size"));
- const bool sign = json_is_true(json_object_get(simple_obj, "signed"));
- const json_int_t s_size = sign ? size : -size;
-
- switch (s_size) {
- case 1:
- *output_ffi_type = &ffi_type_sint8;
- return 'B';
- case 2:
- *output_ffi_type = &ffi_type_sint16;
- return 'S';
- case 4:
- *output_ffi_type = &ffi_type_sint32;
- return 'I';
- case 8:
- *output_ffi_type = &ffi_type_sint64;
- return 'J';
- case -1:
- *output_ffi_type = &ffi_type_uint8;
- return 'b';
- case -2:
- *output_ffi_type = &ffi_type_uint16;
- return 's';
- case -4:
- *output_ffi_type = &ffi_type_uint32;
- return 'i';
- case -8:
- *output_ffi_type = &ffi_type_uint64;
- return 'j';
- default:
- LOG_ERROR("Unrecognized size = %lld", size);
- return '0';
- }
-}
-
-static dyn_type * dynAvprType_createSimpleTypeFromName(dyn_type * parent, const char * type_name) {
- dyn_type * type = NULL;
-
- if (!type_name) {
- LOG_ERROR("Simple Type, did not pass a valid name, returning NULL");
- }
- else if (strcmp(type_name, "int") == 0) {
- type = dynAvprType_createSimpleType(parent, 'I', "int");
- }
- else if (strcmp(type_name, "long") == 0) {
- type = dynAvprType_createSimpleType(parent, 'J', "long");
- }
- else if (strcmp(type_name, "string") == 0) {
- type = dynAvprType_createSimpleType(parent, 't', "string");
- }
- else if (strcmp(type_name, "boolean") == 0) {
- type = dynAvprType_createSimpleType(parent, 'Z', "boolean");
- }
- else if (strcmp(type_name, "float") == 0) {
- type = dynAvprType_createSimpleType(parent, 'F', "float");
- }
- else if (strcmp(type_name, "double") == 0) {
- type = dynAvprType_createSimpleType(parent, 'D', "double");
- }
- else if (strcmp(type_name, "null") == 0) {
- type = dynAvprType_createSimpleType(parent, 'V', "null");
- }
- else if (strcmp(type_name, "bytes") == 0) {
- type = dynAvprType_createSimpleType(parent, 'P', "bytes");
- }
- else if (strcmp(type_name, "void_ptr") == 0) {
- type = dynAvprType_createSimpleType(parent, 'P', "void_ptr");
- }
- else if (strcmp(type_name, "native_int") == 0) {
- type = dynAvprType_createSimpleType(parent, 'N', "native_int");
- }
-
- return type;
-}
-
-static dyn_type * dynAvprType_createSimpleType(dyn_type * parent, char kind, const char * name) {
- dyn_type * type = dynAvprType_initializeType(parent);
- if (!type) {
- return NULL;
- }
-
- ffi_type * ffiType = NULL;
- switch (kind) {
- case 'I':
- ffiType = &ffi_type_sint32;
- break;
- case 'J':
- ffiType = &ffi_type_sint64;
- break;
- case 't':
- ffiType = &ffi_type_pointer;
- break;
- case 'Z':
- ffiType = &ffi_type_uint8;
- break;
- case 'F':
- ffiType = &ffi_type_float;
- break;
- case 'D':
- ffiType = &ffi_type_double;
- break;
- case 'V':
- ffiType = &ffi_type_void;
- break;
- case 'P':
- ffiType = &ffi_type_pointer;
- break;
- case 'N':
- ffiType = &ffi_type_sint;
- break;
- default:
- LOG_ERROR("Unrecognized kind: '%c'.", kind);
- free(type);
- return NULL;
- }
-
- type->name = strdup(name);
- type->type = (kind == 't') ? DYN_TYPE_TEXT : DYN_TYPE_SIMPLE;
- type->descriptor = kind;
- type->ffiType = ffiType;
- return type;
-}
-
-static char * dynAvprType_createFqnFromJson(json_t const * const jsonObject, const char * namespace) {
- const char *name = json_string_value(json_object_get(jsonObject, "name"));
- if (!name) {
- LOG_ERROR("This object appears to not have a name!!");
- return NULL;
- }
-
- const bool local_ns = json_is_string(json_object_get(jsonObject, "namespace"));
- const char *ns = local_ns ? json_string_value(json_object_get(jsonObject, "namespace")) : namespace;
- if (!ns) {
- LOG_ERROR("Need a namespace because the jsonObject does not have a namespace!");
- return NULL;
- }
-
- // Create fqn
- const size_t length = strlen(ns) + strlen(name) + 2;
- char * fqn = calloc(length, sizeof(char));
-
- snprintf(fqn, length, "%s.%s", ns, name);
- return fqn;
-}
-
-static inline enum JsonTypeType dynAvprType_getType(json_t const * const json_type) {
- if (json_is_string(json_type)) {
- return SIMPLE; // Create type based on size (Could also be an internal type!)
- }
- else if (json_is_object(json_type) && json_is_string(json_object_get(json_type, "type")) && 0 == strcmp("array", json_string_value(json_object_get(json_type, "type")))) {
- return ARRAY;
- }
- else {
- return INVALID; // Not a legal type declaration
- }
-}
-
-static inline void dynAvprType_createVersionMetaEntry(dyn_type * type, json_t const * const root, json_t const * const array_object, const char* parent_ns) {
- struct meta_entry * m_entry = dynAvprType_createMetaEntry("version");
-
- json_t const * json_type_version = json_object_get(dynAvprType_findType(dynType_getName(type), array_object, parent_ns), "version");
-
- // If version is not available check root version
- if (!json_is_string(json_type_version)) {
- json_type_version = json_object_get(root, "version");
- }
-
- // If version is available use it (either from record or root)
- if (json_is_string(json_type_version)) {
- const char* version_str = json_string_value(json_type_version);
- // Check if a valid version was given
- celix_version_t* v = celix_version_createVersionFromString(version_str);
- if (v != NULL) {
- m_entry->value = strdup(version_str);
- celix_version_destroy(v);
- }
- else {
- m_entry->value = strdup("0.0.0");
- }
- }
- else {
- // If no version or an invalid version is available, default to 0.0.0
- m_entry->value = strdup("0.0.0");
- }
-
- // Insert into type
- TAILQ_INSERT_TAIL(&type->metaProperties, m_entry, entries);
-}
-
-static inline void dynAvprType_createAnnotationEntries(dyn_type * type, json_t const * const array_object, const char* parent_ns) {
- json_t const * json_type = dynAvprType_findType(dynType_getName(type), array_object, parent_ns);
- const char* const not_of_interest[5] = {"type", "name", "fields", "version", "alias"};
- const char* key;
- json_t const * value;
- json_object_foreach((json_t*)json_type, key, value) {
- if (! ( strcmp(key, not_of_interest[0]) == 0
- || strcmp(key, not_of_interest[1]) == 0
- || strcmp(key, not_of_interest[2]) == 0
- || strcmp(key, not_of_interest[3]) == 0
- || strcmp(key, not_of_interest[4]) == 0))
- {
- struct meta_entry * m_entry = dynAvprType_createMetaEntry(key);
-
- switch (json_typeof(value)) {
- case JSON_STRING:
- m_entry->value = strdup(json_string_value(value));
- break;
- case JSON_INTEGER:
- asprintf(&m_entry->value, "%" JSON_INTEGER_FORMAT, json_integer_value(value));
- break;
- case JSON_REAL:
- asprintf(&m_entry->value, "%f", json_real_value(value));
- break;
- case JSON_TRUE:
- m_entry->value = strdup("true");
- break;
- case JSON_FALSE:
- m_entry->value = strdup("false");
- break;
- case JSON_NULL:
- m_entry->value = strdup("null");
- break;
- case JSON_OBJECT:
- /* fall through */
- case JSON_ARRAY:
- /* fall through */
- default:
- free(m_entry->name);
- free(m_entry);
- continue; // Do not add the invalid entry as a meta-entry
- }
-
- TAILQ_INSERT_TAIL(&type->metaProperties, m_entry, entries);
- }
- }
-}
diff --git a/libs/dfi/src/dyn_interface.c b/libs/dfi/src/dyn_interface.c
index 9f702ce7..bad96335 100644
--- a/libs/dfi/src/dyn_interface.c
+++ b/libs/dfi/src/dyn_interface.c
@@ -31,7 +31,6 @@ DFI_SETUP_LOG(dynInterface);
static const int OK = 0;
static const int ERROR = 1;
-// Also export for dyn_avpr_interface
int dynInterface_checkInterface(dyn_interface_type *intf);
static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream);
diff --git a/libs/utils/src/properties.c b/libs/utils/src/properties.c
index 8d3a2dfa..24dcafd5 100644
--- a/libs/utils/src/properties.c
+++ b/libs/utils/src/properties.c
@@ -374,7 +374,6 @@ void celix_properties_destroy(celix_properties_t* props) {
celix_properties_t* celix_properties_load(const char* filename) {
FILE* file = fopen(filename, "r");
if (file == NULL) {
- celix_err_pushf("Cannot open file '%s'", filename);
return NULL;
}
celix_properties_t* props = celix_properties_loadWithStream(file);
diff --git a/rat-excludes.txt b/rat-excludes.txt
index ab72b018..a17bae1e 100644
--- a/rat-excludes.txt
+++ b/rat-excludes.txt
@@ -28,9 +28,6 @@ Doxyfile.in
Workaround to exclude .in files.
(.*).in
- Avpr files cannot have comments and as result no license info
-(.*).avpr
-
build/*
cmake-build-debug/*