00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00054
00055
00056
00057
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
00075
00076
00077
00078
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
00105
00106
00107
00108
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
00137
00138
00139
00140
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
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 int TestDds(void);
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 }