[gnome-keyring/trust-store: 96/105] Better ASN.1 test coverage and fixes.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring/trust-store: 96/105] Better ASN.1 test coverage and fixes.
- Date: Tue, 23 Nov 2010 03:08:53 +0000 (UTC)
commit f52fe414b7c6c2de7ed07654b6dcd1355e5a77b1
Author: Stef Walter <stefw collabora co uk>
Date: Fri Nov 19 18:06:10 2010 +0000
Better ASN.1 test coverage and fixes.
egg/egg-asn1x.c | 14 +++++++-
egg/tests/test-asn1.c | 78 ++++++++++++++++++++++++++++++++++++++++---
egg/tests/test.asn | 2 +
egg/tests/unit-test-asn1.c | 19 +++++++++-
4 files changed, 103 insertions(+), 10 deletions(-)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 9d82b94..c37acc8 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -1390,6 +1390,7 @@ traverse_and_sort_set_of (GNode *node, gpointer user_data)
gsize n_data;
Atlv *tlv;
GNode *child;
+ GNode *next;
g_assert (allocator);
@@ -1398,7 +1399,9 @@ traverse_and_sort_set_of (GNode *node, gpointer user_data)
return FALSE;
bufs = NULL;
- for (child = node->children; child; child = child->next) {
+ for (child = node->children; child; child = next) {
+ next = child->next;
+
tlv = anode_get_tlv_data (child);
if (!tlv)
continue;
@@ -2282,6 +2285,8 @@ egg_asn1x_name (GNode *node)
guint
egg_asn1x_count (GNode *node)
{
+ guint result = 0;
+ GNode *child;
gint type;
g_return_val_if_fail (node, 0);
@@ -2292,7 +2297,12 @@ egg_asn1x_count (GNode *node)
return 0;
}
- return g_node_n_children (node);
+ for (child = node->children; child; child = child->next) {
+ if (egg_asn1x_have (child))
+ ++result;
+ }
+
+ return result;
}
GNode*
diff --git a/egg/tests/test-asn1.c b/egg/tests/test-asn1.c
index 6e9d77d..02fdced 100644
--- a/egg/tests/test-asn1.c
+++ b/egg/tests/test-asn1.c
@@ -53,12 +53,6 @@ const gchar ENUM_TWO[] = "\x0A\x01\x02";
/* ENUM with value = 3 */
const gchar ENUM_THREE[] = "\x0A\x01\x03";
-/* SEQUENCE OF with one INTEGER = 1 */
-const gchar SEQOF_ONE[] = "\x30\x03\x02\x01\x01";
-
-/* SEQUENCE OF with two INTEGER = 1, 2 */
-const gchar SEQOF_TWO[] = "\x30\x06\x02\x01\x01\x02\x01\x02";
-
#define XL(x) G_N_ELEMENTS (x) - 1
DEFINE_TEST(asn1_boolean)
@@ -435,6 +429,12 @@ DEFINE_TEST(asn1_append)
gpointer data;
gsize n_data;
+ /* SEQUENCE OF with one INTEGER = 1 */
+ const gchar SEQOF_ONE[] = "\x30\x03\x02\x01\x01";
+
+ /* SEQUENCE OF with two INTEGER = 1, 2 */
+ const gchar SEQOF_TWO[] = "\x30\x06\x02\x01\x01\x02\x01\x02";
+
asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestSeqOf", SEQOF_ONE, XL (SEQOF_ONE));
g_assert (asn);
@@ -455,6 +455,72 @@ DEFINE_TEST(asn1_append)
egg_asn1x_destroy (asn);
}
+DEFINE_TEST(asn1_append_and_clear)
+{
+ GNode *asn;
+ gpointer data;
+ gsize n_data;
+
+ asn = egg_asn1x_create (test_asn1_tab, "TestSeqOf");
+ g_assert (asn);
+
+ g_assert_cmpuint (egg_asn1x_count (asn), ==, 0);
+
+ if (!egg_asn1x_set_integer_as_ulong (egg_asn1x_append (asn), 2))
+ g_assert_not_reached ();
+ if (!egg_asn1x_set_integer_as_ulong (egg_asn1x_append (asn), 3))
+ g_assert_not_reached ();
+
+ g_assert_cmpuint (egg_asn1x_count (asn), ==, 0);
+
+ data = egg_asn1x_encode (asn, NULL, &n_data);
+ g_assert (data);
+
+ g_assert_cmpuint (egg_asn1x_count (asn), ==, 2);
+
+ egg_asn1x_clear (asn);
+ g_assert_cmpuint (egg_asn1x_count (asn), ==, 0);
+
+ egg_asn1x_destroy (asn);
+ g_free (data);
+}
+
+DEFINE_TEST(asn1_setof)
+{
+ GNode *asn;
+ gpointer data;
+ gsize n_data;
+
+ /* SEQUENCE OF with one INTEGER = 3 */
+ const gchar SETOF_ONE[] = "\x31\x03\x02\x01\x03";
+
+ /* SET OF with two INTEGER = 1, 3, 8 */
+ const gchar SETOF_THREE[] = "\x31\x09\x02\x01\x01\x02\x01\x03\x02\x01\x08";
+
+ asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestSetOf", SETOF_ONE, XL (SETOF_ONE));
+ g_assert (asn);
+
+ /* Add integer 1, in SET OF DER should sort to front */
+ if (!egg_asn1x_set_integer_as_ulong (egg_asn1x_append (asn), 1))
+ g_assert_not_reached ();
+
+ /* Add integer 8, in SET OF DER should sort to back */
+ if (!egg_asn1x_set_integer_as_ulong (egg_asn1x_append (asn), 8))
+ g_assert_not_reached ();
+
+ data = egg_asn1x_encode (asn, NULL, &n_data);
+ if (!data) {
+ g_printerr ("%s\n", egg_asn1x_message (asn));
+ g_assert_not_reached ();
+ }
+
+ g_assert (n_data == XL (SETOF_THREE));
+ g_assert (memcmp (data, SETOF_THREE, n_data) == 0);
+
+ g_free (data);
+ egg_asn1x_destroy (asn);
+}
+
DEFINE_TEST (asn1_enumerated)
{
GNode *asn;
diff --git a/egg/tests/test.asn b/egg/tests/test.asn
index 3c7c342..dca24d0 100644
--- a/egg/tests/test.asn
+++ b/egg/tests/test.asn
@@ -42,6 +42,8 @@ TestAnySeq ::= SEQUENCE {
TestSeqOf ::= SEQUENCE OF INTEGER
+TestSetOf ::= SET OF INTEGER
+
TestEnumerated ::= ENUMERATED {
valueZero (0),
valueOne (1),
diff --git a/egg/tests/unit-test-asn1.c b/egg/tests/unit-test-asn1.c
index 63c835d..b01ae23 100644
--- a/egg/tests/unit-test-asn1.c
+++ b/egg/tests/unit-test-asn1.c
@@ -202,12 +202,20 @@ DEFINE_TEST(element_length_content)
content = egg_asn1x_element_content (buffer, length, &n_content);
g_assert (content);
g_assert_cmpuint (n_content, ==, 11);
-
+
content = egg_asn1x_element_content (content, n_content, &n_content);
g_assert (content);
g_assert_cmpuint (n_content, ==, 9);
g_assert (memcmp (content, "SOME DATA", 9) == 0);
+ const char *BAD_ASN_TAG = "\x00";
+ content = egg_asn1x_element_content (BAD_ASN_TAG, 1, &n_content);
+ g_assert (content == NULL);
+
+ const char *BAD_ASN_LENGTH = "\x30\x80";
+ content = egg_asn1x_element_content (BAD_ASN_LENGTH, 2, &n_content);
+ g_assert (content == NULL);
+
egg_asn1x_destroy (asn);
g_free (buffer);
}
@@ -295,6 +303,10 @@ static const TimeTestData generalized_time_test_data[] = {
{ "20070725013528+1130", 1185368728 },
{ "20070725Z", 1185321600 },
{ "20070725+0000", 1185321600 },
+
+ /* Bad ones */
+ { "200707", -1 },
+
{ NULL, 0 }
};
@@ -312,7 +324,10 @@ static const TimeTestData utc_time_test_data[] = {
{ "070725013528+1130", 1185368728 },
{ "070725Z", 1185321600 },
{ "070725+0000", 1185321600 },
-
+
+ /* Bad ones */
+ { "0707", -1 },
+
{ NULL, 0 }
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]