mconnect - KDE Connect protocol implementation in Vala/C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

  1. /* ex:ts=4:sw=4:sts=4:et */
  2. /* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  3. /**
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * AUTHORS
  18. * Maciek Borzecki <maciek.borzecki (at] gmail.com>
  19. */
  20. #include <glib.h>
  21. #include <glib/gstdio.h>
  22. #include "mconn-crypt.h"
  23. static void test_simple(void)
  24. {
  25. g_remove("/tmp/test.key");
  26. /* we made sure that file is removed */
  27. g_assert_false(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  28. MconnCrypt *cr = mconn_crypt_new_for_key_path("/tmp/test.key");
  29. g_assert_nonnull(cr);
  30. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  31. gchar *pubkey1 = mconn_crypt_get_public_key_pem(cr);
  32. mconn_crypt_unref(cr);
  33. /* file should still exit */
  34. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  35. cr = mconn_crypt_new_for_key_path("/tmp/test.key");
  36. /* key should have been loaded */
  37. g_assert_nonnull(cr);
  38. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  39. gchar *pubkey2 = mconn_crypt_get_public_key_pem(cr);
  40. mconn_crypt_unref(cr);
  41. g_assert_cmpstr(pubkey1, ==, pubkey2);
  42. }
  43. int main(int argc, char *argv[])
  44. {
  45. g_test_init(&argc, &argv, NULL);
  46. g_test_add_func("/mconn-crypt/init", test_simple);
  47. return g_test_run();
  48. }