Преглед изворни кода

Start setting up more elaborate tests

Matthias Vogelgesang пре 7 година
родитељ
комит
73f7141e04
2 измењених фајлова са 45 додато и 8 уклоњено
  1. 1 1
      src/iridium-standard-file.c
  2. 44 7
      test/test-crypto.c

+ 1 - 1
src/iridium-standard-file.c

@@ -355,7 +355,7 @@ iridium_standard_file_get_items (JsonParser *parser,
   GList *items = NULL;
 
   root = json_node_get_object (json_parser_get_root (parser));
-  array = json_object_get_array_member (root, "retrieved_items");
+  array = json_object_get_array_member (root, "items");
 
   for (guint i = 0; i < json_array_get_length (array); i++) {
     JsonObject *data;

+ 44 - 7
test/test-crypto.c

@@ -1,7 +1,38 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <string.h>
+#include <json-glib/json-glib.h>
 #include "iridium-crypto.h"
+#include "iridium-standard-file.h"
+
+typedef struct {
+  JsonParser *parser;
+} Dump;
+
+static void
+dump_003_set_up (Dump *dump, gconstpointer user_data)
+{
+  GBytes *data;
+  GError *error = NULL;
+
+  data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.json",
+                                  G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+  g_assert_nonnull (data);
+
+  dump->parser = json_parser_new_immutable ();
+
+  g_assert (json_parser_load_from_data (dump->parser, g_bytes_get_data (data, NULL),
+                                        g_bytes_get_size(data), &error));
+
+  g_assert_null (error);
+  g_bytes_unref (data);
+}
+
+static void
+dump_003_tear_down (Dump *dump, gconstpointer user_data)
+{
+  g_object_unref (dump->parser);
+}
 
 static void
 test_hexlify (void)
@@ -22,14 +53,18 @@ test_unhexlify (void)
 }
 
 static void
-test_decrypt_003 (void)
+test_decrypt_003_wrong_password (Dump *dump, gconstpointer user_data)
 {
-  GBytes *data;
+  IridiumAuthParams *params;
+  GList *items;
+  GError *error;
 
-  data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.json",
-                                  G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
-  g_assert_nonnull (data);
-  g_bytes_unref (data);
+  params = iridium_crypto_auth_params_new ();
+  iridium_crypto_derive_keys (params, "foo");
+  items = iridium_standard_file_get_items (dump->parser, params, &error);
+  g_assert_null (items);
+  g_assert_nonnull (error);
+  iridium_crypto_auth_params_free (params);
 }
 
 int
@@ -38,7 +73,9 @@ main (int argc, char * argv[])
   g_test_init (&argc, &argv, NULL);
   g_test_add_func ("/crypto/hexlify", test_hexlify);
   g_test_add_func ("/crypto/unhexlify", test_unhexlify);
-  g_test_add_func ("/crypto/decrypt/003", test_decrypt_003);
+
+  g_test_add ("/crypto/decrypt/003/wrong-password", Dump, NULL,
+              dump_003_set_up, test_decrypt_003_wrong_password, dump_003_tear_down);
 
   return g_test_run ();
 }