-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb47eb9
commit d70ef4f
Showing
3 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |