[gcr] egg: Rework egg_assert_cmpbytes()
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr] egg: Rework egg_assert_cmpbytes()
- Date: Thu, 24 Nov 2011 06:58:07 +0000 (UTC)
commit c823c00677ddda03862adf2914a35670fa7cb0c9
Author: Stef Walter <stefw collabora co uk>
Date: Thu Nov 17 10:30:42 2011 +0100
egg: Rework egg_assert_cmpbytes()
* Rename to more inline with other testing functions
* Clearer messages
egg/egg-bytes.h | 3 ---
egg/egg-testing.c | 3 ++-
egg/egg-testing.h | 7 +++++++
egg/tests/test-asn1.c | 22 +++++++++++-----------
egg/tests/test-openssl.c | 2 +-
5 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/egg/egg-bytes.h b/egg/egg-bytes.h
index c30a43a..d25432f 100644
--- a/egg/egg-bytes.h
+++ b/egg/egg-bytes.h
@@ -99,7 +99,4 @@ gboolean egg_bytes_equal (gconstpointer bytes1,
gint egg_bytes_compare (gconstpointer bytes1,
gconstpointer bytes2);
-#define egg_assert_equal_bytes(b, p, s) \
- egg_assert_cmpmem (egg_bytes_get_data (b), egg_bytes_get_size (b), ==, (p), (s))
-
#endif /* __EGG_BYTES_H__ */
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 85d4b0b..88d647d 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -28,6 +28,7 @@
#include <glib-object.h>
#include <errno.h>
+#include <string.h>
#include <unistd.h>
#ifdef WITH_VALGRIND
@@ -68,7 +69,7 @@ egg_test_escape_data (const guchar *data,
result = g_string_sized_new (n_data * 2 + 1);
for (i = 0; i < n_data; ++i) {
c = data[i];
- if (g_ascii_isprint (c)) {
+ if (g_ascii_isprint (c) && !strchr ("\n\r\v", c)) {
g_string_append_c (result, c);
} else {
g_string_append (result, "\\x");
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
index 529443f..a08c34a 100644
--- a/egg/egg-testing.h
+++ b/egg/egg-testing.h
@@ -37,6 +37,13 @@
G_STRFUNC, #a "[" #na"] " #cmp " " #b "[" #nb "]", \
__p1, __n1, #cmp, __p2, __n2); } while (0)
+#define egg_assert_cmpbytes(a, cmp, b, nb) \
+ do { gpointer __p1 = (gpointer)(a); gconstpointer __p2 = (b); gsize __n2 = (nb); \
+ if (egg_bytes_get_size (__p1) cmp __n2 && memcmp (egg_bytes_get_data (__p1), __p2, __n2) cmp 0) ; else \
+ egg_assertion_message_cmpmem (G_LOG_DOMAIN, __FILE__, __LINE__, \
+ G_STRFUNC, #a " " #cmp " " #b, \
+ egg_bytes_get_data (__p1), egg_bytes_get_size(__p1), #cmp, __p2, __n2); } while (0)
+
void egg_assertion_message_cmpmem (const char *domain, const char *file,
int line, const char *func,
const char *expr, gconstpointer arg1,
diff --git a/egg/tests/test-asn1.c b/egg/tests/test-asn1.c
index 41ec2b5..caf01af 100644
--- a/egg/tests/test-asn1.c
+++ b/egg/tests/test-asn1.c
@@ -553,12 +553,12 @@ test_any_set_raw (void)
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
- egg_assert_equal_bytes (data, SEQ_ENCODING, XL (SEQ_ENCODING));
+ egg_assert_cmpbytes (data, ==, SEQ_ENCODING, XL (SEQ_ENCODING));
check = egg_asn1x_get_element_raw (node);
g_assert (check);
- egg_assert_equal_bytes (check, SFARNSWORTH, XL (SFARNSWORTH));
+ egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
egg_bytes_unref (data);
egg_bytes_unref (check);
@@ -592,12 +592,12 @@ test_any_set_raw_explicit (void)
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
- egg_assert_equal_bytes (data, SEQ_ENCODING, XL (SEQ_ENCODING));
+ egg_assert_cmpbytes (data, ==, SEQ_ENCODING, XL (SEQ_ENCODING));
check = egg_asn1x_get_element_raw (node);
g_assert (check);
- egg_assert_equal_bytes (check, SFARNSWORTH, XL (SFARNSWORTH));
+ egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
egg_bytes_unref (data);
egg_bytes_unref (check);
@@ -666,12 +666,12 @@ perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsi
}
g_assert (data != NULL);
- egg_assert_equal_bytes (data, encoding, n_encoding);
+ egg_assert_cmpbytes (data, ==, encoding, n_encoding);
check = egg_asn1x_get_element_raw (node);
g_assert (check != NULL);
- egg_assert_equal_bytes (check, SFARNSWORTH, XL (SFARNSWORTH));
+ egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
egg_bytes_unref (data);
egg_bytes_unref (check);
@@ -724,7 +724,7 @@ test_append (void)
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
- egg_assert_equal_bytes (data, SEQOF_TWO, XL (SEQOF_TWO));
+ egg_assert_cmpbytes (data, ==, SEQOF_TWO, XL (SEQOF_TWO));
egg_bytes_unref (data);
egg_asn1x_destroy (asn);
@@ -794,7 +794,7 @@ test_setof (void)
g_assert_not_reached ();
}
- egg_assert_equal_bytes (data, SETOF_THREE, XL (SETOF_THREE));
+ egg_assert_cmpbytes (data, ==, SETOF_THREE, XL (SETOF_THREE));
egg_bytes_unref (data);
egg_asn1x_destroy (asn);
@@ -818,7 +818,7 @@ test_setof_empty (void)
g_assert_not_reached ();
}
- egg_assert_equal_bytes (data, SETOF_NONE, XL (SETOF_NONE));
+ egg_assert_cmpbytes (data, ==, SETOF_NONE, XL (SETOF_NONE));
egg_bytes_unref (data);
egg_asn1x_destroy (asn);
@@ -849,7 +849,7 @@ test_enumerated (void)
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
- egg_assert_equal_bytes (data, ENUM_THREE, XL (ENUM_THREE));
+ egg_assert_cmpbytes (data, ==, ENUM_THREE, XL (ENUM_THREE));
egg_bytes_unref (data);
egg_asn1x_destroy (asn);
@@ -1076,7 +1076,7 @@ test_read_element (Test* test, gconstpointer unused)
data = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "data", NULL));
g_assert (data != NULL);
- egg_assert_equal_bytes (data, "SOME DATA", 9);
+ egg_assert_cmpbytes (data, ==, "SOME DATA", 9);
egg_bytes_unref (data);
egg_asn1x_destroy (asn);
diff --git a/egg/tests/test-openssl.c b/egg/tests/test-openssl.c
index 57b0e8e..6c39496 100644
--- a/egg/tests/test-openssl.c
+++ b/egg/tests/test-openssl.c
@@ -165,7 +165,7 @@ test_write_exactly_same (Test *test, gconstpointer unused)
* and line endings.
*/
- egg_assert_equal_bytes (test->input, result, n_result);
+ egg_assert_cmpbytes (test->input, ==, result, n_result);
g_free (result);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]