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 TestDqsBasic(void)
00061 {
00062 char* sql = NULL;
00063
00064 sql = DqsInit("TEST");
00065 DqsEnd(&sql);
00066
00067 CU_ASSERT_STRING_EQUAL(sql, "SELECT * FROM TEST");
00068 DqsFree(sql);
00069
00070 sql = DqsCountInit("TEST");
00071 DqsEnd(&sql);
00072
00073 CU_ASSERT_STRING_EQUAL(sql, "SELECT COUNT(*) FROM TEST");
00074 DqsFree(sql);
00075
00076 return;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 static void TestDqsConditionInt(void)
00088 {
00089 char* sql = NULL;
00090 int clause = 0;
00091
00092 sql = DqsCountInit("TEST");
00093 DqsConditionInt(&sql, "ALPHA", DQS_COMPARE_LT, 1, clause++);
00094 DqsConditionInt(&sql, "BETA", DQS_COMPARE_LE, 2, clause++);
00095 DqsConditionInt(&sql, "GAMMA", DQS_COMPARE_EQ, 3, clause++);
00096 DqsConditionInt(&sql, "DELTA", DQS_COMPARE_NE, 4, clause++);
00097 DqsConditionInt(&sql, "EPSILON", DQS_COMPARE_GE, 5, clause++);
00098 DqsConditionInt(&sql, "ZETA", DQS_COMPARE_GT, 6, clause++);
00099 DqsEnd(&sql);
00100
00101 CU_ASSERT_STRING_EQUAL(sql,
00102 "SELECT COUNT(*) FROM TEST WHERE ALPHA < 1 AND BETA <= 2 AND GAMMA = 3 "
00103 "AND DELTA != 4 AND EPSILON >= 5 AND ZETA > 6");
00104 DqsFree(sql);
00105
00106 return;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 static void TestDqsConditionString(void)
00118 {
00119 char* sql = NULL;
00120 int clause = 0;
00121 static const char* TEST =
00122 "SELECT * FROM TEST WHERE ALPHA < \"PETER\" AND BETA <= \"PIPER\" "
00123 "AND GAMMA = \"PICKED\" AND DELTA != \"A\" AND EPSILON >= \"PECK\" "
00124 "AND ZETA > \"OF\"";
00125
00126 sql = DqsInit("TEST");
00127 DqsConditionString(&sql, "ALPHA", DQS_COMPARE_LT, "PETER", clause++);
00128 DqsConditionString(&sql, "BETA", DQS_COMPARE_LE, "PIPER", clause++);
00129 DqsConditionString(&sql, "GAMMA", DQS_COMPARE_EQ, "PICKED", clause++);
00130 DqsConditionString(&sql, "DELTA", DQS_COMPARE_NE, "A", clause++);
00131 DqsConditionString(&sql, "EPSILON", DQS_COMPARE_GE, "PECK", clause++);
00132 DqsConditionString(&sql, "ZETA", DQS_COMPARE_GT, "OF", clause++);
00133 DqsEnd(&sql);
00134
00135 CU_ASSERT_STRING_EQUAL(sql, TEST);
00136 DqsFree(sql);
00137
00138 return;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 static void TestDqsConditionKeyword(void)
00151 {
00152 char* sql = NULL;
00153 int clause = 0;
00154 static const char* TEST =
00155 "SELECT * FROM TEST WHERE ALPHA IN (1, 2, 3) "
00156 "AND BETA IN (\"ALEPH\", \"BETH\")";
00157
00158 sql = DqsInit("TEST");
00159 DqsConditionKeyword(&sql, "ALPHA", DQS_COMPARE_IN, "(1, 2, 3)", clause++);
00160 DqsConditionKeyword(&sql, "BETA", DQS_COMPARE_IN, "(\"ALEPH\", \"BETH\")",
00161 clause++);
00162 DqsEnd(&sql);
00163
00164 CU_ASSERT_STRING_EQUAL(sql, TEST);
00165 DqsFree(sql);
00166
00167 return;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 static void TestDqsOrderBy(void)
00180 {
00181 char* sql = NULL;
00182 int clause = 0;
00183 static const char* TEST =
00184 "SELECT * FROM TEST WHERE ALPHA IN (1, 2, 3) ORDER BY BETA";
00185
00186 sql = DqsInit("TEST");
00187 DqsConditionKeyword(&sql, "ALPHA", DQS_COMPARE_IN, "(1, 2, 3)", clause++);
00188 DqsOrderBy(&sql, "BETA");
00189 DqsEnd(&sql);
00190
00191 CU_ASSERT_STRING_EQUAL(sql, TEST);
00192 DqsFree(sql);
00193
00194 return;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 int TestDqs(void);
00214 int TestDqs(void)
00215 {
00216 struct test_testdef tests[] = {
00217 {"TestDqsBasic", TestDqsBasic},
00218 {"TestDqsConditionInt", TestDqsConditionInt},
00219 {"TestDqsConditionString", TestDqsConditionString},
00220 {"TestDqsConditionKeyword", TestDqsConditionKeyword},
00221 {"TestDqsOrderBy", TestDqsOrderBy},
00222 {NULL, NULL}
00223 };
00224
00225 return TcuCreateSuite("Dqs", NULL, NULL, tests);
00226 }