summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2023-09-29 20:24:16 +0300
committerdefanor <defanor@uberspace.net>2023-09-29 20:24:16 +0300
commitccdb748c81abc9bb30b8989e27d22bbbb219f9a0 (patch)
tree295be2ea605c8acbe56116ea3ce119b99e3e0440 /tests
parent04e6fd5194481798bc30abc7a690664d5af36aeb (diff)
Add more checks, tests, and documentation
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am25
-rw-r--r--tests/base64.c18
-rw-r--r--tests/send_to_self.c8
-rw-r--r--tests/xml_parse_and_print.c27
-rw-r--r--tests/xml_print_and_parse.c64
5 files changed, 126 insertions, 16 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 22290a5..93c0b82 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,19 +1,24 @@
AM_CFLAGS = -Werror -Wall -Wextra -pedantic -std=gnu99
-COMMON_FLAGS = $(AM_CFLAGS) $(LIBXML_CFLAGS) \
+COMMON_FLAGS = $(AM_CFLAGS) $(LIBXML_CFLAGS) $(EXPAT_CFLAGS) \
$(GNUTLS_CFLAGS) $(LIBDANE_CFLAGS) $(OPENSSL_CFLAGS) \
$(GSASL_CFLAGS) $(UNBOUND_CFLAGS) $(CARES_CFLAGS) $(GPGME_CFLAGS) \
$(ICU_I18N_CFLAGS) $(LIBGCRYPT_CFLAGS) $(CURL_CFLAGS) \
$(NICE_CFLAGS) $(GLIB_CFLAGS) $(SRTP_CFLAGS) \
- -I$(top_srcdir)/src
-COMMON_LIBS = $(LIBXML_LIBS) \
- $(GNUTLS_LIBS) $(LIBDANE_LIBS) $(OPENSSL_LIBS) \
- $(GSASL_LIBS) $(UNBOUND_LIBS) $(CARES_LIBS) $(GPGME_LIBS) $(ICU_I18N_LIBS) \
- $(LIBGCRYPT_LIBS) $(CURL_LIBS) $(NICE_LIBS) $(GLIB_LIBS) $(SRTP_LIBS) \
- -L$(top_builddir)/src -lrexmpp
+ $(PORTAUDIO_CFLAGS) $(OPUS_CFLAGS) $(NETTLE_CFLAGS)
+COMMON_LDADD = -L$(top_builddir)/src -lrexmpp
send_to_self_CFLAGS = $(COMMON_FLAGS)
-send_to_self_LDADD = $(COMMON_LIBS)
+xml_parse_and_print_CFLAGS = $(COMMON_FLAGS)
+xml_print_and_parse_CFLAGS = $(COMMON_FLAGS)
+base64_CFLAGS = $(COMMON_FLAGS)
-check_PROGRAMS = send_to_self
-TESTS = send_to_self
+send_to_self_LDADD = $(COMMON_LDADD)
+xml_parse_and_print_LDADD = $(COMMON_LDADD)
+xml_print_and_parse_LDADD = $(COMMON_LDADD)
+base64_LDADD = $(COMMON_LDADD)
+
+check_PROGRAMS = send_to_self \
+ xml_parse_and_print xml_print_and_parse base64
+TESTS = send_to_self \
+ xml_parse_and_print xml_print_and_parse base64
diff --git a/tests/base64.c b/tests/base64.c
new file mode 100644
index 0000000..b69ba0e
--- /dev/null
+++ b/tests/base64.c
@@ -0,0 +1,18 @@
+#include <string.h>
+#include "rexmpp_base64.h"
+
+int main () {
+ char *original_plain = "test string";
+ char *original_base64 = "dGVzdCBzdHJpbmc=";
+ char *encoded, *decoded;
+ size_t encoded_len, decoded_len;
+ if (rexmpp_base64_to(original_plain, strlen(original_plain),
+ &encoded, &encoded_len)) {
+ return -1;
+ }
+ if (rexmpp_base64_from(original_base64, strlen(original_base64),
+ &decoded, &decoded_len)) {
+ return -1;
+ }
+ return strcmp(original_plain, decoded) || strcmp(original_base64, encoded);
+}
diff --git a/tests/send_to_self.c b/tests/send_to_self.c
index b5d6d7e..2fcb80f 100644
--- a/tests/send_to_self.c
+++ b/tests/send_to_self.c
@@ -16,7 +16,6 @@ that it's the expected message.
#include <stdio.h>
#include <errno.h>
#include <syslog.h>
-#include <gsasl.h>
#include <rexmpp.h>
#include <rexmpp_sasl.h>
@@ -89,9 +88,7 @@ int my_xml_out_cb (rexmpp_t *s, rexmpp_xml_t *node) {
return 0;
}
-int main (int argc, char **argv) {
- (void)argc;
- (void)argv;
+int main () {
jid = getenv("JID");
pass = getenv("PASS");
char *tls_policy = getenv("TLS_POLICY");
@@ -143,8 +140,7 @@ int main (int argc, char **argv) {
if (stage == TEST_CONNECTING && s.stream_state == REXMPP_STREAM_READY) {
rexmpp_xml_t *msg =
- rexmpp_xml_add_id(&s,
- rexmpp_xml_new_elem("message", "jabber:client"));
+ rexmpp_xml_add_id(rexmpp_xml_new_elem("message", "jabber:client"));
rexmpp_xml_add_attr(msg, "to", jid);
rexmpp_xml_add_attr(msg, "type", "chat");
rexmpp_xml_t *body = rexmpp_xml_new_elem("body", NULL);
diff --git a/tests/xml_parse_and_print.c b/tests/xml_parse_and_print.c
new file mode 100644
index 0000000..ad6bbca
--- /dev/null
+++ b/tests/xml_parse_and_print.c
@@ -0,0 +1,27 @@
+#include <string.h>
+#include <stdlib.h>
+#include "rexmpp_xml.h"
+
+int main () {
+ int ret = 0;
+
+ char *str = "<foo bar=\"baz\">"
+ "<qux xmlns=\"urn:test\">a b c d</qux>"
+ "<quux e=\"f\" g=\"h\"/>"
+ "</foo>";
+ rexmpp_xml_t *xml = rexmpp_xml_parse (str, strlen(str));
+
+ if (xml == NULL) {
+ ret = -1;
+ } else {
+ char *str_new = rexmpp_xml_serialize (xml, 0);
+ if (str_new == NULL) {
+ ret = -2;
+ } else {
+ ret = strcmp(str, str_new);
+ free(str_new);
+ }
+ rexmpp_xml_free(xml);
+ }
+ return ret;
+}
diff --git a/tests/xml_print_and_parse.c b/tests/xml_print_and_parse.c
new file mode 100644
index 0000000..9bd7a3f
--- /dev/null
+++ b/tests/xml_print_and_parse.c
@@ -0,0 +1,64 @@
+#include <string.h>
+#include <stdlib.h>
+#include "rexmpp_xml.h"
+
+int main () {
+ int ret = 0;
+
+ rexmpp_xml_attr_t
+ foo_attributes = { .qname = {"bar", NULL},
+ .value = "baz",
+ .next = NULL },
+ quux_attributes_g = { .qname = {"g", NULL},
+ .value = "h",
+ .next = NULL },
+ quux_attributes =
+ { .qname = {"e", NULL},
+ .value = "f",
+ .next = &quux_attributes_g };
+ rexmpp_xml_t
+ quux = { .type = REXMPP_XML_ELEMENT,
+ .alt.elem =
+ { .qname = {"quux", NULL},
+ .attributes = &quux_attributes,
+ .children = NULL
+ },
+ .next = NULL
+ },
+ qux_text = { .type = REXMPP_XML_TEXT,
+ .alt.text = "a b c d",
+ .next = NULL },
+ qux = { .type = REXMPP_XML_ELEMENT,
+ .alt.elem =
+ { .qname = {"qux", "urn:dummy"},
+ .attributes = NULL,
+ .children = &qux_text
+ },
+ .next = &quux
+ },
+ xml =
+ { .type = REXMPP_XML_ELEMENT,
+ .alt.elem =
+ { .qname = {"foo", NULL},
+ .attributes = &foo_attributes,
+ .children = &qux
+ },
+ .next = NULL
+ };
+
+ char *str_new = rexmpp_xml_serialize (&xml, 0);
+ if (str_new == NULL) {
+ ret = -1;
+ } else {
+ rexmpp_xml_t *xml_new = rexmpp_xml_parse (str_new, strlen(str_new));
+ if (xml_new == NULL) {
+ ret = -2;
+ } else {
+ /* Compare the XML structures. */
+ ret = (rexmpp_xml_eq(&xml, xml_new) == 0);
+ rexmpp_xml_free(xml_new);
+ }
+ free(str_new);
+ }
+ return ret;
+}