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.

58 lines
1.8 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 "mconn-crypt.h"
  22. static void test_simple(void)
  23. {
  24. g_remove("/tmp/test.key");
  25. /* we made sure that file is removed */
  26. g_assert_false(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  27. MconnCrypt *cr = mconn_crypt_new_for_key_path("/tmp/test.key");
  28. g_assert_nonnull(cr);
  29. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  30. gchar *pubkey1 = mconn_crypt_get_public_key_pem(cr);
  31. mconn_crypt_unref(cr);
  32. /* file should still exit */
  33. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  34. cr = mconn_crypt_new_for_key_path("/tmp/test.key");
  35. /* key should have been loaded */
  36. g_assert_nonnull(cr);
  37. g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));
  38. gchar *pubkey2 = mconn_crypt_get_public_key_pem(cr);
  39. mconn_crypt_unref(cr);
  40. g_assert_cmpstr(pubkey1, ==, pubkey2);
  41. }
  42. int main(int argc, char *argv[])
  43. {
  44. g_test_init(&argc, &argv, NULL);
  45. g_test_add_func("/mconn-crypt/init", test_simple);
  46. return g_test_run();
  47. }