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 "ksm/db_fields.h"
00049 #include "test_routines.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 static void TestKsmImportRepository(void)
00061 {
00062 char* sql = NULL;
00063 int status = 0;
00064 int count = 0;
00065
00066 char* repo_name = "myNewRepo";
00067 char* repo_capacity = "500";
00068
00069
00070 sql = DqsCountInit(DB_SECURITY_MODULE_TABLE);
00071 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, repo_name, 0);
00072 DqsEnd(&sql);
00073
00074
00075 status = DbIntQuery(DbHandle(), &count, sql);
00076 CU_ASSERT_EQUAL(status, 0);
00077 CU_ASSERT_EQUAL(count, 0);
00078
00079
00080 status = KsmImportRepository(repo_name, repo_capacity, 0);
00081 CU_ASSERT_EQUAL(status, 0);
00082
00083
00084 status = DbIntQuery(DbHandle(), &count, sql);
00085 DqsFree(sql);
00086 CU_ASSERT_EQUAL(status, 0);
00087 CU_ASSERT_EQUAL(count, 1);
00088
00089
00090 sql = DqsSpecifyInit(DB_SECURITY_MODULE_TABLE,"capacity");
00091 DqsConditionString(&sql, "name", DQS_COMPARE_EQ, repo_name, 0);
00092 DqsEnd(&sql);
00093
00094 status = DbIntQuery(DbHandle(), &count, sql);
00095 CU_ASSERT_EQUAL(status, 0);
00096 CU_ASSERT_EQUAL(count, 500);
00097
00098
00099 status = KsmImportRepository(repo_name, "5000", 0);
00100 CU_ASSERT_EQUAL(status, 0);
00101
00102
00103 status = DbIntQuery(DbHandle(), &count, sql);
00104 DqsFree(sql);
00105 CU_ASSERT_EQUAL(status, 0);
00106 CU_ASSERT_EQUAL(count, 5000);
00107
00108
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 static void TestKsmImportPolicy(void)
00118 {
00119 char* sql = NULL;
00120 int status = 0;
00121 int count = 0;
00122
00123 char* policy_name = "myNewPolicy";
00124 char* policy_desc = "Pretty policy";
00125
00126
00127 sql = DqsCountInit("policies");
00128 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, policy_name, 0);
00129 DqsEnd(&sql);
00130
00131
00132 status = DbIntQuery(DbHandle(), &count, sql);
00133 CU_ASSERT_EQUAL(status, 0);
00134 CU_ASSERT_EQUAL(count, 0);
00135
00136
00137 status = KsmImportPolicy(policy_name, policy_desc);
00138 CU_ASSERT_EQUAL(status, 0);
00139
00140
00141 status = DbIntQuery(DbHandle(), &count, sql);
00142 DqsFree(sql);
00143 CU_ASSERT_EQUAL(status, 0);
00144 CU_ASSERT_EQUAL(count, 1);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 static void TestKsmImportZone(void)
00156 {
00157 char* sql = NULL;
00158 int status = 0;
00159 int count = 0;
00160
00161 char* zone_name = "myNewZone.test";
00162 int policy_id = 1;
00163 int new_zone = 0;
00164
00165
00166 sql = DqsCountInit(DB_ZONE_TABLE);
00167 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, zone_name, 0);
00168 DqsEnd(&sql);
00169
00170
00171 status = DbIntQuery(DbHandle(), &count, sql);
00172 CU_ASSERT_EQUAL(status, 0);
00173 CU_ASSERT_EQUAL(count, 0);
00174
00175
00176 status = KsmImportZone(zone_name, policy_id, 1, &new_zone, "signconf", "input", "output");
00177 CU_ASSERT_EQUAL(status, 0);
00178 CU_ASSERT_EQUAL(new_zone, 1);
00179
00180
00181 status = DbIntQuery(DbHandle(), &count, sql);
00182 DqsFree(sql);
00183 CU_ASSERT_EQUAL(status, 0);
00184 CU_ASSERT_EQUAL(count, 1);
00185
00186
00187 sql = DqsSpecifyInit(DB_ZONE_TABLE,"policy_id");
00188 DqsConditionString(&sql, "name", DQS_COMPARE_EQ, zone_name, 0);
00189 DqsEnd(&sql);
00190
00191 status = DbIntQuery(DbHandle(), &count, sql);
00192 CU_ASSERT_EQUAL(status, 0);
00193 CU_ASSERT_EQUAL(count, 1);
00194
00195
00196 status = KsmImportZone(zone_name, 2, 0, &new_zone, "signconf", "input", "output");
00197 CU_ASSERT_EQUAL(status, 0);
00198 CU_ASSERT_EQUAL(new_zone, 0);
00199
00200
00201 status = DbIntQuery(DbHandle(), &count, sql);
00202 DqsFree(sql);
00203 CU_ASSERT_EQUAL(status, 0);
00204 CU_ASSERT_EQUAL(count, 2);
00205
00206
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216 static void TestKsmSerialIdFromName(void)
00217 {
00218 int status;
00219 int serial_id;
00220
00221 char* serial1 = "unixtime";
00222 char* serial2 = "somethingElse";
00223
00224
00225 status = KsmSerialIdFromName(serial1, &serial_id);
00226 CU_ASSERT_EQUAL(status, 0);
00227 CU_ASSERT_EQUAL(serial_id, 1);
00228
00229
00230 status = KsmSerialIdFromName(serial2, &serial_id);
00231 CU_ASSERT_EQUAL(status, 65557);
00232
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 int TestKsmImport(void);
00251 int TestKsmImport(void)
00252 {
00253 struct test_testdef tests[] = {
00254 {"KsmImportRepository", TestKsmImportRepository},
00255 {"KsmImportPolicy", TestKsmImportPolicy},
00256 {"KsmImportZone", TestKsmImportZone},
00257 {"KsmSerialIdFromName", TestKsmSerialIdFromName},
00258 {NULL, NULL}
00259 };
00260
00261
00262
00263
00264
00265
00266 return TcuCreateSuite("KsmImport", TdbSetup, TdbTeardown, tests);
00267 }