From 13c4a1dc257ebf10b2b1ac7e411d70aacf43234f Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 13 Jan 2015 19:34:51 +0100 Subject: [PATCH] mconn-crypt-vala-test: mconn-crypt tests in Vala --- Makefile.am | 11 +++++++-- test/mconn-crypt-vala-test.vala | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/mconn-crypt-vala-test.vala diff --git a/Makefile.am b/Makefile.am index 52be323..1ea5af2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ bin_PROGRAMS = mconnect -noinst_PROGRAMS = test-mconn-crypt +noinst_PROGRAMS = test-mconn-crypt \ + test-mconn-crypt-vala mconnect_SOURCES = src/main.vala \ src/discovery.vala \ @@ -19,5 +20,11 @@ test_mconn_crypt_SOURCES = test/mconn-crypt-test.c \ test_mconn_crypt_LDADD = $(MCONNECT_LIBS) test_mconn_crypt_CFLAGS = $(MCONNECT_CFLAGS) -Isrc -VALAFLAGS = $(MCONNECT_VALAFLAGS) +test_mconn_crypt_vala_SOURCES = test/mconn-crypt-vala-test.vala \ + src/mconn-crypt.c \ + src/mconn-crypt.h +test_mconn_crypt_vala_LDADD = $(MCONNECT_LIBS) +test_mconn_crypt_vala_CFLAGS = $(MCONNECT_CFLAGS) -Isrc + +VALAFLAGS = $(MCONNECT_VALAFLAGS) --vapidir=src --pkg=mconn-crypt diff --git a/test/mconn-crypt-vala-test.vala b/test/mconn-crypt-vala-test.vala new file mode 100644 index 0000000..aeca5f2 --- /dev/null +++ b/test/mconn-crypt-vala-test.vala @@ -0,0 +1,41 @@ +using MConn; + +void test_simple() { + string file_path = "/tmp/test-key-vala.pem"; + FileUtils.remove(file_path); + + string pubkey1; + string pubkey2; + + { + assert(FileUtils.test(file_path, FileTest.EXISTS) == false); + var c = new Crypt.for_key_path(file_path); + assert(FileUtils.test(file_path, FileTest.EXISTS) == true); + pubkey1 = c.get_public_key_pem(); + assert(pubkey1 != null); + } + + // file should still exist + assert(FileUtils.test(file_path, FileTest.EXISTS) == true); + + { + assert(FileUtils.test(file_path, FileTest.EXISTS) == true); + var c = new Crypt.for_key_path(file_path); + assert(FileUtils.test(file_path, FileTest.EXISTS) == true); + pubkey2 = c.get_public_key_pem(); + assert(pubkey2 != null); + } + + debug("public key1:\n%s", pubkey1); + debug("public key2:\n%s", pubkey2); + assert(pubkey1 == pubkey2); +} + +public static void main(string[] args) { + Test.init(ref args); + + Test.add_func("/mconn-crypt-vala/simple", () => { + test_simple(); + }); + Test.run(); +} \ No newline at end of file