OpenDNSSEC-enforcer
1.3.8
|
00001 /* 00002 * $Id: test_ksm_parameter.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_parameter.c - Test Key Parameter Module 00031 * 00032 * Description: 00033 * This is a short test module to check the functions in the Ksm Parameter 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 "ksm/db_fields.h" 00049 #include "test_routines.h" 00050 00051 00052 /*+ 00053 * TestKsmParameterSet - Test Parameter Set code 00054 * 00055 * Description: 00056 * Tests that a parameter can be set 00057 -*/ 00058 00059 static void TestKsmParameterSet(void) 00060 { 00061 char* sql; /* Constructed query */ 00062 int status; /* Status return */ 00063 int where = 0; /* WHERE clause count */ 00064 char buffer[2]; /* User buffer */ 00065 DB_RESULT result; /* Result object */ 00066 DB_ROW row; /* Row object */ 00067 00068 /* Check that a genuine parameter can be set (for the first time) */ 00069 status = KsmParameterSet("Blah","Test", 2, 2); 00070 CU_ASSERT_EQUAL(status, 0); 00071 00072 sql = DqsSpecifyInit("PARAMETER_VIEW", DB_PARAMETER_VIEW_FIELDS); 00073 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, "Blah", where++); 00074 DqsConditionString(&sql, "CATEGORY", DQS_COMPARE_EQ, "Test", where++); 00075 DqsEnd(&sql); 00076 status = DbExecuteSql(DbHandle(), sql, &result); 00077 CU_ASSERT_EQUAL(status, 0); 00078 DqsFree(sql); 00079 00080 status = DbFetchRow(result, &row); 00081 CU_ASSERT_EQUAL(status, 0); 00082 status = DbStringBuffer(row, DB_PARAMETER_VALUE, buffer, sizeof(buffer)); 00083 CU_ASSERT_EQUAL(status, 0); 00084 CU_ASSERT_STRING_EQUAL(buffer, "2"); 00085 00086 DbFreeRow(row); 00087 DbFreeResult(result); 00088 00089 /* Check that an existing parameter can be overwritten */ 00090 status = KsmParameterSet("Blah2", "Test", 2, 2); 00091 CU_ASSERT_EQUAL(status, 0); 00092 00093 where = 0; 00094 sql = DqsSpecifyInit("PARAMETER_VIEW", DB_PARAMETER_VIEW_FIELDS); 00095 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, "Blah2", where++); 00096 DqsConditionString(&sql, "CATEGORY", DQS_COMPARE_EQ, "Test", where++); 00097 DqsEnd(&sql); 00098 status = DbExecuteSql(DbHandle(), sql, &result); 00099 CU_ASSERT_EQUAL(status, 0); 00100 DqsFree(sql); 00101 00102 status = DbFetchRow(result, &row); 00103 CU_ASSERT_EQUAL(status, 0); 00104 status = DbStringBuffer(row, DB_PARAMETER_VALUE, buffer, sizeof(buffer)); 00105 CU_ASSERT_EQUAL(status, 0); 00106 CU_ASSERT_STRING_EQUAL(buffer, "2"); 00107 00108 /* Check that a non-existing parameter can not be */ 00109 status = KsmParameterSet("Blah3", "Test", 2, 2); 00110 CU_ASSERT_EQUAL(status, 65548); /* Parameter doesn't exist */ 00111 00112 DbFreeRow(row); 00113 DbFreeResult(result); 00114 } 00115 00116 /*+ 00117 * TestKsmParameterShow - Test Parameter Show code 00118 * 00119 * Description: 00120 * Tests that a parameter can be shown 00121 -*/ 00122 00123 static void TestKsmParameterShow(void) 00124 { 00125 int status; /* Status return */ 00126 00127 /* 00128 * Check that an existing parameter can be shown 00129 * not sure how useful this is as a test 00130 */ 00131 status = KsmParameterShow("Blah", "Test", 2); 00132 CU_ASSERT_EQUAL(status, 0); 00133 00134 } 00135 00136 /* 00137 * TestKsmParameter - Create Test Suite 00138 * 00139 * Description: 00140 * Adds the test suite to the CUnit test registry and adds all the tests 00141 * to it. 00142 * 00143 * Arguments: 00144 * None. 00145 * 00146 * Returns: 00147 * int 00148 * Return status. 0 => Success. 00149 */ 00150 00151 int TestKsmParameter(void); /* Declaration */ 00152 int TestKsmParameter(void) 00153 { 00154 struct test_testdef tests[] = { 00155 {"KsmParameterSet", TestKsmParameterSet}, 00156 {"KsmParameterShow", TestKsmParameterShow}, 00157 {NULL, NULL} 00158 }; 00159 00160 /* TODO 00161 * have been a bit lazy here and reuse TdbSetup etc... 00162 * this has the consequence of all the setups running for each suite 00163 * if this gets too slow then we will need to separate them out 00164 * */ 00165 return TcuCreateSuite("KsmParameter", TdbSetup, TdbTeardown, tests); 00166 }