• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

/srv/bpo/opendnssec/opendnssec-1.3.2/enforcer/test/cunit/test_dd_string.c

Go to the documentation of this file.
00001 /*
00002  * $Id: test_dd_string.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_dd_string.c - Test dd_string
00031  *
00032  * Description:
00033  *      This is a short test module to check the functions in the code that
00034  *      constructs a DELETE statement.
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/database_statement.h"
00048 #include "test_routines.h"
00049 
00050 
00051 
00052 /*+
00053  * TestDdsBasic - Test Basic Dds Routines
00054  *
00055  * Description:
00056  *      Constructs a database DELETE statement and checks the string so
00057  *      constructed.
00058 -*/
00059 
00060 static void TestDdsBasic(void)
00061 {
00062         char*   sql = NULL;
00063 
00064         sql = DdsInit("TEST");
00065         DdsEnd(&sql);
00066 
00067         CU_ASSERT_STRING_EQUAL(sql, "DELETE FROM TEST");
00068         DdsFree(sql);
00069 
00070         return;
00071 }
00072 
00073 /*+
00074  * TestDdsConditionInt - Test Conditional
00075  *
00076  * Description:
00077  *              Checks that the deletion can be constrained by a WHERE clause comparing
00078  *              fields to integers.
00079 -*/
00080 
00081 static void TestDdsConditionInt(void)
00082 {
00083         char*   sql = NULL;
00084         int             clause = 0;
00085 
00086         sql = DdsInit("TEST");
00087         DdsConditionInt(&sql, "ALPHA", DQS_COMPARE_LT, 1, clause++);
00088         DdsConditionInt(&sql, "BETA", DQS_COMPARE_LE, 2, clause++);
00089         DdsConditionInt(&sql, "GAMMA", DQS_COMPARE_EQ, 3, clause++);
00090         DdsConditionInt(&sql, "DELTA", DQS_COMPARE_NE, 4, clause++);
00091         DdsConditionInt(&sql, "EPSILON", DQS_COMPARE_GE, 5, clause++);
00092         DdsConditionInt(&sql, "ZETA", DQS_COMPARE_GT, 6, clause++);
00093         DdsEnd(&sql);
00094 
00095         CU_ASSERT_STRING_EQUAL(sql,
00096                 "DELETE FROM TEST WHERE ALPHA < 1 AND BETA <= 2 AND GAMMA = 3 "
00097                 "AND DELTA != 4 AND EPSILON >= 5 AND ZETA > 6");
00098         DdsFree(sql);
00099 
00100         return;
00101 }
00102 
00103 /*+
00104  * TestDdsConditionString - Test Conditional
00105  *
00106  * Description:
00107  *              Checks that the deletion can be constrained by a WHERE clause comparing
00108  *              fields to strings.
00109 -*/
00110 
00111 static void TestDdsConditionString(void)
00112 {
00113         char*   sql = NULL;
00114         int             clause = 0;
00115         static const char* TEST = 
00116                 "DELETE FROM TEST WHERE ALPHA < \"PETER\" AND BETA <= \"PIPER\" "
00117                 "AND GAMMA = \"PICKED\" AND DELTA != \"A\" AND EPSILON >= \"PECK\" "
00118                 "AND ZETA > \"OF\"";
00119 
00120         sql = DdsInit("TEST");
00121         DdsConditionString(&sql, "ALPHA", DQS_COMPARE_LT, "PETER", clause++);
00122         DdsConditionString(&sql, "BETA", DQS_COMPARE_LE, "PIPER", clause++);
00123         DdsConditionString(&sql, "GAMMA", DQS_COMPARE_EQ, "PICKED", clause++);
00124         DdsConditionString(&sql, "DELTA", DQS_COMPARE_NE, "A", clause++);
00125         DdsConditionString(&sql, "EPSILON", DQS_COMPARE_GE, "PECK", clause++);
00126         DdsConditionString(&sql, "ZETA", DQS_COMPARE_GT, "OF", clause++);
00127         DdsEnd(&sql);
00128 
00129         CU_ASSERT_STRING_EQUAL(sql, TEST);
00130         DdsFree(sql);
00131 
00132         return;
00133 }
00134 
00135 /*+
00136  * TestDdsConditionKeyword - Test Conditional
00137  *
00138  * Description:
00139  *              Checks that the deletion can be constrained by a WHERE clause comprising
00140  *              an IN clause.
00141 -*/
00142 
00143 
00144 static void TestDdsConditionKeyword(void)
00145 {
00146         char*   sql = NULL;
00147         int             clause = 0;
00148         static const char* TEST = 
00149                 "DELETE FROM TEST WHERE ALPHA IN (1, 2, 3) "
00150                 "AND BETA IN (\"ALEPH\", \"BETH\")";
00151 
00152         sql = DdsInit("TEST");
00153         DdsConditionKeyword(&sql, "ALPHA", DQS_COMPARE_IN, "(1, 2, 3)", clause++);
00154         DdsConditionKeyword(&sql, "BETA", DQS_COMPARE_IN, "(\"ALEPH\", \"BETH\")",
00155                 clause++);
00156         DdsEnd(&sql);
00157 
00158         CU_ASSERT_STRING_EQUAL(sql, TEST);
00159         DdsFree(sql);
00160 
00161         return;
00162 }
00163 
00164 
00165 /*+
00166  * TestDds  - Create Test Suite
00167  *
00168  * Description:
00169  *      Adds the test suite to the CUnit test registry and adds all the tests
00170  *      to it.
00171  *
00172  * Arguments:
00173  *      None.
00174  *
00175  * Returns:
00176  *      int
00177  *          Return status.  0 => Success.
00178  */
00179 
00180 int TestDds(void);      /* Declaration */
00181 int TestDds(void)
00182 {
00183     struct test_testdef tests[] = {
00184         {"TestDdsBasic",                        TestDdsBasic},
00185         {"TestDdsConditionInt",         TestDdsConditionInt},
00186         {"TestDdsConditionString",      TestDdsConditionString},
00187         {"TestDdsConditionKeyword",     TestDdsConditionKeyword},
00188         {NULL,                      NULL}
00189     };
00190 
00191     return TcuCreateSuite("Dds", NULL, NULL, tests);
00192 }

Generated on Mon Oct 31 2011 14:38:30 for OpenDNSSEC-enforcer by  doxygen 1.7.1