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/ksm.h"
00048 #include "test_routines.h"
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 static void TestKsmKeyDeleteRange(void)
00059 {
00060 char* sql;
00061 int status;
00062 int where = 0;
00063 int rowcount;
00064
00065
00066 sql = DqsCountInit("KEYDATA_VIEW");
00067 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 2, where++);
00068 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 5, where++);
00069 DqsEnd(&sql);
00070 status = DbIntQuery(DbHandle(), &rowcount, sql);
00071 CU_ASSERT_EQUAL(status, 0);
00072
00073 CU_ASSERT_EQUAL(rowcount, 2);
00074
00075
00076 status = KsmDeleteKeyRange(3, 4);
00077 CU_ASSERT_EQUAL(status, 0);
00078
00079
00080 status = DbIntQuery(DbHandle(), &rowcount, sql);
00081 CU_ASSERT_EQUAL(status, 0);
00082 DqsFree(sql);
00083
00084 CU_ASSERT_EQUAL(rowcount, 0);
00085
00086
00087 where = 0;
00088 sql = DqsCountInit("KEYDATA_VIEW");
00089 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 1, where++);
00090 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 7, where++);
00091 DqsEnd(&sql);
00092 status = DbIntQuery(DbHandle(), &rowcount, sql);
00093 CU_ASSERT_EQUAL(status, 0);
00094 DqsFree(sql);
00095
00096
00097 CU_ASSERT_EQUAL(rowcount, 6);
00098
00099
00100
00101
00102
00103 where = 0;
00104 sql = DqsCountInit("KEYDATA_VIEW");
00105 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 4, where++);
00106 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 7, where++);
00107 DqsEnd(&sql);
00108 status = DbIntQuery(DbHandle(), &rowcount, sql);
00109 CU_ASSERT_EQUAL(status, 0);
00110
00111 CU_ASSERT_EQUAL(rowcount, 2);
00112
00113
00114 status = KsmDeleteKeyRange(6, 5);
00115 CU_ASSERT_EQUAL(status, 0);
00116
00117
00118 status = DbIntQuery(DbHandle(), &rowcount, sql);
00119 CU_ASSERT_EQUAL(status, 0);
00120 DqsFree(sql);
00121
00122 CU_ASSERT_EQUAL(rowcount, 0);
00123
00124
00125 where = 0;
00126 sql = DqsCountInit("KEYDATA_VIEW");
00127 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 1, where++);
00128 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 7, where++);
00129 DqsEnd(&sql);
00130 status = DbIntQuery(DbHandle(), &rowcount, sql);
00131 CU_ASSERT_EQUAL(status, 0);
00132 DqsFree(sql);
00133
00134
00135 CU_ASSERT_EQUAL(rowcount, 4);
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 static void TestKsmKeyDeleteRanges(void)
00146 {
00147 char* sql;
00148 int status;
00149 int where = 0;
00150 int rowcount;
00151 int limit[4];
00152 int size;
00153
00154
00155 sql = DqsCountInit("KEYDATA_VIEW");
00156 DqsConditionInt(&sql, "ID", DQS_COMPARE_GT, 8, where++);
00157 DqsConditionInt(&sql, "ID", DQS_COMPARE_LT, 14, where++);
00158 DqsEnd(&sql);
00159 status = DbIntQuery(DbHandle(), &rowcount, sql);
00160 CU_ASSERT_EQUAL(status, 0);
00161
00162 CU_ASSERT_EQUAL(rowcount, 5);
00163
00164
00165 limit[0] = 9;
00166 limit[1] = 10;
00167 limit[2] = 13;
00168 limit[3] = 12;
00169 size = 4;
00170 status = KsmDeleteKeyRanges(limit, size);
00171 CU_ASSERT_EQUAL(status, 0);
00172
00173
00174 status = DbIntQuery(DbHandle(), &rowcount, sql);
00175 CU_ASSERT_EQUAL(status, 0);
00176 DqsFree(sql);
00177
00178 CU_ASSERT_EQUAL(rowcount, 1);
00179
00180
00181 where = 0;
00182 sql = DqsCountInit("KEYDATA_VIEW");
00183 DqsConditionInt(&sql, "ID", DQS_COMPARE_GE, 8, where++);
00184 DqsConditionInt(&sql, "ID", DQS_COMPARE_LE, 15, where++);
00185 DqsEnd(&sql);
00186 status = DbIntQuery(DbHandle(), &rowcount, sql);
00187 DqsFree(sql);
00188 CU_ASSERT_EQUAL(status, 0);
00189
00190 CU_ASSERT_EQUAL(rowcount, 4);
00191
00192 where = 0;
00193 sql = DqsCountInit("KEYDATA_VIEW");
00194 DqsConditionInt(&sql, "ID", DQS_COMPARE_EQ, 11, where++);
00195 DqsEnd(&sql);
00196 status = DbIntQuery(DbHandle(), &rowcount, sql);
00197 DqsFree(sql);
00198 CU_ASSERT_EQUAL(status, 0);
00199
00200 CU_ASSERT_EQUAL(rowcount, 1);
00201
00202
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 int TestKsmKeyDelete(void);
00221 int TestKsmKeyDelete(void)
00222 {
00223 struct test_testdef tests[] = {
00224 {"KsmKeyDeleteRange", TestKsmKeyDeleteRange},
00225 {"KsmKeyDeleteRanges", TestKsmKeyDeleteRanges},
00226 {NULL, NULL}
00227 };
00228
00229
00230
00231
00232
00233
00234 return TcuCreateSuite("KsmKeyDelete", TdbSetup, TdbTeardown, tests);
00235 }