From: Jaeyun Jung Date: Wed, 21 Aug 2024 07:45:37 +0000 (+0900) Subject: [Test] file name for test X-Git-Tag: accepted/tizen/unified/20240903.172453~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b7a5f3d907c6e9000660d9d4867953f7a2beb8d;p=platform%2Fupstream%2Fnnstreamer-edge.git [Test] file name for test Code clean, update file name for custom library test and fix indent. Signed-off-by: Jaeyun Jung --- diff --git a/include/nnstreamer-edge-custom.h b/include/nnstreamer-edge-custom.h index 5fee205..eee6504 100644 --- a/include/nnstreamer-edge-custom.h +++ b/include/nnstreamer-edge-custom.h @@ -20,7 +20,9 @@ extern "C" { #endif /* __cplusplus */ /** - * @brief NNStreamer Edge custom connection definition. This is used to define a custom connsction. The user should implement the functions and provide them using nns_edge_custom_get_instance(). Refer to the example in nnstreamer-edge-custom.c for more details. + * @brief NNStreamer Edge custom connection definition. This is used to define a custom connection. + * The user should implement the functions and provide them using nns_edge_custom_get_instance(). + * Refer to the example in nnstreamer-edge-custom-test.c for more details. */ typedef struct _NnsEdgeCustomDef { @@ -43,7 +45,6 @@ typedef struct _NnsEdgeCustomDef */ void* nns_edge_custom_get_instance (); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0d84476..5a919be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,17 +5,16 @@ TARGET_LINK_LIBRARIES(unittest_nnstreamer-edge ${TEST_REQUIRE_PKGS_LDFLAGS} ${NN INSTALL (TARGETS unittest_nnstreamer-edge DESTINATION ${BIN_INSTALL_DIR}) # Custom connection lib for unit test -SET(NNS_EDGE_CUSTOM_LIB_NAME nnstreamer-edge-custom-test) -SET(NNS_EDGE_CUSTOM_SRCS ${NNS_EDGE_SRCS} nnstreamer-edge-custom.c) -ADD_LIBRARY(${NNS_EDGE_CUSTOM_LIB_NAME} SHARED ${NNS_EDGE_CUSTOM_SRCS}) -SET_TARGET_PROPERTIES(${NNS_EDGE_CUSTOM_LIB_NAME} PROPERTIES VERSION ${SO_VERSION}) -TARGET_INCLUDE_DIRECTORIES(${NNS_EDGE_CUSTOM_LIB_NAME} PRIVATE ${EDGE_REQUIRE_PKGS_INCLUDE_DIRS} ${INCLUDE_DIR} ${NNS_EDGE_SRC_DIR}) -TARGET_LINK_LIBRARIES(${NNS_EDGE_CUSTOM_LIB_NAME} ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME}) -INSTALL (TARGETS ${NNS_EDGE_CUSTOM_LIB_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +SET(NNS_EDGE_CUSTOM_TEST_LIB_NAME nnstreamer-edge-custom-test) +SET(NNS_EDGE_CUSTOM_SRCS ${NNS_EDGE_SRCS} nnstreamer-edge-custom-test.c) +ADD_LIBRARY(${NNS_EDGE_CUSTOM_TEST_LIB_NAME} SHARED ${NNS_EDGE_CUSTOM_SRCS}) +TARGET_INCLUDE_DIRECTORIES(${NNS_EDGE_CUSTOM_TEST_LIB_NAME} PRIVATE ${EDGE_REQUIRE_PKGS_INCLUDE_DIRS} ${INCLUDE_DIR} ${NNS_EDGE_SRC_DIR}) +TARGET_LINK_LIBRARIES(${NNS_EDGE_CUSTOM_TEST_LIB_NAME} ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME}) +INSTALL (TARGETS ${NNS_EDGE_CUSTOM_TEST_LIB_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) ADD_EXECUTABLE(unittest_nnstreamer-edge-custom unittest_nnstreamer-edge-custom.cc) TARGET_INCLUDE_DIRECTORIES(unittest_nnstreamer-edge-custom PRIVATE ${EDGE_REQUIRE_PKGS_INCLUDE_DIRS} ${INCLUDE_DIR} ${NNS_EDGE_SRC_DIR}) -TARGET_LINK_LIBRARIES(unittest_nnstreamer-edge-custom ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME} ${NNS_EDGE_CUSTOM_LIB_NAME}) +TARGET_LINK_LIBRARIES(unittest_nnstreamer-edge-custom ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME} ${NNS_EDGE_CUSTOM_TEST_LIB_NAME}) INSTALL (TARGETS unittest_nnstreamer-edge-custom DESTINATION ${BIN_INSTALL_DIR}) # AITT test diff --git a/tests/nnstreamer-edge-custom-test.c b/tests/nnstreamer-edge-custom-test.c new file mode 100644 index 0000000..48f599f --- /dev/null +++ b/tests/nnstreamer-edge-custom-test.c @@ -0,0 +1,201 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2024 Gichan Jang + * + * @file nnstreamer-edge-custom-test.c + * @date 16 Aug 2024 + * @brief NNStreamer-edge custom connection for test. + * @see https://github.com/nnstreamer/nnstreamer-edge + * @author Gichan Jang + * @bug No known bugs except for NYI items + */ + +#include "nnstreamer-edge-custom.h" +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" +#include "nnstreamer-edge.h" + +typedef struct +{ + int is_connected; + char *peer_address; + nns_edge_event_cb event_cb; + void *user_data; +} nns_edge_custom_test_s; + +static int +nns_edge_custom_close (void *priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, priv should not be null."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + + SAFE_FREE (custom_h->peer_address); + SAFE_FREE (custom_h); + + return NNS_EDGE_ERROR_NONE; +} + +static const char * +nns_edge_custom_get_description () +{ + return "custom"; +} + +static int +nns_edge_custom_create (void **priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, handle should not be null."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) calloc (1, sizeof (nns_edge_custom_test_s)); + if (!custom_h) { + nns_edge_loge ("Failed to allocate memory for edge custom handle."); + return NNS_EDGE_ERROR_OUT_OF_MEMORY; + } + + *priv = custom_h; + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_start (void *priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, priv should not be null."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + custom_h->is_connected = 0; + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_stop (void *priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, priv should not be null."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + custom_h->is_connected = 0; + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_connect (void *priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, priv is NULL"); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + custom_h->is_connected = 1; + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_subscribe (void *priv) +{ + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} + +static int +nns_edge_custom_is_connected (void *priv) +{ + if (!priv) { + nns_edge_loge ("Invalid param, handle should not be null."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + + if (custom_h->is_connected == 1) + return NNS_EDGE_ERROR_NONE; + + return NNS_EDGE_ERROR_CONNECTION_FAILURE; +} + +static int +nns_edge_custom_set_event_cb (void *priv, nns_edge_event_cb cb, void *user_data) +{ + if (!priv || !cb) { + nns_edge_loge ("Invalid param, cb(%p)", cb); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_send_data (void *priv, nns_edge_data_h data_h) +{ + if (!priv || !data_h) { + nns_edge_loge ("Invalid param, data_h(%p)", data_h); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + + return NNS_EDGE_ERROR_NONE; +} + +static int +nns_edge_custom_set_option (void *priv, const char *key, const char *value) +{ + if (!priv || !key || !value) { + nns_edge_loge ("Invalid param, key(%s), value(%s)", key, value); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + + if (strcasecmp (key, "PEER_ADDRESS") == 0) { + SAFE_FREE (custom_h->peer_address); + custom_h->peer_address = nns_edge_strdup (value); + } else { + nns_edge_loge ("key(%s) does not supported.", key); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + + return NNS_EDGE_ERROR_NONE; +} + +static char * +nns_edge_custom_get_option (void *priv, const char *key) +{ + if (!priv || !key) { + nns_edge_loge ("Invalid param, key(%s)", key); + return NULL; + } + nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; + if (strcasecmp (key, "PEER_ADDRESS") == 0) + return nns_edge_strdup (custom_h->peer_address); + + return NULL; +} + +nns_edge_custom_s edge_custom_h = { + .nns_edge_custom_get_description = nns_edge_custom_get_description, + .nns_edge_custom_create = nns_edge_custom_create, + .nns_edge_custom_close = nns_edge_custom_close, + .nns_edge_custom_start = nns_edge_custom_start, + .nns_edge_custom_stop = nns_edge_custom_stop, + .nns_edge_custom_connect = nns_edge_custom_connect, + .nns_edge_custom_subscribe = nns_edge_custom_subscribe, + .nns_edge_custom_is_connected = nns_edge_custom_is_connected, + .nns_edge_custom_set_event_cb = nns_edge_custom_set_event_cb, + .nns_edge_custom_send_data = nns_edge_custom_send_data, + .nns_edge_custom_set_option = nns_edge_custom_set_option, + .nns_edge_custom_get_option = nns_edge_custom_get_option +}; + +void * +nns_edge_custom_get_instance () +{ + return &edge_custom_h; +} diff --git a/tests/nnstreamer-edge-custom.c b/tests/nnstreamer-edge-custom.c deleted file mode 100644 index 7dc6586..0000000 --- a/tests/nnstreamer-edge-custom.c +++ /dev/null @@ -1,201 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/** - * Copyright (C) 2024 Gichan Jang - * - * @file nnstreamer-edge-custom.c - * @date 16 Aug 2024 - * @brief NNStreamer-edge custom connection for test. - * @see https://github.com/nnstreamer/nnstreamer-edge - * @author Gichan Jang - * @bug No known bugs except for NYI items - */ - -#include "nnstreamer-edge-custom.h" -#include "nnstreamer-edge-log.h" -#include "nnstreamer-edge-util.h" -#include "nnstreamer-edge.h" - -typedef struct -{ - int is_connected; - char *peer_address; - nns_edge_event_cb event_cb; - void *user_data; -} nns_edge_custom_test_s; - -static int -nns_edge_custom_close (void *priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, priv should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - - SAFE_FREE (custom_h->peer_address); - SAFE_FREE (custom_h); - - return NNS_EDGE_ERROR_NONE; -} - -static const char * -nns_edge_custom_get_description () -{ - return "custom"; -} - -static int -nns_edge_custom_create (void **priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, handle should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) calloc (1, sizeof (nns_edge_custom_test_s)); - if (!custom_h) { - nns_edge_loge ("Failed to allocate memory for edge custom handle."); - return NNS_EDGE_ERROR_OUT_OF_MEMORY; - } - - *priv = custom_h; - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_start (void *priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, priv should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - custom_h->is_connected = 0; - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_stop (void *priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, priv should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - custom_h->is_connected = 0; - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_connect (void *priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, priv is NULL"); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - custom_h->is_connected = 1; - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_subscribe (void *priv) -{ - return NNS_EDGE_ERROR_NOT_SUPPORTED; -} - -static int -nns_edge_custom_is_connected (void *priv) -{ - if (!priv) { - nns_edge_loge ("Invalid param, handle should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - - if (custom_h->is_connected == 1) - return NNS_EDGE_ERROR_NONE; - - return NNS_EDGE_ERROR_CONNECTION_FAILURE; -} - -static int -nns_edge_custom_set_event_cb (void *priv, nns_edge_event_cb cb, void *user_data) -{ - if (!priv || !cb) { - nns_edge_loge ("Invalid param, cb(%p)", cb); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_send_data (void *priv, nns_edge_data_h data_h) -{ - if (!priv || !data_h) { - nns_edge_loge ("Invalid param, data_h(%p)", data_h); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - return NNS_EDGE_ERROR_NONE; -} - -static int -nns_edge_custom_set_option (void *priv, const char *key, const char *value) -{ - if (!priv || !key || !value) { - nns_edge_loge ("Invalid param, key(%s), value(%s)", key, value); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - - if (strcasecmp (key, "PEER_ADDRESS") == 0) { - SAFE_FREE (custom_h->peer_address); - custom_h->peer_address = nns_edge_strdup (value); - } else { - nns_edge_loge ("key(%s) does not supported.", key); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - return NNS_EDGE_ERROR_NONE; -} - -static char * -nns_edge_custom_get_option (void *priv, const char *key) -{ - if (!priv || !key) { - nns_edge_loge ("Invalid param, key(%s)", key); - return NULL; - } - nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv; - if (strcasecmp (key, "PEER_ADDRESS") == 0) - return nns_edge_strdup (custom_h->peer_address); - - return NULL; -} - -nns_edge_custom_s edge_custom_h = { - .nns_edge_custom_get_description = nns_edge_custom_get_description, - .nns_edge_custom_create = nns_edge_custom_create, - .nns_edge_custom_close = nns_edge_custom_close, - .nns_edge_custom_start = nns_edge_custom_start, - .nns_edge_custom_stop = nns_edge_custom_stop, - .nns_edge_custom_connect = nns_edge_custom_connect, - .nns_edge_custom_subscribe = nns_edge_custom_subscribe, - .nns_edge_custom_is_connected = nns_edge_custom_is_connected, - .nns_edge_custom_set_event_cb = nns_edge_custom_set_event_cb, - .nns_edge_custom_send_data = nns_edge_custom_send_data, - .nns_edge_custom_set_option = nns_edge_custom_set_option, - .nns_edge_custom_get_option = nns_edge_custom_get_option -}; - -void * -nns_edge_custom_get_instance () -{ - return &edge_custom_h; -} diff --git a/tests/unittest_nnstreamer-edge.cc b/tests/unittest_nnstreamer-edge.cc index 1461b1a..e9d252c 100644 --- a/tests/unittest_nnstreamer-edge.cc +++ b/tests/unittest_nnstreamer-edge.cc @@ -2082,7 +2082,6 @@ TEST(edgeData, deserializeInvalidParam04_n) SAFE_FREE (data); } - /** * @brief Serialize and deserialize the edge-data. */ @@ -2164,7 +2163,6 @@ TEST(edgeDataSerialize, normal) SAFE_FREE (serialized_data); } - /** * @brief Serialize edge-data - invalid param. */