/pidgin/main: fce4d896285e: Add a bunch of util tests
Gary Kramlich
grim at reaperworld.com
Wed Mar 30 19:25:27 EDT 2016
Changeset: fce4d896285e32aab2c0be3f4904e80dfffea0c6
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2016-03-10 22:33 -0600
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/fce4d896285e
Description:
Add a bunch of util tests
diffstat:
libpurple/tests/.hgignore | 1 +
libpurple/tests/Makefile.am | 6 +-
libpurple/tests/test_util.c | 625 +++++++++++++++++++++++--------------------
3 files changed, 342 insertions(+), 290 deletions(-)
diffs (truncated from 745 to 300 lines):
diff --git a/libpurple/tests/.hgignore b/libpurple/tests/.hgignore
--- a/libpurple/tests/.hgignore
+++ b/libpurple/tests/.hgignore
@@ -3,6 +3,7 @@ syntax: regexp
^test_sha(1|256)$
^test_des3?$
^test_hmac$
+^test_util$
syntax: glob
*.log
diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am
--- a/libpurple/tests/Makefile.am
+++ b/libpurple/tests/Makefile.am
@@ -12,7 +12,8 @@ test_programs=\
test_md4 \
test_md5 \
test_sha1 \
- test_sha256
+ test_sha256 \
+ test_util
test_des_SOURCES=test_des.c
@@ -36,6 +37,9 @@ test_sha1_LDADD=$(COMMON_LIBS)
test_sha256_SOURCES=test_sha256.c
test_sha256_LDADD=$(COMMON_LIBS)
+test_util_SOURCES=test_util.c
+test_util_LDADD=$(COMMON_LIBS)
+
AM_CPPFLAGS = \
-I$(top_srcdir)/libpurple \
-I$(top_builddir)/libpurple \
diff --git a/libpurple/tests/test_util.c b/libpurple/tests/test_util.c
--- a/libpurple/tests/test_util.c
+++ b/libpurple/tests/test_util.c
@@ -1,76 +1,86 @@
-#include <string.h>
+#include <glib.h>
-#include "tests.h"
#include "../util.h"
-START_TEST(test_util_base16_encode)
-{
- assert_string_equal_free("68656c6c6f2c20776f726c642100", purple_base16_encode((const unsigned char *)"hello, world!", 14));
+/******************************************************************************
+ * base 16 tests
+ *****************************************************************************/
+static void
+test_util_base_16_encode(void) {
+ gchar *in = purple_base16_encode((const guchar *)"hello, world!", 14);
+ g_assert_cmpstr("68656c6c6f2c20776f726c642100", ==, in);
}
-END_TEST
-START_TEST(test_util_base16_decode)
-{
+static void
+test_util_base_16_decode(void) {
gsize sz = 0;
guchar *out = purple_base16_decode("21646c726f77202c6f6c6c656800", &sz);
- fail_unless(sz == 14, NULL);
- assert_string_equal_free("!dlrow ,olleh", (char *)out);
+
+ g_assert_cmpint(sz, ==, 14);
+ g_assert_cmpstr("!dlrow ,olleh", ==, (const gchar *)out);
}
-END_TEST
-START_TEST(test_util_base64_encode)
-{
- assert_string_equal_free("Zm9ydHktdHdvAA==", purple_base64_encode((const unsigned char *)"forty-two", 10));
+/******************************************************************************
+ * base 64 tests
+ *****************************************************************************/
+static void
+test_util_base_64_encode(void) {
+ gchar *in = purple_base64_encode((const unsigned char *)"forty-two", 10);
+ g_assert_cmpstr("Zm9ydHktdHdvAA==", ==, in);
}
-END_TEST
-START_TEST(test_util_base64_decode)
-{
- gsize sz;
+static void
+test_util_base_64_decode(void) {
+ gsize sz = 0;
guchar *out = purple_base64_decode("b3d0LXl0cm9mAA==", &sz);
- fail_unless(sz == 10, NULL);
- assert_string_equal_free("owt-ytrof", (char *)out);
+
+ g_assert_cmpint(sz, ==, 10);
+ g_assert_cmpstr("owt-ytrof", ==, (gchar *)out);
}
-END_TEST
-START_TEST(test_util_escape_filename)
-{
- assert_string_equal("foo", purple_escape_filename("foo"));
- assert_string_equal("@oo", purple_escape_filename("@oo"));
- assert_string_equal("#oo", purple_escape_filename("#oo"));
- assert_string_equal("-oo", purple_escape_filename("-oo"));
- assert_string_equal("_oo", purple_escape_filename("_oo"));
- assert_string_equal(".oo", purple_escape_filename(".oo"));
- assert_string_equal("%25oo", purple_escape_filename("%oo"));
- assert_string_equal("%21oo", purple_escape_filename("!oo"));
+/******************************************************************************
+ * filename escape tests
+ *****************************************************************************/
+static void
+test_util_filename_escape(void) {
+ g_assert_cmpstr("foo", ==, purple_escape_filename("foo"));
+ g_assert_cmpstr("@oo", ==, purple_escape_filename("@oo"));
+ g_assert_cmpstr("#oo", ==, purple_escape_filename("#oo"));
+ g_assert_cmpstr("-oo", ==, purple_escape_filename("-oo"));
+ g_assert_cmpstr("_oo", ==, purple_escape_filename("_oo"));
+ g_assert_cmpstr(".oo", ==, purple_escape_filename(".oo"));
+ g_assert_cmpstr("%25oo", ==, purple_escape_filename("%oo"));
+ g_assert_cmpstr("%21oo", ==, purple_escape_filename("!oo"));
}
-END_TEST
-START_TEST(test_util_unescape_filename)
-{
- assert_string_equal("bar", purple_unescape_filename("bar"));
- assert_string_equal("@ar", purple_unescape_filename("@ar"));
- assert_string_equal("!ar", purple_unescape_filename("!ar"));
- assert_string_equal("!ar", purple_unescape_filename("%21ar"));
- assert_string_equal("%ar", purple_unescape_filename("%25ar"));
+static void
+test_util_filename_unescape(void) {
+ g_assert_cmpstr("bar", ==, purple_unescape_filename("bar"));
+ g_assert_cmpstr("@ar", ==, purple_unescape_filename("@ar"));
+ g_assert_cmpstr("!ar", ==, purple_unescape_filename("!ar"));
+ g_assert_cmpstr("!ar", ==, purple_unescape_filename("%21ar"));
+ g_assert_cmpstr("%ar", ==, purple_unescape_filename("%25ar"));
}
-END_TEST
-
-START_TEST(test_util_text_strip_mnemonic)
-{
- assert_string_equal_free("", purple_text_strip_mnemonic(""));
- assert_string_equal_free("foo", purple_text_strip_mnemonic("foo"));
- assert_string_equal_free("foo", purple_text_strip_mnemonic("_foo"));
+/******************************************************************************
+ * text_strip tests
+ *****************************************************************************/
+static void
+test_util_text_strip_mnemonic(void) {
+ g_assert_cmpstr("", ==, purple_text_strip_mnemonic(""));
+ g_assert_cmpstr("foo", ==, purple_text_strip_mnemonic("foo"));
+ g_assert_cmpstr("foo", ==, purple_text_strip_mnemonic("_foo"));
}
-END_TEST
+/******************************************************************************
+ * email tests
+ *****************************************************************************/
/*
* Many of the valid and invalid email addresses lised below are from
* http://fightingforalostcause.net/misc/2006/compare-email-regex.php
*/
-const char *valid_emails[] = {
+const gchar *valid_emails[] = {
"purple-devel at lists.sf.net",
"l3tt3rsAndNumb3rs at domain.com",
"has-dash at domain.com",
@@ -95,7 +105,15 @@ const char *valid_emails[] = {
"HenryThe__WhiteCricket at hotmail.com"
};
-const char *invalid_emails[] = {
+static void
+test_util_email_is_valid(void) {
+ size_t i;
+
+ for (i = 0; i < G_N_ELEMENTS(valid_emails); i++)
+ g_assert_true(purple_email_is_valid(valid_emails[i]));
+}
+
+const gchar *invalid_emails[] = {
"purple-devel@@lists.sf.net",
"purple at devel@lists.sf.net",
"purple-devel at list..sf.net",
@@ -123,235 +141,259 @@ const char *invalid_emails[] = {
/* "local at SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org" */
};
-START_TEST(test_util_email_is_valid)
-{
+static void
+test_util_email_is_invalid(void) {
size_t i;
- for (i = 0; i < G_N_ELEMENTS(valid_emails); i++)
- fail_unless(purple_email_is_valid(valid_emails[i]), "Email address was: %s", valid_emails[i]);
+ for (i = 0; i < G_N_ELEMENTS(invalid_emails); i++)
+ g_assert_false(purple_email_is_valid(invalid_emails[i]));
+}
- for (i = 0; i < G_N_ELEMENTS(invalid_emails); i++)
- fail_if(purple_email_is_valid(invalid_emails[i]), "Email address was: %s", invalid_emails[i]);
+/******************************************************************************
+ * ipv6 tests
+ *****************************************************************************/
+static void
+test_util_ipv6_is_valid(void) {
+ g_assert_true(purple_ipv6_address_is_valid("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
+ g_assert_true(purple_ipv6_address_is_valid("2001:db8:85a3:0:0:8a2e:370:7334"));
+ g_assert_true(purple_ipv6_address_is_valid("2001:db8:85a3::8a2e:370:7334"));
+ g_assert_true(purple_ipv6_address_is_valid("2001:0db8:0:0::1428:57ab"));
+ g_assert_true(purple_ipv6_address_is_valid("::1"));
+ g_assert_true(purple_ipv6_address_is_valid("1::"));
+ g_assert_true(purple_ipv6_address_is_valid("1::1"));
+ g_assert_true(purple_ipv6_address_is_valid("::"));
}
-END_TEST
-START_TEST(test_util_ipv6_is_valid)
-{
- fail_unless(purple_ipv6_address_is_valid("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
- fail_unless(purple_ipv6_address_is_valid("2001:db8:85a3:0:0:8a2e:370:7334"));
- fail_unless(purple_ipv6_address_is_valid("2001:db8:85a3::8a2e:370:7334"));
- fail_unless(purple_ipv6_address_is_valid("2001:0db8:0:0::1428:57ab"));
- fail_unless(purple_ipv6_address_is_valid("::1"));
- fail_unless(purple_ipv6_address_is_valid("1::"));
- fail_unless(purple_ipv6_address_is_valid("1::1"));
- fail_unless(purple_ipv6_address_is_valid("::"));
- fail_if(purple_ipv6_address_is_valid(""));
- fail_if(purple_ipv6_address_is_valid(":"));
- fail_if(purple_ipv6_address_is_valid("1.2.3.4"));
- fail_if(purple_ipv6_address_is_valid("2001::FFD3::57ab"));
- fail_if(purple_ipv6_address_is_valid("200000000::1"));
- fail_if(purple_ipv6_address_is_valid("QWERTY::1"));
+static void
+test_util_ipv6_is_invalid(void) {
+ g_assert_false(purple_ipv6_address_is_valid(""));
+ g_assert_false(purple_ipv6_address_is_valid(":"));
+ g_assert_false(purple_ipv6_address_is_valid("1.2.3.4"));
+ g_assert_false(purple_ipv6_address_is_valid("2001::FFD3::57ab"));
+ g_assert_false(purple_ipv6_address_is_valid("200000000::1"));
+ g_assert_false(purple_ipv6_address_is_valid("QWERTY::1"));
}
-END_TEST
-START_TEST(test_util_str_to_time)
-{
+/******************************************************************************
+ * str_to_time tests
+ *****************************************************************************/
+static void
+test_util_str_to_time(void) {
struct tm tm;
- long tz_off;
- const char *rest;
+ glong tz_off;
+ const gchar *rest;
time_t timestamp;
- fail_unless(377182200 == purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL));
- fail_unless(1175919261 == purple_str_to_time("20070407T04:14:21", TRUE, NULL, NULL, NULL));
- fail_unless(1282941722 == purple_str_to_time("2010-08-27.204202", TRUE, NULL, NULL, NULL));
+ g_assert_cmpint(377182200, ==, purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL));
+ g_assert_cmpint(1175919261, ==, purple_str_to_time("20070407T04:14:21", TRUE, NULL, NULL, NULL));
+ g_assert_cmpint(1282941722, ==, purple_str_to_time("2010-08-27.204202", TRUE, NULL, NULL, NULL));
timestamp = purple_str_to_time("2010-08-27.134202-0700PDT", FALSE, &tm, &tz_off, &rest);
- fail_unless(1282941722 == timestamp);
- fail_unless((-7 * 60 * 60) == tz_off);
- assert_string_equal("PDT", rest);
+ g_assert_cmpint(1282941722, ==, timestamp);
+ g_assert_cmpint((-7 * 60 * 60), ==, tz_off);
+ g_assert_cmpstr("PDT", ==, rest);
}
-END_TEST
-START_TEST(test_markup_html_to_xhtml)
-{
- gchar *xhtml = NULL;
- gchar *plaintext = NULL;
+/******************************************************************************
+ * Markup tests
+ *****************************************************************************/
+typedef struct {
+ gchar *markup;
+ gchar *xhtml;
+ gchar *plaintext;
+} MarkupTestData;
- purple_markup_html_to_xhtml("<a>", &xhtml, &plaintext);
- assert_string_equal_free("<a href=\"\"></a>", xhtml);
- assert_string_equal_free("", plaintext);
+static void
+test_util_markup_html_to_xhtml(void) {
+ gint i;
More information about the Commits
mailing list