OpenDNSSEC-enforcer 1.3.0
|
00001 /* 00002 * $Id: test_ksm_key_delete.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_ksm_key_delete.c - Test Key Delete Module 00031 * 00032 * Description: 00033 * This is a short test module to check the functions in the Ksm Key Delete 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 * TestKsmKeyDeleteRange - Test KsmDeleteKeyRange code 00053 * 00054 * Description: 00055 * Tests that a key range can be deleted 00056 -*/ 00057 00058 static void TestKsmKeyDeleteRange(void) 00059 { 00060 char* sql; /* Constructed query */ 00061 int status; /* Status return */ 00062 int where = 0; /* WHERE clause count */ 00063 int rowcount; /* Result */ 00064 00065 /* First check that the rows exist */ 00066 sql = DqsCountInit("KEYDATA_VIEW"); 00067 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 2, where++); 00068 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 5, where++); 00069 DqsEnd(&sql); 00070 status = DbIntQuery(DbHandle(), &rowcount, sql); 00071 CU_ASSERT_EQUAL(status, 0); 00072 00073 CU_ASSERT_EQUAL(rowcount, 2); 00074 00075 /* Delete some */ 00076 status = KsmDeleteKeyRange(3, 4); 00077 CU_ASSERT_EQUAL(status, 0); 00078 00079 /* Make sure that they have gone */ 00080 status = DbIntQuery(DbHandle(), &rowcount, sql); 00081 CU_ASSERT_EQUAL(status, 0); 00082 DqsFree(sql); 00083 00084 CU_ASSERT_EQUAL(rowcount, 0); 00085 00086 /* Check that no other keys were harmed */ 00087 where = 0; 00088 sql = DqsCountInit("KEYDATA_VIEW"); 00089 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 1, where++); 00090 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 7, where++); 00091 DqsEnd(&sql); 00092 status = DbIntQuery(DbHandle(), &rowcount, sql); 00093 CU_ASSERT_EQUAL(status, 0); 00094 DqsFree(sql); 00095 00096 /* 6 expected because key 1 has 2 instances */ 00097 CU_ASSERT_EQUAL(rowcount, 6); 00098 00099 /* 00100 * Start again, this time we will put min and max in the "wrong" way round 00101 * First check that the rows exist 00102 */ 00103 where = 0; 00104 sql = DqsCountInit("KEYDATA_VIEW"); 00105 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 4, where++); 00106 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 7, where++); 00107 DqsEnd(&sql); 00108 status = DbIntQuery(DbHandle(), &rowcount, sql); 00109 CU_ASSERT_EQUAL(status, 0); 00110 00111 CU_ASSERT_EQUAL(rowcount, 2); 00112 00113 /* Delete some */ 00114 status = KsmDeleteKeyRange(6, 5); 00115 CU_ASSERT_EQUAL(status, 0); 00116 00117 /* Make sure that they have gone */ 00118 status = DbIntQuery(DbHandle(), &rowcount, sql); 00119 CU_ASSERT_EQUAL(status, 0); 00120 DqsFree(sql); 00121 00122 CU_ASSERT_EQUAL(rowcount, 0); 00123 00124 /* Check that no other keys were harmed */ 00125 where = 0; 00126 sql = DqsCountInit("KEYDATA_VIEW"); 00127 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 1, where++); 00128 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 7, where++); 00129 DqsEnd(&sql); 00130 status = DbIntQuery(DbHandle(), &rowcount, sql); 00131 CU_ASSERT_EQUAL(status, 0); 00132 DqsFree(sql); 00133 00134 /* 4 expected because key 1 has 2 instances */ 00135 CU_ASSERT_EQUAL(rowcount, 4); 00136 } 00137 00138 /*+ 00139 * TestKsmKeyDeleteRanges - Test KsmDeleteKeyRanges code 00140 * 00141 * Description: 00142 * Tests that key ranges can be deleted 00143 -*/ 00144 00145 static void TestKsmKeyDeleteRanges(void) 00146 { 00147 char* sql; /* Constructed query */ 00148 int status; /* Status return */ 00149 int where = 0; /* WHERE clause count */ 00150 int rowcount; /* Result */ 00151 int limit[4]; /* ranges to delete */ 00152 int size; /* size of limit vector */ 00153 00154 /* First check that the rows exist */ 00155 sql = DqsCountInit("KEYDATA_VIEW"); 00156 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 8, where++); 00157 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 14, where++); 00158 DqsEnd(&sql); 00159 status = DbIntQuery(DbHandle(), &rowcount, sql); 00160 CU_ASSERT_EQUAL(status, 0); 00161 00162 CU_ASSERT_EQUAL(rowcount, 5); 00163 00164 /* Delete some */ 00165 limit[0] = 9; 00166 limit[1] = 10; 00167 limit[2] = 13; 00168 limit[3] = 12; 00169 size = 4; 00170 status = KsmDeleteKeyRanges(limit, size); 00171 CU_ASSERT_EQUAL(status, 0); 00172 00173 /* Make sure that they have gone */ 00174 status = DbIntQuery(DbHandle(), &rowcount, sql); 00175 CU_ASSERT_EQUAL(status, 0); 00176 DqsFree(sql); 00177 00178 CU_ASSERT_EQUAL(rowcount, 1); 00179 00180 /* Check that no other keys were harmed */ 00181 where = 0; 00182 sql = DqsCountInit("KEYDATA_VIEW"); 00183 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 8, where++); 00184 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 15, where++); 00185 DqsEnd(&sql); 00186 status = DbIntQuery(DbHandle(), &rowcount, sql); 00187 DqsFree(sql); 00188 CU_ASSERT_EQUAL(status, 0); 00189 00190 CU_ASSERT_EQUAL(rowcount, 4); 00191 00192 where = 0; 00193 sql = DqsCountInit("KEYDATA_VIEW"); 00194 DqsConditionInt(&sql, "ID", DQS_COMPARE_EQ, 11, where++); 00195 DqsEnd(&sql); 00196 status = DbIntQuery(DbHandle(), &rowcount, sql); 00197 DqsFree(sql); 00198 CU_ASSERT_EQUAL(status, 0); 00199 00200 CU_ASSERT_EQUAL(rowcount, 1); 00201 00202 /* TODO what happens if the limit vector is not set? */ 00203 } 00204 00205 /* 00206 * TestKsmKeyDelete - Create Test Suite 00207 * 00208 * Description: 00209 * Adds the test suite to the CUnit test registry and adds all the tests 00210 * to it. 00211 * 00212 * Arguments: 00213 * None. 00214 * 00215 * Returns: 00216 * int 00217 * Return status. 0 => Success. 00218 */ 00219 00220 int TestKsmKeyDelete(void); /* Declaration */ 00221 int TestKsmKeyDelete(void) 00222 { 00223 struct test_testdef tests[] = { 00224 {"KsmKeyDeleteRange", TestKsmKeyDeleteRange}, 00225 {"KsmKeyDeleteRanges", TestKsmKeyDeleteRanges}, 00226 {NULL, NULL} 00227 }; 00228 00229 /* TODO 00230 * have been a bit lazy here and reuse TdbSetup etc... 00231 * this has the consequence of all the setups running for each suite 00232 * if this gets too slow then we will need to separate them out 00233 * */ 00234 return TcuCreateSuite("KsmKeyDelete", TdbSetup, TdbTeardown, tests); 00235 }