OpenDNSSEC-enforcer  1.4.1
test_ksm_zone.c
Go to the documentation of this file.
1 /*
2  * $Id: test_ksm_zone.c 3858 2010-09-01 15:05:02Z sion $
3  *
4  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 /*+
30  * Filename: test_ksm_zone.c - Test ksm_zone Module
31  *
32  * Description:
33  * This is a short test module to check the function in the Ksm Zone
34  * module.
35  *
36  * The test program makes use of the CUnit framework, as described in
37  * http://cunit.sourceforge.net
38 -*/
39 
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <time.h>
44 
45 #include "CUnit/Basic.h"
46 
47 #include "ksm/ksm.h"
48 #include "test_routines.h"
49 
50 
51 /*+
52  * TestKsmZoneRead - Test
53  *
54  * Description:
55  * Tests that a zone can be returned
56 -*/
57 
58 static void TestKsmZoneRead(void)
59 {
60  int status; /* Status return */
61  int policy_id = 2;
62  DB_RESULT result;
63  KSM_ZONE* zone;
64 
65  zone = (KSM_ZONE *)malloc(sizeof(KSM_ZONE));
66 
67  /* Call KsmZoneInit */
68  status = KsmZoneInit(&result, policy_id);
69  CU_ASSERT_EQUAL(status, 0);
70 
71  /* get the first zone */
72  status = KsmZone(result, zone);
73  CU_ASSERT_EQUAL(status, 0);
74  CU_ASSERT_STRING_EQUAL(zone->name, "opendnssec.org");
75 
76  /* get the second zone */
77  status = KsmZone(result, zone);
78  CU_ASSERT_EQUAL(status, 0);
79  CU_ASSERT_STRING_EQUAL(zone->name, "opendnssec.se");
80 
81  DbFreeResult(result);
82 
83  free(zone);
84 }
85 
86 /*+
87  * TestKsmZoneIdFromName - Test
88  *
89  * Description:
90  * Tests that a zone can be returned
91 -*/
92 
93 static void TestKsmZoneIdFromName(void)
94 {
95  int status; /* Status return */
96  int zone_id; /* returned id */
97 
98  char* zone1 = "opendnssec.org";
99  char* zone2 = "opendnssec.se";
100 
101  /* get the first zone */
102  status = KsmZoneIdFromName(zone1, &zone_id);
103  CU_ASSERT_EQUAL(status, 0);
104  CU_ASSERT_EQUAL(zone_id, 1);
105 
106  /* get the first zone */
107  status = KsmZoneIdFromName(zone2, &zone_id);
108  CU_ASSERT_EQUAL(status, 0);
109  CU_ASSERT_EQUAL(zone_id, 2);
110 
111 }
112 
113 /*
114  * TestKsmZone - Create Test Suite
115  *
116  * Description:
117  * Adds the test suite to the CUnit test registry and adds all the tests
118  * to it.
119  *
120  * Arguments:
121  * None.
122  *
123  * Returns:
124  * int
125  * Return status. 0 => Success.
126  */
127 
128 int TestKsmZone(void); /* Declaration */
129 int TestKsmZone(void)
130 {
131  struct test_testdef tests[] = {
132  {"KsmZone", TestKsmZoneRead},
133  {"KsmZoneIdFromName", TestKsmZoneIdFromName},
134  {NULL, NULL}
135  };
136 
137  /* TODO
138  * have been a bit lazy here and reuse TdbSetup etc...
139  * this has the consequence of all the setups running for each suite
140  * if this gets too slow then we will need to separate them out
141  * */
142  return TcuCreateSuite("KsmZone", TdbSetup, TdbTeardown, tests);
143 }
void DbFreeResult(DB_RESULT result)
char name[KSM_ZONE_NAME_LENGTH]
Definition: ksm.h:286
int KsmZoneInit(DB_RESULT *handle, int policy_id)
Definition: ksm_zone.c:68
int TcuCreateSuite(const char *title, int(*init)(), int(*teardown)(), struct test_testdef *tests)
int KsmZone(DB_RESULT handle, KSM_ZONE *data)
Definition: ksm_zone.c:152
int KsmZoneIdFromName(const char *zone_name, int *zone_id)
Definition: ksm_zone.c:249
int TdbTeardown(void)
int TdbSetup(void)
Definition: ksm.h:283
int TestKsmZone(void)