pidgin: 74a81229: Expand our test for purple_email_is_vali...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Jun 14 17:10:40 EDT 2010


-----------------------------------------------------------------
Revision: 74a81229c626a318447546176d5b27a0197a44a4
Ancestor: b002aa7c53145ba5350bf1b2ed47059a4018c79a
Author: markdoliner at pidgin.im
Date: 2010-06-14T21:05:47
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/74a81229c626a318447546176d5b27a0197a44a4

Modified files:
        libpurple/tests/test_util.c

ChangeLog: 

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

-------------- next part --------------
============================================================
--- libpurple/tests/test_util.c	88da4e64dd0cc9050d58f8ec014f97b050692bb7
+++ libpurple/tests/test_util.c	4f0635a8b3688980eea70f2fb12af4a7e039499c
@@ -66,8 +66,57 @@ END_TEST
 }
 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 at domain.com",
+	"has-dash at domain.com",
+	"hasApostrophe.o'leary at domain.org",
+	"uncommonTLD at domain.museum",
+	"uncommonTLD at domain.travel",
+	"uncommonTLD at domain.mobi",
+	"countryCodeTLD at domain.uk",
+	"countryCodeTLD at domain.rw",
+	"lettersInDomain at 911.com",
+	"underscore_inLocal at domain.net",
+	"IPInsteadOfDomain at 127.0.0.1",
+	/* "IPAndPort at 127.0.0.1:25", */
+	"subdomain at sub.domain.com",
+	"local at dash-inDomain.com",
+	"dot.inLocal at foo.com",
+	"a at singleLetterLocal.org",
+	"singleLetterDomain at x.org",
+	"&*=?^+{}'~@validCharsInLocal.net",
+	"foor at bar.newTLD"
+};
+
+const char *invalid_emails[] = {
+	"missingDomain at .com",
+	"@missingLocal.org",
+	"missingatSign.net",
+	"missingDot at com",
+	"two@@signs.com",
+	"colonButNoPort at 127.0.0.1:",
+	""
+	/* "someone-else at 127.0.0.1.26", */
+	/* ".localStartsWithDot at domain.com", */
+	/* "localEndsWithDot. at domain.com", */
+	/* "two..consecutiveDots at domain.com", */
+	/* "domainStartsWithDash at -domain.com", */
+	"domainEndsWithDash at domain-.com",
+	/* "numbersInTLD at domain.c0m", */
+	/* "missingTLD at domain.", */
+	"! \"#$%(),/;<>[]`|@invalidCharsInLocal.org",
+	"invalidCharsInDomain@! \"#$%(),/;<>_[]`|.org",
+	/* "local at SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org" */
+};
+
 START_TEST(test_util_email_is_valid)
 {
+	size_t i;
+
 	fail_unless(purple_email_is_valid("purple-devel at lists.sf.net"));
 	fail_if(purple_email_is_valid("purple-devel@@lists.sf.net"));
 	fail_if(purple_email_is_valid("purple at devel@lists.sf.net"));
@@ -77,6 +126,12 @@ START_TEST(test_util_email_is_valid)
 	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
 


More information about the Commits mailing list