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.

57 lines
1.7 KiB

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