[glib-networking] Review use of g_assert() in tests
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking] Review use of g_assert() in tests
- Date: Thu, 22 Mar 2018 21:49:13 +0000 (UTC)
commit 345a16f65d4435395b2b69ff115507d58e61de71
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Mon Feb 26 14:07:21 2018 -0600
Review use of g_assert() in tests
Let's use the special testing macros instead.
https://bugzilla.gnome.org/show_bug.cgi?id=793856
tls/tests/certificate.c | 94 ++++++++++++++--------------
tls/tests/connection.c | 144 +++++++++++++++++++++---------------------
tls/tests/dtls-connection.c | 4 +-
tls/tests/file-database.c | 68 ++++++++++----------
4 files changed, 155 insertions(+), 155 deletions(-)
---
diff --git a/tls/tests/certificate.c b/tls/tests/certificate.c
index 6537a36..69dfff1 100644
--- a/tls/tests/certificate.c
+++ b/tls/tests/certificate.c
@@ -119,7 +119,7 @@ test_create_pem (TestCertificate *test,
cert = g_tls_certificate_new_from_pem (test->cert_pem, test->cert_pem_length, &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
g_object_get (cert, "certificate-pem", &pem, NULL);
g_assert_cmpstr (pem, ==, test->cert_pem);
@@ -127,7 +127,7 @@ test_create_pem (TestCertificate *test,
g_object_add_weak_pointer (G_OBJECT (cert), (gpointer *)&cert);
g_object_unref (cert);
- g_assert (cert == NULL);
+ g_assert_null (cert);
}
static void
@@ -142,11 +142,11 @@ test_create_with_key_pem (TestCertificate *test,
"private-key-pem", test->key_pem,
NULL);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
g_object_add_weak_pointer (G_OBJECT (cert), (gpointer *)&cert);
g_object_unref (cert);
- g_assert (cert == NULL);
+ g_assert_null (cert);
}
static void
@@ -161,18 +161,18 @@ test_create_der (TestCertificate *test,
"certificate", test->cert_der,
NULL);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
g_object_get (cert, "certificate", &der, NULL);
- g_assert (der);
+ g_assert_nonnull (der);
g_assert_cmpuint (der->len, ==, test->cert_der->len);
- g_assert (memcmp (der->data, test->cert_der->data, der->len) == 0);
+ g_assert_cmpint (memcmp (der->data, test->cert_der->data, der->len), ==, 0);
g_byte_array_unref (der);
g_object_add_weak_pointer (G_OBJECT (cert), (gpointer *)&cert);
g_object_unref (cert);
- g_assert (cert == NULL);
+ g_assert_null (cert);
}
static void
@@ -187,11 +187,11 @@ test_create_with_key_der (TestCertificate *test,
"private-key", test->key_der,
NULL);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
g_object_add_weak_pointer (G_OBJECT (cert), (gpointer *)&cert);
g_object_unref (cert);
- g_assert (cert == NULL);
+ g_assert_null (cert);
}
static void
@@ -203,26 +203,26 @@ test_create_certificate_with_issuer (TestCertificate *test,
issuer = g_tls_certificate_new_from_file (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (issuer));
+ g_assert_true (G_IS_TLS_CERTIFICATE (issuer));
cert = g_initable_new (test->cert_gtype, NULL, &error,
"certificate-pem", test->cert_pem,
"issuer", issuer,
NULL);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
g_object_add_weak_pointer (G_OBJECT (issuer), (gpointer *)&issuer);
g_object_unref (issuer);
- g_assert (issuer != NULL);
+ g_assert_nonnull (issuer);
check = g_tls_certificate_get_issuer (cert);
- g_assert (check == issuer);
+ g_assert_true (check == issuer);
g_object_add_weak_pointer (G_OBJECT (cert), (gpointer *)&cert);
g_object_unref (cert);
- g_assert (cert == NULL);
- g_assert (issuer == NULL);
+ g_assert_null (cert);
+ g_assert_null (issuer);
}
static void
@@ -233,12 +233,12 @@ test_create_certificate_with_garbage_input (TestCertificate *test,
GError *error = NULL;
cert = g_tls_certificate_new_from_file (tls_test_file_path ("garbage.pem"), &error);
- g_assert (cert == NULL);
+ g_assert_null (cert);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
cert = g_tls_certificate_new_from_pem ("I am not a very good certificate.", -1, &error);
- g_assert (cert == NULL);
+ g_assert_null (cert);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
}
@@ -251,15 +251,15 @@ test_create_certificate_chain (void)
cert = g_tls_certificate_new_from_file (tls_test_file_path ("chain.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
intermediate = g_tls_certificate_get_issuer (cert);
- g_assert (G_IS_TLS_CERTIFICATE (intermediate));
+ g_assert_true (G_IS_TLS_CERTIFICATE (intermediate));
root = g_tls_certificate_get_issuer (intermediate);
- g_assert (G_IS_TLS_CERTIFICATE (root));
+ g_assert_true (G_IS_TLS_CERTIFICATE (root));
- g_assert (g_tls_certificate_get_issuer (root) == NULL);
+ g_assert_null (g_tls_certificate_get_issuer (root));
g_object_unref (cert);
}
@@ -274,10 +274,10 @@ test_create_certificate_no_chain (void)
cert = g_tls_certificate_new_from_file (tls_test_file_path ("non-ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
issuer = g_tls_certificate_get_issuer (cert);
- g_assert (issuer == NULL);
+ g_assert_null (issuer);
g_object_unref (cert);
/* Truncate a valid chain certificate file. We should only get the
@@ -290,10 +290,10 @@ test_create_certificate_no_chain (void)
cert = g_tls_certificate_new_from_pem (cert_pem, cert_pem_length - 100, &error);
g_free (cert_pem);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
issuer = g_tls_certificate_get_issuer (cert);
- g_assert (issuer == NULL);
+ g_assert_null (issuer);
g_object_unref (cert);
}
@@ -341,44 +341,44 @@ setup_verify (TestVerify *test,
test->cert = g_tls_certificate_new_from_file (tls_test_file_path ("server.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (test->cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->cert));
test->identity = g_network_address_new ("server.example.com", 80);
test->anchor = g_tls_certificate_new_from_file (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (test->anchor));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->anchor));
test->database = g_tls_file_database_new (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
}
static void
teardown_verify (TestVerify *test,
gconstpointer data)
{
- g_assert (G_IS_TLS_CERTIFICATE (test->cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->cert));
g_object_add_weak_pointer (G_OBJECT (test->cert),
(gpointer *)&test->cert);
g_object_unref (test->cert);
- g_assert (test->cert == NULL);
+ g_assert_null (test->cert);
- g_assert (G_IS_TLS_CERTIFICATE (test->anchor));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->anchor));
g_object_add_weak_pointer (G_OBJECT (test->anchor),
(gpointer *)&test->anchor);
g_object_unref (test->anchor);
- g_assert (test->anchor == NULL);
+ g_assert_null (test->anchor);
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
g_object_add_weak_pointer (G_OBJECT (test->database),
(gpointer *)&test->database);
g_object_unref (test->database);
- g_assert (test->database == NULL);
+ g_assert_null (test->database);
g_object_add_weak_pointer (G_OBJECT (test->identity),
(gpointer *)&test->identity);
g_object_unref (test->identity);
- g_assert (test->identity == NULL);
+ g_assert_null (test->identity);
}
static void
@@ -441,7 +441,7 @@ test_verify_certificate_bad_ca (TestVerify *test,
/* Use a client certificate as the CA, which is wrong */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_certificate_verify (test->cert, test->identity, cert);
g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_UNKNOWN_CA);
@@ -460,7 +460,7 @@ test_verify_certificate_bad_before (TestVerify *test,
/* This is a certificate in the future */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client-future.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_certificate_verify (cert, NULL, test->anchor);
g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_NOT_ACTIVATED);
@@ -479,7 +479,7 @@ test_verify_certificate_bad_expired (TestVerify *test,
/* This is a certificate in the future */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client-past.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_certificate_verify (cert, NULL, test->anchor);
g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_EXPIRED);
@@ -499,12 +499,12 @@ test_verify_certificate_bad_combo (TestVerify *test,
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client-past.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
/* Unrelated cert used as certificate authority */
cacert = g_tls_certificate_new_from_file (tls_test_file_path ("server-self.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cacert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cacert));
/*
* - Use unrelated cert as CA
@@ -540,12 +540,12 @@ test_certificate_is_same (void)
three = g_tls_certificate_new_from_file (tls_test_file_path ("server.pem"), &error);
g_assert_no_error (error);
- g_assert (g_tls_certificate_is_same (one, two) == TRUE);
- g_assert (g_tls_certificate_is_same (two, one) == TRUE);
- g_assert (g_tls_certificate_is_same (three, one) == FALSE);
- g_assert (g_tls_certificate_is_same (one, three) == FALSE);
- g_assert (g_tls_certificate_is_same (two, three) == FALSE);
- g_assert (g_tls_certificate_is_same (three, two) == FALSE);
+ g_assert_true (g_tls_certificate_is_same (one, two));
+ g_assert_true (g_tls_certificate_is_same (two, one));
+ g_assert_false (g_tls_certificate_is_same (three, one));
+ g_assert_false (g_tls_certificate_is_same (one, three));
+ g_assert_false (g_tls_certificate_is_same (two, three));
+ g_assert_false (g_tls_certificate_is_same (three, two));
g_object_unref (one);
g_object_unref (two);
diff --git a/tls/tests/connection.c b/tls/tests/connection.c
index 2c59001..64ca464 100644
--- a/tls/tests/connection.c
+++ b/tls/tests/connection.c
@@ -222,7 +222,7 @@ on_server_close_finish (GObject *object,
g_io_stream_close_finish (G_IO_STREAM (object), res, &error);
if (test->expect_server_error)
- g_assert (error != NULL);
+ g_assert_nonnull (error);
else
g_assert_no_error (error);
test->server_running = FALSE;
@@ -242,7 +242,7 @@ on_output_write_finish (GObject *object,
{
TestConnection *test = user_data;
- g_assert (test->server_error == NULL);
+ g_assert_no_error (test->server_error);
g_output_stream_write_finish (G_OUTPUT_STREAM (object), res, &test->server_error);
if (!test->server_error && test->rehandshake)
@@ -451,7 +451,7 @@ on_input_read_finish (GObject *object,
NULL, &test->read_error);
if (!test->read_error)
{
- g_assert (line);
+ g_assert_nonnull (line);
check = g_strdup (TEST_DATA);
g_strstrip (check);
@@ -470,7 +470,7 @@ read_test_data_async (TestConnection *test)
GDataInputStream *stream;
stream = g_data_input_stream_new (g_io_stream_get_input_stream (test->client_connection));
- g_assert (stream);
+ g_assert_nonnull (stream);
g_data_input_stream_read_line_async (stream, G_PRIORITY_DEFAULT, NULL,
on_input_read_finish, test);
@@ -509,12 +509,12 @@ test_verified_connection (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -546,19 +546,19 @@ test_verified_chain (TestConnection *test,
/* Prepare the intermediate cert. */
intermediate_cert = g_tls_certificate_new_from_file (tls_test_file_path ("intermediate-ca.pem"), &error);
g_assert_no_error (error);
- g_assert (intermediate_cert);
+ g_assert_nonnull (intermediate_cert);
/* Prepare the server cert. */
g_clear_pointer (&cert_data, g_free);
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -567,7 +567,7 @@ test_verified_chain (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
g_object_unref (intermediate_cert);
g_free (cert_data);
@@ -594,13 +594,13 @@ test_verified_chain_with_redundant_root_cert (TestConnection *test,
/* The root is redundant. It should not hurt anything. */
root_cert = g_tls_certificate_new_from_file (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (root_cert);
+ g_assert_nonnull (root_cert);
/* Prepare the intermediate cert. */
g_file_get_contents (tls_test_file_path ("intermediate-ca.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
intermediate_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -608,19 +608,19 @@ test_verified_chain_with_redundant_root_cert (TestConnection *test,
"certificate-pem", cert_data,
NULL);
g_assert_no_error (error);
- g_assert (intermediate_cert);
+ g_assert_nonnull (intermediate_cert);
/* Prepare the server cert. */
g_clear_pointer (&cert_data, g_free);
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -629,7 +629,7 @@ test_verified_chain_with_redundant_root_cert (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
g_object_unref (intermediate_cert);
g_object_unref (root_cert);
@@ -662,19 +662,19 @@ test_verified_chain_with_duplicate_server_cert (TestConnection *test,
/* Prepare the intermediate cert. */
intermediate_cert = g_tls_certificate_new_from_file (tls_test_file_path ("intermediate-ca.pem"), &error);
g_assert_no_error (error);
- g_assert (intermediate_cert);
+ g_assert_nonnull (intermediate_cert);
/* Prepare the server cert. */
g_clear_pointer (&cert_data, g_free);
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -682,7 +682,7 @@ test_verified_chain_with_duplicate_server_cert (TestConnection *test,
"certificate-pem", cert_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
/* Prepare the server cert... again. Private key must go on this one. */
extra_server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
@@ -692,7 +692,7 @@ test_verified_chain_with_duplicate_server_cert (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (extra_server_cert);
+ g_assert_nonnull (extra_server_cert);
g_object_unref (intermediate_cert);
g_object_unref (server_cert);
@@ -721,11 +721,11 @@ test_verified_unordered_chain (TestConnection *test,
intermediate_cert = g_tls_certificate_new_from_file (tls_test_file_path ("intermediate-ca.pem"),
&error);
g_assert_no_error (error);
- g_assert (intermediate_cert);
+ g_assert_nonnull (intermediate_cert);
g_file_get_contents (tls_test_file_path ("ca.pem"), &cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
/* Prepare the root cert (to be sent in the middle of the chain). */
root_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
@@ -734,18 +734,18 @@ test_verified_unordered_chain (TestConnection *test,
"certificate-pem", cert_data,
NULL);
g_assert_no_error (error);
- g_assert (root_cert);
+ g_assert_nonnull (root_cert);
g_clear_pointer (&cert_data, g_free);
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
/* Prepare the server cert. */
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
@@ -755,7 +755,7 @@ test_verified_unordered_chain (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
g_object_unref (intermediate_cert);
g_object_unref (root_cert);
@@ -786,7 +786,7 @@ test_verified_chain_with_alternative_ca_cert (TestConnection *test,
* fail, since the issuer is untrusted. */
root_cert = g_tls_certificate_new_from_file (tls_test_file_path ("ca-alternative.pem"), &error);
g_assert_no_error (error);
- g_assert (root_cert);
+ g_assert_nonnull (root_cert);
/* Prepare the intermediate cert. Modern TLS libraries are expected to notice
* that it is signed by the same public key as a certificate in the root
@@ -797,7 +797,7 @@ test_verified_chain_with_alternative_ca_cert (TestConnection *test,
g_file_get_contents (tls_test_file_path ("intermediate-ca.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
intermediate_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -805,19 +805,19 @@ test_verified_chain_with_alternative_ca_cert (TestConnection *test,
"certificate-pem", cert_data,
NULL);
g_assert_no_error (error);
- g_assert (intermediate_cert);
+ g_assert_nonnull (intermediate_cert);
/* Prepare the server cert. */
g_clear_pointer (&cert_data, g_free);
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -826,7 +826,7 @@ test_verified_chain_with_alternative_ca_cert (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
g_object_unref (intermediate_cert);
g_object_unref (root_cert);
@@ -854,19 +854,19 @@ test_invalid_chain_with_alternative_ca_cert (TestConnection *test,
/* This certificate has the same public key as a certificate in the root store. */
root_cert = g_tls_certificate_new_from_file (tls_test_file_path ("ca-alternative.pem"), &error);
g_assert_no_error (error);
- g_assert (root_cert);
+ g_assert_nonnull (root_cert);
/* The intermediate cert is not sent. The chain should be rejected, since without intermediate.pem
* there is no proof that ca-alternative.pem signed server-intermediate.pem. */
g_file_get_contents (tls_test_file_path ("server-intermediate.pem"),
&cert_data, NULL, &error);
g_assert_no_error (error);
- g_assert (cert_data);
+ g_assert_nonnull (cert_data);
g_file_get_contents (tls_test_file_path ("server-intermediate-key.pem"),
&key_data, NULL, &error);
g_assert_no_error (error);
- g_assert (key_data);
+ g_assert_nonnull (key_data);
server_cert = g_initable_new (g_tls_backend_get_certificate_type (backend),
NULL, &error,
@@ -875,7 +875,7 @@ test_invalid_chain_with_alternative_ca_cert (TestConnection *test,
"private-key-pem", key_data,
NULL);
g_assert_no_error (error);
- g_assert (server_cert);
+ g_assert_nonnull (server_cert);
g_object_unref (root_cert);
g_free (cert_data);
@@ -885,7 +885,7 @@ test_invalid_chain_with_alternative_ca_cert (TestConnection *test,
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -907,7 +907,7 @@ on_notify_accepted_cas (GObject *obj,
gpointer user_data)
{
gboolean *changed = user_data;
- g_assert (*changed == FALSE);
+ g_assert_false (*changed);
*changed = TRUE;
}
@@ -924,12 +924,12 @@ test_client_auth_connection (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_REQUIRED, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -954,9 +954,9 @@ test_client_auth_connection (TestConnection *test,
g_assert_no_error (test->server_error);
peer = g_tls_connection_get_peer_certificate (G_TLS_CONNECTION (test->server_connection));
- g_assert (peer != NULL);
- g_assert (g_tls_certificate_is_same (peer, cert));
- g_assert (cas_changed == TRUE);
+ g_assert_nonnull (peer);
+ g_assert_true (g_tls_certificate_is_same (peer, cert));
+ g_assert_true (cas_changed);
g_object_unref (cert);
g_object_unref (test->database);
@@ -987,8 +987,8 @@ test_client_auth_connection (TestConnection *test,
/* peer should see the second client cert */
peer = g_tls_connection_get_peer_certificate (G_TLS_CONNECTION (test->server_connection));
- g_assert (peer != NULL);
- g_assert (g_tls_certificate_is_same (peer, cert));
+ g_assert_nonnull (peer);
+ g_assert_true (g_tls_certificate_is_same (peer, cert));
}
static void
@@ -1013,12 +1013,12 @@ test_client_auth_failure (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_REQUIRED, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -1039,7 +1039,7 @@ test_client_auth_failure (TestConnection *test,
g_assert_error (test->read_error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED);
g_assert_error (test->server_error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED);
- g_assert (accepted_changed == TRUE);
+ g_assert_true (accepted_changed);
g_object_unref (test->client_connection);
g_object_unref (test->database);
@@ -1080,9 +1080,9 @@ test_client_auth_failure (TestConnection *test,
g_assert_no_error (test->server_error);
peer = g_tls_connection_get_peer_certificate (G_TLS_CONNECTION (test->server_connection));
- g_assert (peer != NULL);
- g_assert (g_tls_certificate_is_same (peer, cert));
- g_assert (accepted_changed == TRUE);
+ g_assert_nonnull (peer);
+ g_assert_true (g_tls_certificate_is_same (peer, cert));
+ g_assert_true (accepted_changed);
g_object_unref (cert);
}
@@ -1099,12 +1099,12 @@ test_client_auth_fail_missing_client_private_key (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_REQUIRED, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -1141,12 +1141,12 @@ test_client_auth_request_cert (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_REQUIRED, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -1173,9 +1173,9 @@ test_client_auth_request_cert (TestConnection *test,
g_assert_no_error (test->server_error);
peer = g_tls_connection_get_peer_certificate (G_TLS_CONNECTION (test->server_connection));
- g_assert (peer != NULL);
- g_assert (g_tls_certificate_is_same (peer, cert));
- g_assert (cas_changed == TRUE);
+ g_assert_nonnull (peer);
+ g_assert_true (g_tls_certificate_is_same (peer, cert));
+ g_assert_true (cas_changed);
g_object_unref (cert);
}
@@ -1190,12 +1190,12 @@ test_client_auth_request_fail (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("ca-roots.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_REQUIRED, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
@@ -1228,7 +1228,7 @@ test_connection_no_database (TestConnection *test,
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
/* Overrides loading of the default database */
@@ -1338,9 +1338,9 @@ test_connection_socket_client (TestConnection *test,
connection = (GSocketConnection *)test->client_connection;
test->client_connection = NULL;
- g_assert (G_IS_TCP_WRAPPER_CONNECTION (connection));
+ g_assert_true (G_IS_TCP_WRAPPER_CONNECTION (connection));
base = g_tcp_wrapper_connection_get_base_io_stream (G_TCP_WRAPPER_CONNECTION (connection));
- g_assert (G_IS_TLS_CONNECTION (base));
+ g_assert_true (G_IS_TLS_CONNECTION (base));
g_io_stream_close (G_IO_STREAM (connection), NULL, &error);
g_assert_no_error (error);
@@ -1458,9 +1458,9 @@ test_connection_read_time_out_write (TestConnection *test,
connection = (GSocketConnection *)test->client_connection;
test->client_connection = NULL;
- g_assert (G_IS_TCP_WRAPPER_CONNECTION (connection));
+ g_assert_true (G_IS_TCP_WRAPPER_CONNECTION (connection));
base = g_tcp_wrapper_connection_get_base_io_stream (G_TCP_WRAPPER_CONNECTION (connection));
- g_assert (G_IS_TLS_CONNECTION (base));
+ g_assert_true (G_IS_TLS_CONNECTION (base));
g_io_stream_close (G_IO_STREAM (connection), NULL, &error);
g_assert_no_error (error);
@@ -2050,17 +2050,17 @@ test_output_stream_close (TestConnection *test,
ret = g_output_stream_close (g_io_stream_get_output_stream (test->client_connection),
NULL, &error);
g_assert_no_error (error);
- g_assert (ret);
+ g_assert_true (ret);
/* Verify that double close returns TRUE */
ret = g_output_stream_close (g_io_stream_get_output_stream (test->client_connection),
NULL, &error);
g_assert_no_error (error);
- g_assert (ret);
+ g_assert_true (ret);
size = g_output_stream_write (g_io_stream_get_output_stream (test->client_connection),
"data", 4, NULL, &error);
- g_assert (size == -1);
+ g_assert_cmpint (size, ==, -1);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
g_clear_error (&error);
@@ -2075,7 +2075,7 @@ test_output_stream_close (TestConnection *test,
ret = g_io_stream_close (test->client_connection, NULL, &error);
g_assert_no_error (error);
- g_assert (ret);
+ g_assert_true (ret);
}
static void
@@ -2087,12 +2087,12 @@ test_garbage_database (TestConnection *test,
test->database = g_tls_file_database_new (tls_test_file_path ("garbage.pem"), &error);
g_assert_no_error (error);
- g_assert (test->database);
+ g_assert_nonnull (test->database);
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
test->client_connection = g_tls_client_connection_new (connection, test->identity, &error);
g_assert_no_error (error);
- g_assert (test->client_connection);
+ g_assert_nonnull (test->client_connection);
g_object_unref (connection);
g_tls_connection_set_database (G_TLS_CONNECTION (test->client_connection), test->database);
diff --git a/tls/tests/dtls-connection.c b/tls/tests/dtls-connection.c
index 0baa746..5f53134 100644
--- a/tls/tests/dtls-connection.c
+++ b/tls/tests/dtls-connection.c
@@ -328,7 +328,7 @@ close_server_connection (TestConnection *test,
while (g_main_context_iteration (test->server_context, FALSE));
if (graceful && test->expect_server_error)
- g_assert (error != NULL);
+ g_assert_nonnull (error);
else if (graceful)
g_assert_no_error (error);
@@ -628,7 +628,7 @@ read_test_data_async (TestConnection *test)
check = g_strdup (TEST_DATA);
g_assert_cmpuint (strlen (check), ==, message.bytes_received);
- g_assert (strncmp (check, (const char *)buf, message.bytes_received) == 0);
+ g_assert_cmpint (strncmp (check, (const char *)buf, message.bytes_received), ==, 0);
g_free (check);
}
diff --git a/tls/tests/file-database.c b/tls/tests/file-database.c
index 35a06f0..45fc10d 100644
--- a/tls/tests/file-database.c
+++ b/tls/tests/file-database.c
@@ -74,35 +74,35 @@ setup_verify (TestVerify *test,
test->cert = g_tls_certificate_new_from_file (tls_test_file_path ("server.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (test->cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->cert));
test->identity = g_network_address_new ("server.example.com", 80);
test->database = g_tls_file_database_new (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
}
static void
teardown_verify (TestVerify *test,
gconstpointer data)
{
- g_assert (G_IS_TLS_CERTIFICATE (test->cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (test->cert));
g_object_add_weak_pointer (G_OBJECT (test->cert),
(gpointer *)&test->cert);
g_object_unref (test->cert);
- g_assert (test->cert == NULL);
+ g_assert_null (test->cert);
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
g_object_add_weak_pointer (G_OBJECT (test->database),
(gpointer *)&test->database);
g_object_unref (test->database);
- g_assert (test->database == NULL);
+ g_assert_null (test->database);
g_object_add_weak_pointer (G_OBJECT (test->identity),
(gpointer *)&test->identity);
g_object_unref (test->identity);
- g_assert (test->identity == NULL);
+ g_assert_null (test->identity);
}
static void
@@ -154,7 +154,7 @@ test_verify_database_bad_ca (TestVerify *test,
/* Use another certificate which isn't in our CA list */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("server-self.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_database_verify_chain (test->database, cert,
G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER,
@@ -176,7 +176,7 @@ test_verify_database_bad_before (TestVerify *test,
/* This is a certificate in the future */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client-future.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_database_verify_chain (test->database, cert,
G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER,
@@ -198,7 +198,7 @@ test_verify_database_bad_expired (TestVerify *test,
/* This is a certificate in the future */
cert = g_tls_certificate_new_from_file (tls_test_file_path ("client-past.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
errors = g_tls_database_verify_chain (test->database, cert,
G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER,
@@ -220,7 +220,7 @@ test_verify_database_bad_combo (TestVerify *test,
cert = g_tls_certificate_new_from_file (tls_test_file_path ("server-self.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (cert));
+ g_assert_true (G_IS_TLS_CERTIFICATE (cert));
/*
* - Use is self signed
@@ -302,11 +302,11 @@ test_verify_with_incorrect_root_in_chain (void)
*/
database = g_tls_file_database_new (tls_test_file_path ("ca-verisign-sha1.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_DATABASE (database));
+ g_assert_true (G_IS_TLS_DATABASE (database));
ca_verisign_sha1 = g_tls_certificate_new_from_file (tls_test_file_path ("ca-verisign-sha1.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (ca_verisign_sha1));
+ g_assert_true (G_IS_TLS_CERTIFICATE (ca_verisign_sha1));
/*
* This certificate chain contains a root certificate with that same issuer, public key:
@@ -318,12 +318,12 @@ test_verify_with_incorrect_root_in_chain (void)
*/
chain = load_certificate_chain (tls_test_file_path ("chain-with-verisign-md2.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (chain));
+ g_assert_true (G_IS_TLS_CERTIFICATE (chain));
- g_assert (g_tls_certificate_get_issuer (chain) != NULL);
- g_assert (g_tls_certificate_get_issuer (g_tls_certificate_get_issuer (chain)) != NULL);
- g_assert (is_certificate_in_chain (chain, chain));
- g_assert (!is_certificate_in_chain (chain, ca_verisign_sha1));
+ g_assert_nonnull (g_tls_certificate_get_issuer (chain));
+ g_assert_nonnull (g_tls_certificate_get_issuer (g_tls_certificate_get_issuer (chain)));
+ g_assert_true (is_certificate_in_chain (chain, chain));
+ g_assert_false (is_certificate_in_chain (chain, ca_verisign_sha1));
identity = g_network_address_new ("secure-test.streamline-esolutions.com", 443);
@@ -359,18 +359,18 @@ setup_file_database (TestFileDatabase *test,
test->path = tls_test_file_path ("ca-roots.pem");
test->database = g_tls_file_database_new (test->path, &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
}
static void
teardown_file_database (TestFileDatabase *test,
gconstpointer data)
{
- g_assert (G_IS_TLS_DATABASE (test->database));
+ g_assert_true (G_IS_TLS_DATABASE (test->database));
g_object_add_weak_pointer (G_OBJECT (test->database),
(gpointer *)&test->database);
g_object_unref (test->database);
- g_assert (test->database == NULL);
+ g_assert_null (test->database);
}
static void
@@ -390,17 +390,17 @@ test_file_database_handle (TestFileDatabase *test,
certificate = g_tls_certificate_new_from_file (tls_test_file_path ("ca.pem"), &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (certificate));
+ g_assert_true (G_IS_TLS_CERTIFICATE (certificate));
handle = g_tls_database_create_certificate_handle (test->database, certificate);
- g_assert (handle != NULL);
- g_assert (g_str_has_prefix (handle, "file:///"));
+ g_assert_nonnull (handle);
+ g_assert_true (g_str_has_prefix (handle, "file:///"));
check = g_tls_database_lookup_certificate_for_handle (test->database, handle,
NULL, G_TLS_DATABASE_LOOKUP_NONE,
NULL, &error);
g_assert_no_error (error);
- g_assert (G_IS_TLS_CERTIFICATE (check));
+ g_assert_true (G_IS_TLS_CERTIFICATE (check));
g_free (handle);
g_object_unref (check);
@@ -418,7 +418,7 @@ test_file_database_handle_invalid (TestFileDatabase *test,
NULL, G_TLS_DATABASE_LOOKUP_NONE,
NULL, &error);
g_assert_no_error (error);
- g_assert (certificate == NULL);
+ g_assert_null (certificate);
}
/* -----------------------------------------------------------------------------
@@ -507,11 +507,11 @@ test_lookup_certificates_issued_by (void)
g_assert_cmpuint (g_list_length (certificates), ==, 4);
- g_assert (certificate_is_in_list (certificates, tls_test_file_path ("client.pem")));
- g_assert (certificate_is_in_list (certificates, tls_test_file_path ("client-future.pem")));
- g_assert (certificate_is_in_list (certificates, tls_test_file_path ("client-past.pem")));
- g_assert (certificate_is_in_list (certificates, tls_test_file_path ("server.pem")));
- g_assert (!certificate_is_in_list (certificates, tls_test_file_path ("server-self.pem")));
+ g_assert_true (certificate_is_in_list (certificates, tls_test_file_path ("client.pem")));
+ g_assert_true (certificate_is_in_list (certificates, tls_test_file_path ("client-future.pem")));
+ g_assert_true (certificate_is_in_list (certificates, tls_test_file_path ("client-past.pem")));
+ g_assert_true (certificate_is_in_list (certificates, tls_test_file_path ("server.pem")));
+ g_assert_false (certificate_is_in_list (certificates, tls_test_file_path ("server-self.pem")));
g_list_free_full (certificates, g_object_unref);
g_object_unref (database);
@@ -525,13 +525,13 @@ test_default_database_is_singleton (void)
GTlsDatabase *check;
backend = g_tls_backend_get_default ();
- g_assert (G_IS_TLS_BACKEND (backend));
+ g_assert_true (G_IS_TLS_BACKEND (backend));
database = g_tls_backend_get_default_database (backend);
- g_assert (G_IS_TLS_DATABASE (database));
+ g_assert_true (G_IS_TLS_DATABASE (database));
check = g_tls_backend_get_default_database (backend);
- g_assert (database == check);
+ g_assert_true (database == check);
g_object_unref (database);
g_object_unref (check);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]