[Spice-commits] 2 commits - server/reds.c server/tests
Frediano Ziglio
fziglio at kemper.freedesktop.org
Thu Nov 17 11:14:25 UTC 2016
server/reds.c | 2
server/tests/Makefile.am | 1
server/tests/spice-codecs-parsing-test.c | 131 +++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+)
New commits:
commit 39b6b65421a5b9dbb8517d7b997678e204ae9ae7
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Wed Nov 16 16:20:44 2016 +0100
Do not crash on NULL codecs
Reviewed-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
diff --git a/server/reds.c b/server/reds.c
index dd173d9..92feea1 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3532,6 +3532,8 @@ static void reds_set_video_codecs(RedsState *reds, const char *codecs)
{
char *encoder_name, *codec_name;
+ g_return_if_fail(codecs != NULL);
+
if (strcmp(codecs, "auto") == 0) {
codecs = default_video_codecs;
}
diff --git a/server/tests/spice-codecs-parsing-test.c b/server/tests/spice-codecs-parsing-test.c
index 9db321d..0e23553 100644
--- a/server/tests/spice-codecs-parsing-test.c
+++ b/server/tests/spice-codecs-parsing-test.c
@@ -59,33 +59,46 @@ static void codecs_bad(void)
guint i;
const struct {
const gchar *codecs;
+ const GLogLevelFlags log_level;
const gchar *error_message;
} test_cases[] = {
{
+ NULL,
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 'codecs != NULL' failed"
+ },{
";:;",
+ G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
},{
"::::",
+ G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
},{
"missingcolon",
+ G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
},{
":missing_encoder",
+ G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
},{
"missing_value:;",
+ G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
},{
"unknown_encoder:mjpeg",
+ G_LOG_LEVEL_WARNING,
"*spice: unknown video encoder unknown_encoder",
},{
"spice:unknown_codec",
+ G_LOG_LEVEL_WARNING,
"*spice: unknown video codec unknown_codec",
},
#if !defined(HAVE_GSTREAMER_1_0) && !defined(HAVE_GSTREAMER_0_10)
{
"gstreamer:mjpeg",
+ G_LOG_LEVEL_WARNING,
"*spice: unsupported video encoder gstreamer",
}
#endif
@@ -96,7 +109,7 @@ static void codecs_bad(void)
g_assert_nonnull(server);
for (i = 0; i < G_N_ELEMENTS(test_cases); ++i) {
- g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, test_cases[i].error_message);
+ g_test_expect_message(G_LOG_DOMAIN, test_cases[i].log_level, test_cases[i].error_message);
g_assert_cmpint(spice_server_set_video_codecs(server, test_cases[i].codecs), ==, 0);
g_test_assert_expected_messages();
}
commit 5c311ea8a1bf37055a93fe49504273d92b1a4d0f
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Wed Nov 16 16:20:43 2016 +0100
Add test for codecs parsing
With Glib2.34 test invalid codec strings
Reviewed-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 8351253..626cd81 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -37,6 +37,7 @@ LDADD = \
$(NULL)
check_PROGRAMS = \
+ spice-codecs-parsing-test \
spice-options-test \
stat_test \
stream-test \
diff --git a/server/tests/spice-codecs-parsing-test.c b/server/tests/spice-codecs-parsing-test.c
new file mode 100644
index 0000000..9db321d
--- /dev/null
+++ b/server/tests/spice-codecs-parsing-test.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2016 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+#include <glib.h>
+#include <spice.h>
+
+/* GLIB_CHECK_VERSION(2, 40, 0) */
+#ifndef g_assert_nonnull
+#define g_assert_nonnull g_assert
+#endif
+
+static void codecs_good(void)
+{
+ guint i;
+ const gchar *codecs[] = {
+ "",
+ ";",
+ ";;;;",
+ "spice:mjpeg",
+ "spice:mjpeg;;;",
+ "spice:mjpeg;;spice:mjpeg;;;",
+ ";;spice:mjpeg;;spice:mjpeg;;;",
+#if defined(HAVE_GSTREAMER_1_0) || defined(HAVE_GSTREAMER_0_10)
+ "gstreamer:mjpeg;gstreamer:h264;gstreamer:vp8;",
+ ";;spice:mjpeg;;gstreamer:mjpeg;gstreamer:h264;gstreamer:vp8;",
+#endif
+ };
+
+ SpiceServer *server = spice_server_new();
+
+ g_assert_nonnull(server);
+
+ for (i = 0; i < G_N_ELEMENTS(codecs); ++i) {
+ g_assert_cmpint(spice_server_set_video_codecs(server, codecs[i]), ==, 0);
+ }
+
+ spice_server_destroy(server);
+}
+
+/* g_test_expect_message is available since Glib 2.34 */
+#if GLIB_CHECK_VERSION(2, 34, 0)
+static void codecs_bad(void)
+{
+ guint i;
+ const struct {
+ const gchar *codecs;
+ const gchar *error_message;
+ } test_cases[] = {
+ {
+ ";:;",
+ "*spice: invalid encoder:codec value*",
+ },{
+ "::::",
+ "*spice: invalid encoder:codec value*",
+ },{
+ "missingcolon",
+ "*spice: invalid encoder:codec value*",
+ },{
+ ":missing_encoder",
+ "*spice: invalid encoder:codec value*",
+ },{
+ "missing_value:;",
+ "*spice: invalid encoder:codec value*",
+ },{
+ "unknown_encoder:mjpeg",
+ "*spice: unknown video encoder unknown_encoder",
+ },{
+ "spice:unknown_codec",
+ "*spice: unknown video codec unknown_codec",
+ },
+#if !defined(HAVE_GSTREAMER_1_0) && !defined(HAVE_GSTREAMER_0_10)
+ {
+ "gstreamer:mjpeg",
+ "*spice: unsupported video encoder gstreamer",
+ }
+#endif
+ };
+
+ SpiceServer *server = spice_server_new();
+
+ g_assert_nonnull(server);
+
+ for (i = 0; i < G_N_ELEMENTS(test_cases); ++i) {
+ g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, test_cases[i].error_message);
+ g_assert_cmpint(spice_server_set_video_codecs(server, test_cases[i].codecs), ==, 0);
+ g_test_assert_expected_messages();
+ }
+
+ spice_server_destroy(server);
+}
+#endif
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/server/codecs-good", codecs_good);
+#if GLIB_CHECK_VERSION(2, 34, 0)
+ g_test_add_func("/server/codecs-bad", codecs_bad);
+#endif
+
+ return g_test_run();
+}
More information about the Spice-commits
mailing list