changeset 30612:d93865ec84d9

Expand our test for purple_email_is_valid(). I stumbled across a large list of valid and invalid email address and thought it'd make a good test. The ones that are commented out belong in their respective list, but our validate function doesn't catch them. I don't plan on changing our validate function, though. If anyone else wants to... more power to ya
author Mark Doliner <mark@kingant.net>
date Mon, 14 Jun 2010 21:05:47 +0000
parents cd891a88a8fb
children 3a627563ca71
files libpurple/tests/test_util.c
diffstat 1 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/tests/test_util.c	Mon Jun 14 15:59:18 2010 +0000
+++ b/libpurple/tests/test_util.c	Mon Jun 14 21:05:47 2010 +0000
@@ -66,8 +66,57 @@
 }
 END_TEST
 
+/*
+ * Lists of valid and invalid email addresses comes from
+ * http://fightingforalostcause.net/misc/2006/compare-email-regex.php
+ */
+const char *valid_emails[] = {
+	"l3tt3rsAndNumb3rs@domain.com",
+	"has-dash@domain.com",
+	"hasApostrophe.o'leary@domain.org",
+	"uncommonTLD@domain.museum",
+	"uncommonTLD@domain.travel",
+	"uncommonTLD@domain.mobi",
+	"countryCodeTLD@domain.uk",
+	"countryCodeTLD@domain.rw",
+	"lettersInDomain@911.com",
+	"underscore_inLocal@domain.net",
+	"IPInsteadOfDomain@127.0.0.1",
+	/* "IPAndPort@127.0.0.1:25", */
+	"subdomain@sub.domain.com",
+	"local@dash-inDomain.com",
+	"dot.inLocal@foo.com",
+	"a@singleLetterLocal.org",
+	"singleLetterDomain@x.org",
+	"&*=?^+{}'~@validCharsInLocal.net",
+	"foor@bar.newTLD"
+};
+
+const char *invalid_emails[] = {
+	"missingDomain@.com",
+	"@missingLocal.org",
+	"missingatSign.net",
+	"missingDot@com",
+	"two@@signs.com",
+	"colonButNoPort@127.0.0.1:",
+	""
+	/* "someone-else@127.0.0.1.26", */
+	/* ".localStartsWithDot@domain.com", */
+	/* "localEndsWithDot.@domain.com", */
+	/* "two..consecutiveDots@domain.com", */
+	/* "domainStartsWithDash@-domain.com", */
+	"domainEndsWithDash@domain-.com",
+	/* "numbersInTLD@domain.c0m", */
+	/* "missingTLD@domain.", */
+	"! \"#$%(),/;<>[]`|@invalidCharsInLocal.org",
+	"invalidCharsInDomain@! \"#$%(),/;<>_[]`|.org",
+	/* "local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org" */
+};
+
 START_TEST(test_util_email_is_valid)
 {
+	size_t i;
+
 	fail_unless(purple_email_is_valid("purple-devel@lists.sf.net"));
 	fail_if(purple_email_is_valid("purple-devel@@lists.sf.net"));
 	fail_if(purple_email_is_valid("purple@devel@lists.sf.net"));
@@ -77,6 +126,12 @@
 	fail_if(purple_email_is_valid("@lists.sf.net"));
 	fail_if(purple_email_is_valid(""));
 	fail_if(purple_email_is_valid("totally bogus"));
+
+	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++)
+		fail_if(purple_email_is_valid(invalid_emails[i]), "Email address was: %s", invalid_emails[i]);
 }
 END_TEST