OpenDNSSEC-enforcer  1.4.7
test_di_string.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_di_string.c - Test di_string
29  *
30  * Description:
31  * This is a short test module to check the functions in the code that
32  * constructs an INSERT statement.
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/database_statement.h"
46 #include "test_routines.h"
47 
48 
49 
50 /*+
51  * TestDisCreate - Test Dis Routines
52  *
53  * Description:
54  * Constructs a database INSERT statement and checks the string so
55  * constructed.
56 -*/
57 
58 static void TestDisCreate(void)
59 {
60  char* sql = NULL;
61 
62  static const char* TEST =
63  "INSERT INTO TEST VALUES (NULL, 1, 'ALPHA', NULL)";
64 
65  sql = DisInit("TEST");
66  DisAppendInt(&sql, 1);
67  DisAppendString(&sql, "ALPHA");
68  DisAppendString(&sql, NULL);
69  DisEnd(&sql);
70 
71  CU_ASSERT_STRING_EQUAL(sql, TEST);
72  DisFree(sql);
73 
74  return;
75 }
76 
77 
78 /*+
79  * TestDis - Create Test Suite
80  *
81  * Description:
82  * Adds the test suite to the CUnit test registry and adds all the tests
83  * to it.
84  *
85  * Arguments:
86  * None.
87  *
88  * Returns:
89  * int
90  * Return status. 0 => Success.
91  */
92 
93 int TestDis(void); /* Declaration */
94 int TestDis(void)
95 {
96  struct test_testdef tests[] = {
97  {"TestDisCreate", TestDisCreate},
98  {NULL, NULL}
99  };
100 
101  return TcuCreateSuite("Dis", NULL, NULL, tests);
102 }
int TestDis(void)
int TcuCreateSuite(const char *title, int(*init)(), int(*teardown)(), struct test_testdef *tests)
void DisAppendString(char **sql, const char *what)
Definition: di_string.c:142
void DisEnd(char **sql)
Definition: di_string.c:170
void DisFree(char *sql)
Definition: di_string.c:191
char * DisInit(const char *table)
Definition: di_string.c:65
void DisAppendInt(char **sql, int what)
Definition: di_string.c:131