[gnome-keyring] gcr: Test GcrParser with null and empty data
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] gcr: Test GcrParser with null and empty data
- Date: Thu, 1 Sep 2011 10:15:58 +0000 (UTC)
commit d7a21115eec6e6098bb6d1b829283272c06e6eb5
Author: Stef Walter <stefw collabora co uk>
Date: Thu Aug 25 16:34:25 2011 +0200
gcr: Test GcrParser with null and empty data
gcr/gcr-parser.c | 24 +++++++++++++-----------
gcr/tests/test-parser.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c
index 2162b98..d9500dd 100644
--- a/gcr/gcr-parser.c
+++ b/gcr/gcr-parser.c
@@ -1678,19 +1678,21 @@ gcr_parser_parse_data (GcrParser *self, gconstpointer data,
g_return_val_if_fail (data || !n_data, FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
- /* Just the specific formats requested */
- if (self->pv->specific_formats) {
- g_tree_foreach (self->pv->specific_formats, parser_format_foreach, &args);
-
- /* All the 'normal' formats */
- } else if (self->pv->normal_formats) {
- for (i = 0; i < G_N_ELEMENTS (parser_normal); ++i) {
- if (parser_format_foreach ((gpointer)(parser_normal + i),
- (gpointer)(parser_normal + i), &args))
- break;
+ if (data && n_data) {
+ /* Just the specific formats requested */
+ if (self->pv->specific_formats) {
+ g_tree_foreach (self->pv->specific_formats, parser_format_foreach, &args);
+
+ /* All the 'normal' formats */
+ } else if (self->pv->normal_formats) {
+ for (i = 0; i < G_N_ELEMENTS (parser_normal); ++i) {
+ if (parser_format_foreach ((gpointer)(parser_normal + i),
+ (gpointer)(parser_normal + i), &args))
+ break;
+ }
}
}
-
+
switch (args.result) {
case SUCCESS:
return TRUE;
diff --git a/gcr/tests/test-parser.c b/gcr/tests/test-parser.c
index 07b1159..b9d2ab0 100644
--- a/gcr/tests/test-parser.c
+++ b/gcr/tests/test-parser.c
@@ -132,6 +132,36 @@ test_parse_one (Test *test,
g_free (contents);
}
+static void
+test_parse_null (void)
+{
+ GcrParser *parser = gcr_parser_new ();
+ GError *error = NULL;
+ gboolean result;
+
+ result = gcr_parser_parse_data (parser, NULL, 0, &error);
+ g_assert_error (error, GCR_DATA_ERROR, GCR_ERROR_UNRECOGNIZED);
+ g_assert (!result);
+ g_error_free (error);
+
+ g_object_unref (parser);
+}
+
+static void
+test_parse_empty (void)
+{
+ GcrParser *parser = gcr_parser_new ();
+ GError *error = NULL;
+ gboolean result;
+
+ result = gcr_parser_parse_data (parser, "", 0, &error);
+ g_assert_error (error, GCR_DATA_ERROR, GCR_ERROR_UNRECOGNIZED);
+ g_assert (!result);
+ g_error_free (error);
+
+ g_object_unref (parser);
+}
+
int
main (int argc, char **argv)
{
@@ -178,6 +208,9 @@ main (int argc, char **argv)
g_dir_close (dir);
+ g_test_add_func ("/gcr/parser/parse_null", test_parse_null);
+ g_test_add_func ("/gcr/parser/parse_empty", test_parse_empty);
+
ret = g_test_run ();
g_ptr_array_free (strings, TRUE);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]