Skip to content

Commit

Permalink
Add test for libgstc stats methods
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-guindon committed Jul 28, 2023
1 parent bb47eb9 commit d70ef4f
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/libgstc/c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ TESTS = \
libgstc_pipeline_get_state \
libgstc_pipeline_list_signals \
libgstc_pipeline_signal_connect \
libgstc_pipeline_signal_disconnect
libgstc_pipeline_signal_disconnect \
libgstc_enable_stats

check_PROGRAMS = $(TESTS)

Expand Down Expand Up @@ -175,3 +176,7 @@ libgstc_pipeline_list_signals_SOURCES = \
@top_srcdir@/libgstc/c/libgstc.c \
$(COMMON_SOURCES)

libgstc_stats_SOURCES = \
test_libgstc_stats.c \
@top_srcdir@/libgstc/c/libgstc.c \
$(COMMON_SOURCES)
1 change: 1 addition & 0 deletions tests/libgstc/c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib_gstc_tests = [
['test_libgstc_pipeline_list_signals.c'],
['test_libgstc_pipeline_signal_connect.c'],
['test_libgstc_pipeline_signal_disconnect.c'],
['test_libgstc_stats.c'],
]

# These are specials tests since is required to re-compile libgstc
Expand Down
172 changes: 172 additions & 0 deletions tests/libgstc/c/test_libgstc_stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* This file is part of GStreamer Daemon
* Copyright 2015-2023 Ridgerun, LLC (http://www.ridgerun.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <gst/check/gstcheck.h>
#include <string.h>

#include "libgstc.h"
#include "libgstc_json.h"
#include "libgstc_socket.h"
#include "libgstc_assert.h"

/* Test Fixture */
static gchar _request[512];
static GstClient *_client;

static void
setup (void)
{
const gchar *address = "";
unsigned int port = 0;
unsigned long wait_time = 5;
int keep_connection_open = 0;

gstc_client_new (address, port, wait_time, keep_connection_open, &_client);
}

static void
teardown (void)
{
gstc_client_free (_client);
}

/* Mock implementation of a socket */
typedef struct _GstcSocket
{
} GstcSocket;

GstcSocket _socket;

GstcStatus
gstc_socket_new (const char *address, const unsigned int port,
const int keep_connection_open, GstcSocket ** out)
{
*out = &_socket;

return GSTC_OK;
}

void
gstc_socket_free (GstcSocket * socket)
{
}

GstcStatus
gstc_socket_send (GstcSocket * socket, const gchar * request, gchar ** response,
const int timeout)
{
*response = malloc (1);

memcpy (_request, request, strlen (request));

return GSTC_OK;
}

GstcStatus
gstc_json_get_int (const gchar * json, const gchar * name, gint * out)
{
return *out = GSTC_OK;
}

GstcStatus
gstc_json_is_null (const gchar * json, const gchar * name, gint * out)
{
*out = 0;
return GSTC_OK;
}

GstcStatus
gstc_json_get_child_char_array (const char *json, const char *parent_name,
const char *array_name, const char *element_name, char **out[],
int *array_lenght)
{
return GSTC_OK;
}

GstcStatus
gstc_json_child_string (const char *json, const char *parent_name,
const char *data_name, char **out)
{
gstc_assert_and_ret_val (NULL != json, GSTC_NULL_ARGUMENT);
gstc_assert_and_ret_val (NULL != parent_name, GSTC_NULL_ARGUMENT);
gstc_assert_and_ret_val (NULL != data_name, GSTC_NULL_ARGUMENT);
gstc_assert_and_ret_val (NULL != out, GSTC_NULL_ARGUMENT);

return GSTC_OK;
}

GST_START_TEST (test_enable_stats)
{
GstcStatus ret;
const int true_int = 1;
const gchar *expected = "stats_enable true";

ret = gstc_enable_stats (_client, true_int);
assert_equals_int (GSTC_OK, ret);

assert_equals_string (expected, _request);
}

GST_END_TEST;

GST_START_TEST (test_disable_stats)
{
GstcStatus ret;
const int false_int = 0;
const gchar *expected = "stats_enable false";

ret = gstc_enable_stats (_client, false_int);
assert_equals_int (GSTC_OK, ret);

assert_equals_string (expected, _request);
}

GST_END_TEST;

GST_START_TEST (test_stats_get)
{
GstcStatus ret;
const gchar *expected = "stats_get";
gchar *response = NULL;

ret = gstc_get_stats (_client, &response);
assert_equals_int (GSTC_OK, ret);

assert_equals_string (expected, _request);
}

GST_END_TEST;

static Suite *
libgstc_stats_suite (void)
{
Suite *suite = suite_create ("libgstc_stats");
TCase *tc = tcase_create ("general");

suite_add_tcase (suite, tc);

tcase_add_checked_fixture (tc, setup, teardown);
tcase_add_test (tc, test_enable_stats);
tcase_add_test (tc, test_disable_stats);
tcase_add_test (tc, test_stats_get);

return suite;
}

GST_CHECK_MAIN (libgstc_stats);

0 comments on commit d70ef4f

Please sign in to comment.