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 TestDusSetInt(void)
00061 {
00062 char* sql = NULL;
00063 int set = 0;
00064
00065
00066
00067 set = 0;
00068 sql = DusInit("TEST");
00069 DusSetInt(&sql, "ALPHA", 1, set++);
00070 DusEnd(&sql);
00071
00072 CU_ASSERT_STRING_EQUAL(sql, "UPDATE TEST SET ALPHA = 1");
00073 DusFree(sql);
00074
00075
00076
00077 set = 0;
00078 sql = DusInit("TEST");
00079 DusSetInt(&sql, "ALPHA", 1, set++);
00080 DusSetInt(&sql, "BETA", 2, set++);
00081 DusEnd(&sql);
00082
00083 CU_ASSERT_STRING_EQUAL(sql, "UPDATE TEST SET ALPHA = 1, BETA = 2");
00084 DusFree(sql);
00085
00086 return;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 static void TestDusSetString(void)
00100 {
00101 char* sql = NULL;
00102 int set = 0;
00103
00104
00105
00106 set = 0;
00107 sql = DusInit("TEST");
00108 DusSetString(&sql, "ALPHA", "XYZZY", set++);
00109 DusEnd(&sql);
00110
00111 CU_ASSERT_STRING_EQUAL(sql, "UPDATE TEST SET ALPHA = \"XYZZY\"");
00112 DusFree(sql);
00113
00114
00115
00116 set = 0;
00117 sql = DusInit("TEST");
00118 DusSetString(&sql, "BETA", NULL, set++);
00119 DusEnd(&sql);
00120
00121 CU_ASSERT_STRING_EQUAL(sql, "UPDATE TEST SET BETA = NULL");
00122 DusFree(sql);
00123
00124
00125
00126 set = 0;
00127 sql = DusInit("TEST");
00128 DusSetString(&sql, "ALPHA", "XYZZY", set++);
00129 DusSetString(&sql, "BETA", NULL, set++);
00130 DusEnd(&sql);
00131
00132 CU_ASSERT_STRING_EQUAL(sql,
00133 "UPDATE TEST SET ALPHA = \"XYZZY\", BETA = NULL");
00134 DusFree(sql);
00135
00136 return;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 static void TestDusConditionInt(void)
00148 {
00149 char* sql = NULL;
00150 int set = 0;
00151 int where = 0;
00152 static const char* TEST =
00153 "UPDATE TEST SET ALPHA = 0 WHERE ALPHA < 1 AND BETA <= 2 AND GAMMA = 3 "
00154 "AND DELTA != 4 AND EPSILON >= 5 AND ZETA > 6";
00155
00156 sql = DusInit("TEST");
00157 DusSetInt(&sql, "ALPHA", 0, set++);
00158 DusConditionInt(&sql, "ALPHA", DQS_COMPARE_LT, 1, where++);
00159 DusConditionInt(&sql, "BETA", DQS_COMPARE_LE, 2, where++);
00160 DusConditionInt(&sql, "GAMMA", DQS_COMPARE_EQ, 3, where++);
00161 DusConditionInt(&sql, "DELTA", DQS_COMPARE_NE, 4, where++);
00162 DusConditionInt(&sql, "EPSILON", DQS_COMPARE_GE, 5, where++);
00163 DusConditionInt(&sql, "ZETA", DQS_COMPARE_GT, 6, where++);
00164 DusEnd(&sql);
00165
00166 CU_ASSERT_STRING_EQUAL(sql, TEST);
00167 DusFree(sql);
00168
00169 return;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 static void TestDusConditionString(void)
00181 {
00182 char* sql = NULL;
00183 int set = 0;
00184 int where = 0;
00185 static const char* TEST =
00186 "UPDATE TEST SET ALPHA = 0 "
00187 "WHERE ALPHA < \"PETER\" AND BETA <= \"PIPER\" "
00188 "AND GAMMA = \"PICKED\" AND DELTA != \"A\" AND EPSILON >= \"PECK\" "
00189 "AND ZETA > \"OF\"";
00190
00191 sql = DusInit("TEST");
00192 DusSetInt(&sql, "ALPHA", 0, set++);
00193 DusConditionString(&sql, "ALPHA", DQS_COMPARE_LT, "PETER", where++);
00194 DusConditionString(&sql, "BETA", DQS_COMPARE_LE, "PIPER", where++);
00195 DusConditionString(&sql, "GAMMA", DQS_COMPARE_EQ, "PICKED", where++);
00196 DusConditionString(&sql, "DELTA", DQS_COMPARE_NE, "A", where++);
00197 DusConditionString(&sql, "EPSILON", DQS_COMPARE_GE, "PECK", where++);
00198 DusConditionString(&sql, "ZETA", DQS_COMPARE_GT, "OF", where++);
00199 DusEnd(&sql);
00200
00201 CU_ASSERT_STRING_EQUAL(sql, TEST);
00202 DusFree(sql);
00203
00204 return;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 static void TestDusConditionKeyword(void)
00217 {
00218 char* sql = NULL;
00219 int set = 0;
00220 int where = 0;
00221 static const char* TEST =
00222 "UPDATE TEST SET ALPHA = 0, BETA = \"GIMMEL\" WHERE ALPHA IN (1, 2, 3) "
00223 "AND BETA IN (\"ALEPH\", \"BETH\")";
00224
00225 sql = DusInit("TEST");
00226 DusSetInt(&sql, "ALPHA", 0, set++);
00227 DusSetString(&sql, "BETA", "GIMMEL", set++);
00228 DusConditionKeyword(&sql, "ALPHA", DQS_COMPARE_IN, "(1, 2, 3)", where++);
00229 DusConditionKeyword(&sql, "BETA", DQS_COMPARE_IN, "(\"ALEPH\", \"BETH\")",
00230 where++);
00231 DusEnd(&sql);
00232
00233 CU_ASSERT_STRING_EQUAL(sql, TEST);
00234 DusFree(sql);
00235
00236 return;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 int TestDus(void);
00256 int TestDus(void)
00257 {
00258 struct test_testdef tests[] = {
00259 {"TestDusSetInt", TestDusSetInt},
00260 {"TestDusSetString", TestDusSetString},
00261 {"TestDusConditionInt", TestDusConditionInt},
00262 {"TestDusConditionString", TestDusConditionString},
00263 {"TestDusConditionKeyword", TestDusConditionKeyword},
00264 {NULL, NULL}
00265 };
00266
00267 return TcuCreateSuite("Dus", NULL, NULL, tests);
00268 }