00001 /* 00002 * $Id: test_ksm_purge.c 3811 2010-08-26 15:05:19Z 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_purge.c - Test Key Purge Module 00031 * 00032 * Description: 00033 * This is a short test module to check the function in the Ksm Purge 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 * TestKsmPurgeInternal - Test Key Purge code 00053 * 00054 * Description: 00055 * Tests that all dead keys are removed when requested 00056 -*/ 00057 00058 static void TestKsmPurgeInternal(void) 00059 { 00060 int rowcount; /* Number of rows returned */ 00061 char* sql; /* Constructed query */ 00062 char* sql2; /* Constructed query */ 00063 char* sql3; /* Constructed query */ 00064 int status; /* Status return */ 00065 int where = 0; /* WHERE clause count */ 00066 00067 /* Check that only one key is "dead" (STATE=6) */ 00068 00069 sql = DqsCountInit("dnsseckeys"); 00070 DqsConditionInt(&sql, "STATE", DQS_COMPARE_EQ, 6, where++); 00071 StrAppend(&sql, " group by id"); 00072 DqsEnd(&sql); 00073 status = DbIntQuery(DbHandle(), &rowcount, sql); 00074 DqsFree(sql); 00075 00076 CU_ASSERT_EQUAL(status, 0); 00077 CU_ASSERT_EQUAL(rowcount, 1); 00078 00079 /* With 2 entries in dnsseckeys */ 00080 where = 0; 00081 sql2 = DqsCountInit("dnsseckeys"); 00082 DqsConditionInt(&sql2, "keypair_id", DQS_COMPARE_EQ, 1, where++); 00083 DqsEnd(&sql2); 00084 status = DbIntQuery(DbHandle(), &rowcount, sql2); 00085 00086 CU_ASSERT_EQUAL(status, 0); 00087 CU_ASSERT_EQUAL(rowcount, 2); 00088 00089 00090 /* Call KsmPurge */ 00091 KsmPurge(); 00092 00093 /* Now make sure that we have no dead keys */ 00094 sql3 = DqsCountInit("dnsseckeys"); 00095 DqsConditionInt(&sql3, "STATE", DQS_COMPARE_EQ, 6, 0); 00096 status = DbIntQuery(DbHandle(), &rowcount, sql3); 00097 DqsFree(sql3); 00098 00099 CU_ASSERT_EQUAL(status, 0); 00100 00101 CU_ASSERT_EQUAL(rowcount, 0); 00102 00103 /* Make sure that the entries in dnsseckeys have gone too */ 00104 status = DbIntQuery(DbHandle(), &rowcount, sql2); 00105 DqsFree(sql2); 00106 00107 CU_ASSERT_EQUAL(status, 0); 00108 CU_ASSERT_EQUAL(rowcount, 0); 00109 00110 } 00111 00112 /* 00113 * TestKsmPurge - Create Test Suite 00114 * 00115 * Description: 00116 * Adds the test suite to the CUnit test registry and adds all the tests 00117 * to it. 00118 * 00119 * Arguments: 00120 * None. 00121 * 00122 * Returns: 00123 * int 00124 * Return status. 0 => Success. 00125 */ 00126 00127 int TestKsmPurge(void); /* Declaration */ 00128 int TestKsmPurge(void) 00129 { 00130 struct test_testdef tests[] = { 00131 {"KsmPurge", TestKsmPurgeInternal}, 00132 {NULL, NULL} 00133 }; 00134 00135 /* TODO 00136 * have been a bit lazy here and reuse TdbSetup etc... 00137 * this has the consequence of all the setups running for each suite 00138 * if this gets too slow then we will need to separate them out 00139 * */ 00140 return TcuCreateSuite("KsmPurge", TdbSetup, TdbTeardown, tests); 00141 }