added unit test for identification_t.matches()
authorMartin Willi <martin@strongswan.org>
Mon, 6 Jul 2009 09:44:46 +0000 (11:44 +0200)
committerMartin Willi <martin@strongswan.org>
Mon, 6 Jul 2009 11:15:29 +0000 (13:15 +0200)
src/charon/plugins/unit_tester/tests.h
src/charon/plugins/unit_tester/tests/test_id.c

index c303da7..b99940c 100644 (file)
@@ -38,5 +38,6 @@ DEFINE_TEST("SSH agent", test_agent, FALSE)
 DEFINE_TEST("ID parts", test_id_parts, FALSE)
 DEFINE_TEST("ID wildcards", test_id_wildcards, FALSE)
 DEFINE_TEST("ID equals", test_id_equals, FALSE)
+DEFINE_TEST("ID matches", test_id_matches, FALSE)
 
 /** @}*/
index 9dc7e7d..a1ef76b 100644 (file)
@@ -193,4 +193,57 @@ bool test_id_equals()
        return TRUE;
 }
 
+/*******************************************************************************
+ * identification matches test
+ ******************************************************************************/
+
+static id_match_t test_id_matches_one(identification_t *a, char *b_str)
+{
+       identification_t *b;
+       id_match_t match;
+       
+       b = identification_create_from_string(b_str);
+       match = a->matches(a, b);
+       b->destroy(b);
+       return match;
+}
 
+bool test_id_matches()
+{
+       identification_t *a;
+       
+       a = identification_create_from_string(
+                                                          "C=CH, E=martin@strongswan.org, CN=martin");
+       
+       if (test_id_matches_one(a, "C=CH, E=martin@strongswan.org, CN=martin")
+                                                                                                                       != ID_MATCH_PERFECT)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=CH, E=*, CN=martin") != ID_MATCH_ONE_WILDCARD)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=CH, E=*, CN=*") != ID_MATCH_ONE_WILDCARD - 1)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=*, E=*, CN=*") != ID_MATCH_ONE_WILDCARD - 2)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=*, E=*, CN=*, O=BADInc") != ID_MATCH_NONE)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=*, E=*") != ID_MATCH_NONE)
+       {
+               return FALSE;
+       }
+       if (test_id_matches_one(a, "C=*, E=a@b.c, CN=*") != ID_MATCH_NONE)
+       {
+               return FALSE;
+       }
+       a->destroy(a);
+       return TRUE;
+}