00001 /* 00002 * $Id: test_di_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_di_string.c - Test di_string 00031 * 00032 * Description: 00033 * This is a short test module to check the functions in the code that 00034 * constructs an INSERT 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 * TestDisCreate - Test Dis Routines 00054 * 00055 * Description: 00056 * Constructs a database INSERT statement and checks the string so 00057 * constructed. 00058 -*/ 00059 00060 static void TestDisCreate(void) 00061 { 00062 char* sql = NULL; 00063 00064 static const char* TEST = 00065 "INSERT INTO TEST VALUES (NULL, 1, 'ALPHA', NULL)"; 00066 00067 sql = DisInit("TEST"); 00068 DisAppendInt(&sql, 1); 00069 DisAppendString(&sql, "ALPHA"); 00070 DisAppendString(&sql, NULL); 00071 DisEnd(&sql); 00072 00073 CU_ASSERT_STRING_EQUAL(sql, TEST); 00074 DisFree(sql); 00075 00076 return; 00077 } 00078 00079 00080 /*+ 00081 * TestDis - Create Test Suite 00082 * 00083 * Description: 00084 * Adds the test suite to the CUnit test registry and adds all the tests 00085 * to it. 00086 * 00087 * Arguments: 00088 * None. 00089 * 00090 * Returns: 00091 * int 00092 * Return status. 0 => Success. 00093 */ 00094 00095 int TestDis(void); /* Declaration */ 00096 int TestDis(void) 00097 { 00098 struct test_testdef tests[] = { 00099 {"TestDisCreate", TestDisCreate}, 00100 {NULL, NULL} 00101 }; 00102 00103 return TcuCreateSuite("Dis", NULL, NULL, tests); 00104 }