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