OpenDNSSEC-enforcer 1.3.0
|
00001 /* 00002 * $Id: test_keyword.c 5320 2011-07-12 10:42:26Z jakob $ 00003 * 00004 * Copyright (c) 2008-2009 Nominet UK. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00029 /*+ 00030 * Filename: test_keyword.c - Test Keyword Module 00031 * 00032 * Description: 00033 * This is a short test module to check the functions in the keyword 00034 * module. 00035 * 00036 * The test program makes use of the CUnit framework, as described in 00037 * http://cunit.sourceforge.net 00038 -*/ 00039 00040 #include <stdlib.h> 00041 #include <stdio.h> 00042 #include <string.h> 00043 #include <time.h> 00044 00045 #include "CUnit/Basic.h" 00046 00047 #include "ksm/ksm.h" 00048 #include "test_routines.h" 00049 00050 00051 /*+ 00052 * Test<type>KeywordConvert - Test Keyword Conversion Code 00053 * 00054 * Description: 00055 * Tests the translation between the keywords and the values 00056 * for the different keyword sets. 00057 -*/ 00058 00059 static void TestAlgorithmKeywordConvert(void) 00060 { 00061 /* Name to value */ 00062 00063 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSAMD5, KsmKeywordAlgorithmNameToValue("rsamd5")); 00064 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSAMD5, KsmKeywordAlgorithmNameToValue("rsamd")); 00065 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSAMD5, KsmKeywordAlgorithmNameToValue("rsam")); 00066 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("rsa")); 00067 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("rs")); 00068 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("r")); 00069 00070 CU_ASSERT_EQUAL(KSM_ALGORITHM_DH, KsmKeywordAlgorithmNameToValue("dh")); 00071 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("d")); 00072 00073 CU_ASSERT_EQUAL(KSM_ALGORITHM_DSASHA1, KsmKeywordAlgorithmNameToValue("dsa")); 00074 /*CU_ASSERT_EQUAL(KSM_ALGORITHM_DSASHA1, KsmKeywordAlgorithmNameToValue("ds"));*/ 00075 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("d")); 00076 00077 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsasha1")); 00078 /*CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsasha")); 00079 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsash")); 00080 CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsas"));*/ 00081 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("rsa")); 00082 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("rs")); 00083 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("r")); 00084 00085 /* add tests for dsa-nsec3-sha1, rsasha1-nsec3-sha1, rsasha256, rsasha512 */ 00086 00087 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("indirect")); 00088 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("indirec")); 00089 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("indire")); 00090 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("indir")); 00091 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("indi")); 00092 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("ind")); 00093 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("in")); 00094 CU_ASSERT_EQUAL(KSM_ALGORITHM_INDIRECT, KsmKeywordAlgorithmNameToValue("i")); 00095 00096 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVDOM, KsmKeywordAlgorithmNameToValue("domain")); 00097 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVDOM, KsmKeywordAlgorithmNameToValue("domai")); 00098 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVDOM, KsmKeywordAlgorithmNameToValue("doma")); 00099 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVDOM, KsmKeywordAlgorithmNameToValue("dom")); 00100 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVDOM, KsmKeywordAlgorithmNameToValue("do")); 00101 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("d")); 00102 00103 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVOID, KsmKeywordAlgorithmNameToValue("oid")); 00104 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVOID, KsmKeywordAlgorithmNameToValue("oi")); 00105 CU_ASSERT_EQUAL(KSM_ALGORITHM_PRIVOID, KsmKeywordAlgorithmNameToValue("o")); 00106 00107 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("xyz")); 00108 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue("")); 00109 CU_ASSERT_EQUAL(0, KsmKeywordAlgorithmNameToValue(NULL)); 00110 00111 /* ... and the reverse */ 00112 00113 CU_ASSERT_STRING_EQUAL("rsamd5", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_RSAMD5)); 00114 CU_ASSERT_STRING_EQUAL("dh", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_DH)); 00115 CU_ASSERT_STRING_EQUAL("dsa", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_DSASHA1)); 00116 CU_ASSERT_STRING_EQUAL("rsasha1", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_RSASHA1)); 00117 CU_ASSERT_STRING_EQUAL("indirect", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_INDIRECT)); 00118 CU_ASSERT_STRING_EQUAL("domain", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_PRIVDOM)); 00119 CU_ASSERT_STRING_EQUAL("oid", KsmKeywordAlgorithmValueToName(KSM_ALGORITHM_PRIVOID)); 00120 00121 return; 00122 } 00123 00124 static void TestFormatKeywordConvert(void) 00125 { 00126 /* Name to value */ 00127 00128 CU_ASSERT_EQUAL(KSM_FORMAT_FILE, KsmKeywordFormatNameToValue("file")); 00129 CU_ASSERT_EQUAL(KSM_FORMAT_FILE, KsmKeywordFormatNameToValue("fil")); 00130 CU_ASSERT_EQUAL(KSM_FORMAT_FILE, KsmKeywordFormatNameToValue("fi")); 00131 CU_ASSERT_EQUAL(KSM_FORMAT_FILE, KsmKeywordFormatNameToValue("f")); 00132 00133 CU_ASSERT_EQUAL(KSM_FORMAT_HSM, KsmKeywordFormatNameToValue("hsm")); 00134 CU_ASSERT_EQUAL(KSM_FORMAT_HSM, KsmKeywordFormatNameToValue("hs")); 00135 CU_ASSERT_EQUAL(KSM_FORMAT_HSM, KsmKeywordFormatNameToValue("h")); 00136 00137 CU_ASSERT_EQUAL(KSM_FORMAT_URI, KsmKeywordFormatNameToValue("uri")); 00138 CU_ASSERT_EQUAL(KSM_FORMAT_URI, KsmKeywordFormatNameToValue("ur")); 00139 CU_ASSERT_EQUAL(KSM_FORMAT_URI, KsmKeywordFormatNameToValue("u")); 00140 00141 CU_ASSERT_EQUAL(0, KsmKeywordFormatNameToValue("xyz")); 00142 CU_ASSERT_EQUAL(0, KsmKeywordFormatNameToValue("")); 00143 CU_ASSERT_EQUAL(0, KsmKeywordFormatNameToValue(NULL)); 00144 00145 /* ... and the reverse */ 00146 00147 CU_ASSERT_STRING_EQUAL("file", KsmKeywordFormatValueToName(KSM_FORMAT_FILE)); 00148 CU_ASSERT_STRING_EQUAL("hsm", KsmKeywordFormatValueToName(KSM_FORMAT_HSM)); 00149 CU_ASSERT_STRING_EQUAL("uri", KsmKeywordFormatValueToName(KSM_FORMAT_URI)); 00150 00151 return; 00152 } 00153 00154 static void TestStateKeywordConvert(void) 00155 { 00156 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("generate")); 00157 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("generat")); 00158 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("genera")); 00159 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("gener")); 00160 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("gene")); 00161 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("gen")); 00162 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("ge")); 00163 CU_ASSERT_EQUAL(KSM_STATE_GENERATE, KsmKeywordStateNameToValue("g")); 00164 00165 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("publish")); 00166 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("publis")); 00167 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("publi")); 00168 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("publ")); 00169 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("pub")); 00170 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("pu")); 00171 CU_ASSERT_EQUAL(KSM_STATE_PUBLISH, KsmKeywordStateNameToValue("p")); 00172 00173 CU_ASSERT_EQUAL(KSM_STATE_READY, KsmKeywordStateNameToValue("ready")); 00174 CU_ASSERT_EQUAL(KSM_STATE_READY, KsmKeywordStateNameToValue("read")); 00175 CU_ASSERT_EQUAL(KSM_STATE_READY, KsmKeywordStateNameToValue("rea")); 00176 CU_ASSERT_EQUAL(0, KsmKeywordStateNameToValue("re")); /* Confused with "retired" */ 00177 CU_ASSERT_EQUAL(0, KsmKeywordStateNameToValue("r")); /* Confused with "retired" */ 00178 00179 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("active")); 00180 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("activ")); 00181 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("acti")); 00182 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("act")); 00183 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("ac")); 00184 CU_ASSERT_EQUAL(KSM_STATE_ACTIVE, KsmKeywordStateNameToValue("a")); 00185 00186 CU_ASSERT_EQUAL(KSM_STATE_RETIRE, KsmKeywordStateNameToValue("retire")); 00187 CU_ASSERT_EQUAL(KSM_STATE_RETIRE, KsmKeywordStateNameToValue("retir")); 00188 CU_ASSERT_EQUAL(KSM_STATE_RETIRE, KsmKeywordStateNameToValue("reti")); 00189 CU_ASSERT_EQUAL(KSM_STATE_RETIRE, KsmKeywordStateNameToValue("ret")); 00190 CU_ASSERT_EQUAL(0, KsmKeywordStateNameToValue("re")); /* Confused with "ready" */ 00191 CU_ASSERT_EQUAL(0, KsmKeywordStateNameToValue("r")); /* Confused with "ready" */ 00192 00193 CU_ASSERT_EQUAL(KSM_STATE_DEAD, KsmKeywordStateNameToValue("dead")); 00194 CU_ASSERT_EQUAL(KSM_STATE_DEAD, KsmKeywordStateNameToValue("dea")); 00195 CU_ASSERT_EQUAL(KSM_STATE_DEAD, KsmKeywordStateNameToValue("de")); 00196 CU_ASSERT_EQUAL(0, KsmKeywordStateNameToValue("d")); 00197 00198 /* ... and the reverse */ 00199 00200 CU_ASSERT_STRING_EQUAL("generate", KsmKeywordStateValueToName(KSM_STATE_GENERATE)); 00201 CU_ASSERT_STRING_EQUAL("publish", KsmKeywordStateValueToName(KSM_STATE_PUBLISH)); 00202 CU_ASSERT_STRING_EQUAL("ready", KsmKeywordStateValueToName(KSM_STATE_READY)); 00203 CU_ASSERT_STRING_EQUAL("active", KsmKeywordStateValueToName(KSM_STATE_ACTIVE)); 00204 CU_ASSERT_STRING_EQUAL("retire", KsmKeywordStateValueToName(KSM_STATE_RETIRE)); 00205 CU_ASSERT_STRING_EQUAL("dead", KsmKeywordStateValueToName(KSM_STATE_DEAD)); 00206 00207 return; 00208 } 00209 00210 static void TestTypeKeywordConvert(void) 00211 { 00212 CU_ASSERT_EQUAL(KSM_TYPE_KSK, KsmKeywordTypeNameToValue("ksk")); 00213 CU_ASSERT_EQUAL(KSM_TYPE_KSK, KsmKeywordTypeNameToValue("ks")); 00214 CU_ASSERT_EQUAL(KSM_TYPE_KSK, KsmKeywordTypeNameToValue("k")); 00215 00216 CU_ASSERT_EQUAL(KSM_TYPE_ZSK, KsmKeywordTypeNameToValue("zsk")); 00217 CU_ASSERT_EQUAL(KSM_TYPE_ZSK, KsmKeywordTypeNameToValue("zs")); 00218 CU_ASSERT_EQUAL(KSM_TYPE_ZSK, KsmKeywordTypeNameToValue("z")); 00219 00220 /* ... and the reverse */ 00221 00222 CU_ASSERT_STRING_EQUAL("ksk", KsmKeywordTypeValueToName(KSM_TYPE_KSK)); 00223 CU_ASSERT_STRING_EQUAL("zsk", KsmKeywordTypeValueToName(KSM_TYPE_ZSK)); 00224 00225 return; 00226 } 00227 00228 00229 00230 /* 00231 * TestKeyword - Create Test Suite 00232 * 00233 * Description: 00234 * Adds the test suite to the CUnit test registry and adds all the tests 00235 * to it. 00236 * 00237 * Arguments: 00238 * None. 00239 * 00240 * Returns: 00241 * int 00242 * Return status. 0 => Success. 00243 */ 00244 00245 int TestKeyword(void); /* Declaration */ 00246 int TestKeyword(void) 00247 { 00248 struct test_testdef tests[] = { 00249 {"AlgorithmKeywordConvert", TestAlgorithmKeywordConvert}, 00250 {"FormatKeywordConvert", TestFormatKeywordConvert}, 00251 {"StateKeywordConvert", TestStateKeywordConvert}, 00252 {"TypeKeywordConvert", TestTypeKeywordConvert}, 00253 {NULL, NULL} 00254 }; 00255 00256 return TcuCreateSuite("Keyword", NULL, NULL, tests); 00257 }