unit-tests: Test for equality against some empty data identities
authorMartin Willi <martin@revosec.ch>
Tue, 8 Oct 2013 12:34:41 +0000 (14:34 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 31 Oct 2013 20:57:07 +0000 (21:57 +0100)
src/libstrongswan/tests/test_identification.c

index 54a0ba0..43e3ff6 100644 (file)
@@ -476,6 +476,48 @@ START_TEST(test_equals_fqdn)
 }
 END_TEST
 
+START_TEST(test_equals_empty)
+{
+       identification_t *a;
+
+       a = identification_create_from_encoding(_i, chunk_empty);
+
+       switch (_i)
+       {
+               case ID_ANY:
+                       ck_assert(id_equals(a, "%any"));
+                       break;
+               case ID_IPV4_ADDR:
+                       ck_assert(!id_equals(a, "192.168.1.1"));
+                       break;
+               case ID_FQDN:
+                       ck_assert(!id_equals(a, "moon.strongswan.org"));
+                       break;
+               case ID_USER_FQDN:
+                       ck_assert(!id_equals(a, "moon@strongswan.org"));
+                       break;
+               case ID_IPV6_ADDR:
+                       ck_assert(!id_equals(a, "fec0::1"));
+                       break;
+               case ID_DER_ASN1_DN:
+                       ck_assert(!id_equals(a, "C=CH, E=moon@strongswan.org, CN=moon"));
+                       break;
+               case ID_KEY_ID:
+                       ck_assert(!id_equals(a, "@#12345678"));
+                       break;
+               case ID_DER_ASN1_GN:
+               case ID_IPV4_ADDR_SUBNET:
+               case ID_IPV6_ADDR_SUBNET:
+               case ID_IPV4_ADDR_RANGE:
+               case ID_IPV6_ADDR_RANGE:
+                       /* currently not tested */
+                       break;
+       }
+
+       a->destroy(a);
+}
+END_TEST
+
 /*******************************************************************************
  * matches
  */
@@ -690,6 +732,7 @@ Suite *identification_suite_create()
        tcase_add_test(tc, test_equals_any);
        tcase_add_test(tc, test_equals_binary);
        tcase_add_test(tc, test_equals_fqdn);
+       tcase_add_loop_test(tc, test_equals_empty, ID_ANY, ID_KEY_ID + 1);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("matches");