summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2016-10-12 16:26:30 +0900
committerChristoph Lipka <clipka@jp.adit-jv.com>2016-10-24 13:39:56 +0900
commit28812dda5db637a12366a672272e8a498180c5f7 (patch)
treef6c39e126e18543218dc0419237c6f3d83e255ba /src
parentcce8103616694d46d53df581e1378dd13e25b347 (diff)
downloadDLT-daemon-28812dda5db637a12366a672272e8a498180c5f7.tar.gz
Unit Test: Event handling
Unit tests for DLT Daemon connection and event handling Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/dlt_daemon_connection.c6
-rw-r--r--src/daemon/dlt_daemon_connection.h12
-rw-r--r--src/daemon/dlt_daemon_event_handler.c24
-rw-r--r--src/daemon/dlt_daemon_event_handler.h7
4 files changed, 43 insertions, 6 deletions
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 755e76a..51f975d 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -61,7 +61,7 @@
* @return The amount of bytes send on success, -1 otherwise.
* errno is appropriately set.
*/
-static int dlt_connection_send(DltConnection *conn,
+STATIC int dlt_connection_send(DltConnection *conn,
void *msg,
size_t msg_size)
{
@@ -158,7 +158,7 @@ DltConnection *dlt_connection_get_next(DltConnection *current, int type_mask)
return current;
}
-static void dlt_connection_destroy_receiver(DltConnection *con)
+STATIC void dlt_connection_destroy_receiver(DltConnection *con)
{
if (!con)
return;
@@ -189,7 +189,7 @@ static void dlt_connection_destroy_receiver(DltConnection *con)
*
* @return DltReceiver structure or NULL if none corresponds to the type.
*/
-static DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
+STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
DltConnectionType type,
int fd)
{
diff --git a/src/daemon/dlt_daemon_connection.h b/src/daemon/dlt_daemon_connection.h
index aa21a11..00759c6 100644
--- a/src/daemon/dlt_daemon_connection.h
+++ b/src/daemon/dlt_daemon_connection.h
@@ -48,4 +48,16 @@ void dlt_connection_destroy(DltConnection *);
void *dlt_connection_get_callback(DltConnection *);
+#ifdef DLT_UNIT_TESTS
+int dlt_connection_send(DltConnection *conn,
+ void *msg,
+ size_t msg_size);
+
+void dlt_connection_destroy_receiver(DltConnection *con);
+
+DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
+ DltConnectionType type,
+ int fd);
+#endif
+
#endif /* DLT_DAEMON_CONNECTION_H */
diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c
index 80817a4..9ee3bc1 100644
--- a/src/daemon/dlt_daemon_event_handler.c
+++ b/src/daemon/dlt_daemon_event_handler.c
@@ -61,6 +61,10 @@
*/
int dlt_daemon_prepare_event_handling(DltEventHandler *ev)
{
+ if (ev == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
ev->epfd = epoll_create(DLT_EPOLL_MAX_EVENTS);
if (ev->epfd < 0)
@@ -88,6 +92,10 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
DltDaemon *daemon,
DltDaemonLocal *daemon_local)
{
+ if ((pEvent == NULL) || (daemon == NULL) || (daemon_local == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
int nfds = 0;
int i = 0;
char str[DLT_DAEMON_TEXTBUFSIZE];
@@ -187,6 +195,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev,
int fd)
{
+
DltConnection *temp = ev->connections;
while ((temp != NULL) && (temp->receiver->fd != fd))
@@ -207,9 +216,13 @@ DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev,
*
* @return 0 on success, -1 if the connection is not found.
*/
-static int dlt_daemon_remove_connection(DltEventHandler *ev,
+STATIC int dlt_daemon_remove_connection(DltEventHandler *ev,
DltConnection *to_remove)
{
+ if (ev == NULL || to_remove == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
DltConnection **curr = &ev->connections;
/* Find the address where to_remove value is registered */
@@ -262,16 +275,16 @@ void dlt_event_handler_cleanup_connections(DltEventHandler *ev)
* @param ev The event handler structure where the connection list is.
* @param connection The connection to be added.
*/
-static void dlt_daemon_add_connection(DltEventHandler *ev,
+STATIC void dlt_daemon_add_connection(DltEventHandler *ev,
DltConnection *connection)
{
+
DltConnection **temp = &ev->connections;
while (*temp != NULL)
{
temp = &(*temp)->next;
}
-
*temp = connection;
}
@@ -429,6 +442,11 @@ int dlt_event_handler_unregister_connection(DltEventHandler *evhdl,
DltDaemonLocal *daemon_local,
int fd)
{
+ if (evhdl == NULL || daemon_local == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
+
/* Look for the pointer in the client list.
* There shall be only one event handler with the same fd.
*/
diff --git a/src/daemon/dlt_daemon_event_handler.h b/src/daemon/dlt_daemon_event_handler.h
index 532cd1f..ea88da9 100644
--- a/src/daemon/dlt_daemon_event_handler.h
+++ b/src/daemon/dlt_daemon_event_handler.h
@@ -56,4 +56,11 @@ int dlt_event_handler_unregister_connection(DltEventHandler *,
int dlt_connection_check_activate(DltEventHandler *,
DltConnection *,
int);
+#ifdef DLT_UNIT_TESTS
+int dlt_daemon_remove_connection(DltEventHandler *ev,
+ DltConnection *to_remove);
+
+void dlt_daemon_add_connection(DltEventHandler *ev,
+ DltConnection *connection);
+#endif
#endif /* DLT_DAEMON_EVENT_HANDLER_H */