Discussion:
[Spice-devel] [PATCH spice-server] tests: Use g_assert_(non)null instead of g_assert
Frediano Ziglio
2018-12-03 17:09:55 UTC
Permalink
Just a style change, on more recent GLib would print a more
friendly error report.

Signed-off-by: Frediano Ziglio <***@redhat.com>
---
server/tests/test-display-base.c | 2 +-
server/tests/test-listen.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index e9f6c54d..3ca85f3a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -943,7 +943,7 @@ Test* test_new(SpiceCoreInterface* core)
spice_server_destroy(server);
}

- g_assert(test->server != NULL);
+ g_assert_nonnull(test->server);

printf("TESTER: listening on port %d (unsecure)\n", port);
g_test_log_set_fatal_handler(NULL, NULL);
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index d355b471..640e8f12 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -29,6 +29,8 @@
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>

+#include "test-glib-compat.h"
+
/* Arbitrary base port, we want a port which is not in use by the system, and
* by another of our tests (in case of parallel runs)
*/
@@ -189,8 +191,8 @@ static gpointer check_no_connect_thread(gpointer data)
GIOStream *stream;

stream = fake_client_connect(connectable, &error);
- g_assert(error != NULL);
- g_assert(stream == NULL);
+ g_assert_nonnull(error);
+ g_assert_null(stream);
g_clear_error(&error);

g_object_unref(connectable);
--
2.17.2
Uri Lublin
2018-12-03 23:02:52 UTC
Permalink
Post by Frediano Ziglio
Just a style change, on more recent GLib would print a more
friendly error report.
Ack.

Documentation mentions these macros should only be used in
tests and the patch indeed only touches tests.

https://developer.gnome.org/glib/unstable/glib-Testing.html#g-assert-nonnull

Uri.
Post by Frediano Ziglio
---
server/tests/test-display-base.c | 2 +-
server/tests/test-listen.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index e9f6c54d..3ca85f3a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -943,7 +943,7 @@ Test* test_new(SpiceCoreInterface* core)
spice_server_destroy(server);
}
- g_assert(test->server != NULL);
+ g_assert_nonnull(test->server);
printf("TESTER: listening on port %d (unsecure)\n", port);
g_test_log_set_fatal_handler(NULL, NULL);
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index d355b471..640e8f12 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -29,6 +29,8 @@
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>
+#include "test-glib-compat.h"
+
/* Arbitrary base port, we want a port which is not in use by the system, and
* by another of our tests (in case of parallel runs)
*/
@@ -189,8 +191,8 @@ static gpointer check_no_connect_thread(gpointer data)
GIOStream *stream;
stream = fake_client_connect(connectable, &error);
- g_assert(error != NULL);
- g_assert(stream == NULL);
+ g_assert_nonnull(error);
+ g_assert_null(stream);
g_clear_error(&error);
g_object_unref(connectable);
Victor Toso
2018-12-04 08:49:46 UTC
Permalink
Hi,
Post by Frediano Ziglio
Just a style change, on more recent GLib would print a more
friendly error report.
---
server/tests/test-display-base.c | 2 +-
server/tests/test-listen.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index e9f6c54d..3ca85f3a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -943,7 +943,7 @@ Test* test_new(SpiceCoreInterface* core)
spice_server_destroy(server);
}
- g_assert(test->server != NULL);
+ g_assert_nonnull(test->server);
defined at glib 2.40 while we require 2.32
Post by Frediano Ziglio
printf("TESTER: listening on port %d (unsecure)\n", port);
g_test_log_set_fatal_handler(NULL, NULL);
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index d355b471..640e8f12 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -29,6 +29,8 @@
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>
+#include "test-glib-compat.h"
+
/* Arbitrary base port, we want a port which is not in use by the system, and
* by another of our tests (in case of parallel runs)
*/
@@ -189,8 +191,8 @@ static gpointer check_no_connect_thread(gpointer data)
GIOStream *stream;
stream = fake_client_connect(connectable, &error);
- g_assert(error != NULL);
- g_assert(stream == NULL);
+ g_assert_nonnull(error);
+ g_assert_null(stream);
this is closer, defined at glib 2.38 while we require 2.32
Post by Frediano Ziglio
g_clear_error(&error);
g_object_unref(connectable);
--
2.17.2
_______________________________________________
Spice-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/spice-devel
Frediano Ziglio
2018-12-04 08:58:07 UTC
Permalink
Post by Victor Toso
Hi,
Post by Frediano Ziglio
Just a style change, on more recent GLib would print a more
friendly error report.
---
server/tests/test-display-base.c | 2 +-
server/tests/test-listen.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/server/tests/test-display-base.c
b/server/tests/test-display-base.c
index e9f6c54d..3ca85f3a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -943,7 +943,7 @@ Test* test_new(SpiceCoreInterface* core)
spice_server_destroy(server);
}
- g_assert(test->server != NULL);
+ g_assert_nonnull(test->server);
defined at glib 2.40 while we require 2.32
That's why I make sure our compatibility header is included :-)
Post by Victor Toso
Post by Frediano Ziglio
printf("TESTER: listening on port %d (unsecure)\n", port);
g_test_log_set_fatal_handler(NULL, NULL);
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index d355b471..640e8f12 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -29,6 +29,8 @@
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>
+#include "test-glib-compat.h"
+
/* Arbitrary base port, we want a port which is not in use by the system, and
* by another of our tests (in case of parallel runs)
*/
@@ -189,8 +191,8 @@ static gpointer check_no_connect_thread(gpointer data)
GIOStream *stream;
stream = fake_client_connect(connectable, &error);
- g_assert(error != NULL);
- g_assert(stream == NULL);
+ g_assert_nonnull(error);
+ g_assert_null(stream);
this is closer, defined at glib 2.38 while we require 2.32
same
Post by Victor Toso
Post by Frediano Ziglio
g_clear_error(&error);
g_object_unref(connectable);
Frediano
Victor Toso
2018-12-04 09:02:09 UTC
Permalink
Hi,
Post by Frediano Ziglio
Post by Victor Toso
Hi,
Post by Frediano Ziglio
Just a style change, on more recent GLib would print a more
friendly error report.
---
server/tests/test-display-base.c | 2 +-
server/tests/test-listen.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/server/tests/test-display-base.c
b/server/tests/test-display-base.c
index e9f6c54d..3ca85f3a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -943,7 +943,7 @@ Test* test_new(SpiceCoreInterface* core)
spice_server_destroy(server);
}
- g_assert(test->server != NULL);
+ g_assert_nonnull(test->server);
defined at glib 2.40 while we require 2.32
That's why I make sure our compatibility header is included :-)
Post by Victor Toso
Post by Frediano Ziglio
printf("TESTER: listening on port %d (unsecure)\n", port);
g_test_log_set_fatal_handler(NULL, NULL);
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index d355b471..640e8f12 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -29,6 +29,8 @@
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>
+#include "test-glib-compat.h"
+
:)

Missed. I doubled checked, should be fine indeed
Post by Frediano Ziglio
Post by Victor Toso
Post by Frediano Ziglio
/* Arbitrary base port, we want a port which is not in use by the system, and
* by another of our tests (in case of parallel runs)
*/
@@ -189,8 +191,8 @@ static gpointer check_no_connect_thread(gpointer data)
GIOStream *stream;
stream = fake_client_connect(connectable, &error);
- g_assert(error != NULL);
- g_assert(stream == NULL);
+ g_assert_nonnull(error);
+ g_assert_null(stream);
this is closer, defined at glib 2.38 while we require 2.32
same
Post by Victor Toso
Post by Frediano Ziglio
g_clear_error(&error);
g_object_unref(connectable);
Frediano
Loading...