OpenDNSSEC-enforcer
1.3.8
|
00001 /* 00002 * $Id: test_ksm_zone.c 3858 2010-09-01 15:05:02Z sion $ 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_zone.c - Test ksm_zone Module 00031 * 00032 * Description: 00033 * This is a short test module to check the function in the Ksm Zone 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 * TestKsmZoneRead - Test 00053 * 00054 * Description: 00055 * Tests that a zone can be returned 00056 -*/ 00057 00058 static void TestKsmZoneRead(void) 00059 { 00060 int status; /* Status return */ 00061 int policy_id = 2; 00062 DB_RESULT result; 00063 KSM_ZONE* zone; 00064 00065 zone = (KSM_ZONE *)malloc(sizeof(KSM_ZONE)); 00066 00067 /* Call KsmZoneInit */ 00068 status = KsmZoneInit(&result, policy_id); 00069 CU_ASSERT_EQUAL(status, 0); 00070 00071 /* get the first zone */ 00072 status = KsmZone(result, zone); 00073 CU_ASSERT_EQUAL(status, 0); 00074 CU_ASSERT_STRING_EQUAL(zone->name, "opendnssec.org"); 00075 00076 /* get the second zone */ 00077 status = KsmZone(result, zone); 00078 CU_ASSERT_EQUAL(status, 0); 00079 CU_ASSERT_STRING_EQUAL(zone->name, "opendnssec.se"); 00080 00081 DbFreeResult(result); 00082 00083 free(zone); 00084 } 00085 00086 /*+ 00087 * TestKsmZoneIdFromName - Test 00088 * 00089 * Description: 00090 * Tests that a zone can be returned 00091 -*/ 00092 00093 static void TestKsmZoneIdFromName(void) 00094 { 00095 int status; /* Status return */ 00096 int zone_id; /* returned id */ 00097 00098 char* zone1 = "opendnssec.org"; 00099 char* zone2 = "opendnssec.se"; 00100 00101 /* get the first zone */ 00102 status = KsmZoneIdFromName(zone1, &zone_id); 00103 CU_ASSERT_EQUAL(status, 0); 00104 CU_ASSERT_EQUAL(zone_id, 1); 00105 00106 /* get the first zone */ 00107 status = KsmZoneIdFromName(zone2, &zone_id); 00108 CU_ASSERT_EQUAL(status, 0); 00109 CU_ASSERT_EQUAL(zone_id, 2); 00110 00111 } 00112 00113 /* 00114 * TestKsmZone - Create Test Suite 00115 * 00116 * Description: 00117 * Adds the test suite to the CUnit test registry and adds all the tests 00118 * to it. 00119 * 00120 * Arguments: 00121 * None. 00122 * 00123 * Returns: 00124 * int 00125 * Return status. 0 => Success. 00126 */ 00127 00128 int TestKsmZone(void); /* Declaration */ 00129 int TestKsmZone(void) 00130 { 00131 struct test_testdef tests[] = { 00132 {"KsmZone", TestKsmZoneRead}, 00133 {"KsmZoneIdFromName", TestKsmZoneIdFromName}, 00134 {NULL, NULL} 00135 }; 00136 00137 /* TODO 00138 * have been a bit lazy here and reuse TdbSetup etc... 00139 * this has the consequence of all the setups running for each suite 00140 * if this gets too slow then we will need to separate them out 00141 * */ 00142 return TcuCreateSuite("KsmZone", TdbSetup, TdbTeardown, tests); 00143 }