Forráskód Böngészése

Add test infrastructure

Matthias Vogelgesang 7 éve
szülő
commit
9b75a46d1b
6 módosított fájl, 98 hozzáadás és 2 törlés
  1. 3 0
      meson.build
  2. 0 2
      src/meson.build
  3. 28 0
      test/dumps/003.json
  4. 18 0
      test/meson.build
  5. 43 0
      test/test-crypto.c
  6. 6 0
      test/test.gresource.xml

+ 3 - 0
meson.build

@@ -28,8 +28,11 @@ add_project_arguments([
   '-I' + meson.build_root(),
 ], language: 'c')
 
+gnome = import('gnome')
+
 subdir('data')
 subdir('src')
 subdir('po')
+subdir('test')
 
 meson.add_install_script('build-aux/meson/postinstall.py')

+ 0 - 2
src/meson.build

@@ -31,8 +31,6 @@ if not cc.has_header('mkdio.h')
   error('Cannot find mkdio.h')
 endif
 
-gnome = import('gnome')
-
 iridium_sources += gnome.compile_resources(
   'iridium-resources',
   join_paths('resources', 'iridium.gresource.xml'),

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 28 - 0
test/dumps/003.json


+ 18 - 0
test/meson.build

@@ -0,0 +1,18 @@
+tests = [
+  'crypto',
+]
+
+sources = [
+  gnome.compile_resources('iridium-test',
+    'test.gresource.xml',
+    c_name: 'iridium'
+  )
+]
+
+foreach t: tests
+  e = executable(t,
+    sources: sources + ['test-@0@.c'.format(t)],
+    dependencies: libiridium_dep
+  )
+  test(t, e)
+endforeach

+ 43 - 0
test/test-crypto.c

@@ -0,0 +1,43 @@
+#include <glib.h>
+#include <gio/gio.h>
+#include "iridium-crypto.h"
+
+static void
+test_hexlify (void)
+{
+  guint8 data[] = { 'A', '1', 'x', ';' };
+  gchar *hexlified = iridium_crypto_hexlify (data, 4);
+  g_assert_cmpstr (hexlified, ==, "4131783b");
+  g_free (hexlified);
+}
+
+static void
+test_unhexlify (void)
+{
+  gchar *hexlified = "466f6f62617221";
+  guint8 *data = iridium_crypto_unhexlify (hexlified, strlen (hexlified));
+  g_assert_cmpstr ((gchar *) data, ==, "Foobar!");
+  g_free (data);
+}
+
+static void
+test_decrypt_003 (void)
+{
+  GBytes *data;
+
+  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);
+}
+
+int
+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);
+
+  return g_test_run ();
+}

+ 6 - 0
test/test.gresource.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/net/bloerg/Test">
+    <file>dumps/003.json</file>
+  </gresource>
+</gresources>