summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBoris Pek <tehnick-8@yandex.ru>2017-03-29 19:57:40 (GMT)
committerBoris Pek <tehnick-8@yandex.ru>2017-03-29 16:57:10 (GMT)
commitbda9cc9b9abd6a6fa4307bf42b0507f90d3ba47c (patch)
tree990aba72b65ee55fdfb6adaddd5b7d394ef441de /src
parentc78fdfb5763db28d363ec4ea760076c6a73d8a2a (diff)
downloadmxe-bda9cc9b9abd6a6fa4307bf42b0507f90d3ba47c.zip
mxe-bda9cc9b9abd6a6fa4307bf42b0507f90d3ba47c.tar.gz
mxe-bda9cc9b9abd6a6fa4307bf42b0507f90d3ba47c.tar.bz2
libomemo: add test
Diffstat (limited to 'src')
-rw-r--r--src/libomemo-test.c38
-rw-r--r--src/libomemo-test.cmake22
-rw-r--r--src/libomemo.mk7
3 files changed, 67 insertions, 0 deletions
diff --git a/src/libomemo-test.c b/src/libomemo-test.c
new file mode 100644
index 0000000..ef1cbc7
--- /dev/null
+++ b/src/libomemo-test.c
@@ -0,0 +1,38 @@
+// This file is part of MXE. See LICENSE.md for licensing information.
+
+#include <libomemo.h>
+#include <libomemo_crypto.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ char * msg_p = "<message xmlns='jabber:client' type='chat' to='alice@example.com'>"
+ "<body>hello</body>"
+ "</message>";
+
+ printf("Original message:\n%s\n\n", msg_p);
+ fflush(stdout);
+
+ omemo_crypto_provider crypto = {
+ .random_bytes_func = omemo_default_crypto_random_bytes,
+ .aes_gcm_encrypt_func = omemo_default_crypto_aes_gcm_encrypt,
+ .aes_gcm_decrypt_func = omemo_default_crypto_aes_gcm_decrypt,
+ (void *) 0
+ };
+
+ uint32_t sid = 9178;
+
+ omemo_message * msg_out_p;
+ if (omemo_message_prepare_encryption(msg_p, sid, &crypto, &msg_out_p) != 0)
+ return 1;
+
+ char * xml_out_p;
+ if (omemo_message_export_encrypted(msg_out_p, &xml_out_p) != 0)
+ return 1;
+
+ printf("Encrypted message:\n%s\n\n", xml_out_p);
+ fflush(stdout);
+
+ return 0;
+}
+
diff --git a/src/libomemo-test.cmake b/src/libomemo-test.cmake
new file mode 100644
index 0000000..44e7fc5
--- /dev/null
+++ b/src/libomemo-test.cmake
@@ -0,0 +1,22 @@
+# This file is part of MXE. See LICENSE.md for licensing information.
+
+# partial module - included by src/cmake/CMakeLists.txt
+
+set(TGT test-${PKG}-cmake)
+
+enable_language(C)
+add_executable(${TGT} ${CMAKE_CURRENT_LIST_DIR}/${PKG}-test.c)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GLIB2 glib-2.0)
+
+include_directories(${GLIB2_INCLUDE_DIRS})
+target_link_libraries(${TGT} omemo-conversations
+ mxml
+ gcrypt
+ gpg-error
+ pthread
+ ${GLIB2_LIBRARIES})
+
+install(TARGETS ${TGT} DESTINATION bin)
+
diff --git a/src/libomemo.mk b/src/libomemo.mk
index 06aaaff..18ee9a7 100644
--- a/src/libomemo.mk
+++ b/src/libomemo.mk
@@ -20,6 +20,13 @@ define $(PKG)_BUILD
$(INSTALL) -m644 '$(1)/build'/libomemo*.a '$(PREFIX)/$(TARGET)/lib/'
$(INSTALL) -d '$(PREFIX)/$(TARGET)/include'
$(INSTALL) -m644 '$(1)/src'/libomemo*.h '$(PREFIX)/$(TARGET)/include/'
+
+ # test cmake
+ mkdir '$(1).test-cmake'
+ cd '$(1).test-cmake' && '$(TARGET)-cmake' \
+ -DPKG=$(PKG) \
+ '$(PWD)/src/cmake/test'
+ $(MAKE) -C '$(1).test-cmake' -j 1 install
endef
$(PKG)_BUILD_SHARED =