8 #define paste(a,b) a ## b
9 #define _L(a) paste(L,a)
11 #define TRACE1 wprintf
13 /* Setup and Fakery ... */
14 osi_log_t * afsd_logp;
16 void cm_SetFid(cm_fid_t *fidp, afs_uint32 cell, afs_uint32 volume, afs_uint32 vnode, afs_uint32 unique)
19 fidp->volume = volume;
21 fidp->unique = unique;
22 fidp->hash = ((cell & 0xF) << 28) | ((volume & 0x3F) << 22) | ((vnode & 0x7FF) << 11) | (unique & 0x7FF);
25 cm_scache_t *cm_FindSCache(cm_fid_t *fidp)
30 void cm_ReleaseSCache(cm_scache_t *scp)
35 long cm_ApplyDir(cm_scache_t *scp, cm_DirFuncp_t funcp, void *parmp,
36 osi_hyper_t *startOffsetp, cm_user_t *userp, cm_req_t *reqp,
43 afsi_log(char *pattern, ...)
45 char s[256], t[100], d[100], u[512];
47 va_start(ap, pattern);
49 StringCbVPrintfA(s, sizeof(s), pattern, ap);
50 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
51 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
52 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
57 static int initialize_tests(void)
60 cm_InitNormalization();
62 if (!cm_InitBPlusDir()) {
63 TRACE1(L"Can't initialize BPlusDir\n");
67 afsd_logp = osi_LogCreate("fakelog", 100);
75 int n_subSucceeded = 0;
78 static int runtest(wchar_t * testname, int (*f)(void))
85 TRACE1(L"Begin test %s\n", testname);
87 TRACE1(L"End test %s\n", testname);
88 TRACE1(L"Subtests Succeeded %d, Failed %d\n", n_subSucceeded, n_subFailed);
98 #define RUNTEST(f) runtest(_L(#f), f)
100 #define IS_NOT_NULL(v) (((v) != NULL)? n_subSucceeded++: (TRACE1(L"Failed %s\n", _L(#v)), n_subFailed++))
101 #define IS(e) ((e)? n_subSucceeded++ : (TRACE1(L"Failed %s\n", _L(#e)), n_subFailed++))
102 #define CHECK_IF(e) do { if (e) { n_subSucceeded++; } else { TRACE1(L"Failed %s\n", _L(#e)); n_subFailed++; return 1; }} while (0)
104 /**************************************************************/
108 const fschar_t * str;
109 const clientchar_t * lookup;
113 struct strings simple[] = {
114 {"abc", L"ABC", CM_ERROR_INEXACT_MATCH},
118 {"b", L"B", CM_ERROR_INEXACT_MATCH},
119 {"d", L"D", CM_ERROR_INEXACT_MATCH},
120 {"àáâ", L"\x00c0\x00c1\x00c2", CM_ERROR_INEXACT_MATCH},
121 {"Ŷ", L"\x0177", CM_ERROR_INEXACT_MATCH},
122 {"a\xef\xac\xb4",L"a\xfb34",0},
123 {"b\xd7\x94\xd6\xbc",L"b\xfb34",0},
124 {"c\xef\xac\xb4",L"c\x05d4\x05bc",0},
125 {"d\xd7\x94\xd6\xbc",L"d\x05d4\x05bc",0},
128 void init_scache(cm_scache_t * scp, cm_fid_t * fidp)
130 memset(scp, 0, sizeof(cm_scache_t));
131 scp->magic = CM_SCACHE_MAGIC;
132 lock_InitializeRWLock(&scp->rw, "cm_scache_t rw");
133 lock_InitializeRWLock(&scp->bufCreateLock, "cm_scache_t bufCreateLock");
134 lock_InitializeRWLock(&scp->dirlock, "cm_scache_t dirlock");
135 scp->serverLock = -1;
140 int simple_test(void)
145 t = initBtree(64, MAX_FANOUT, cm_BPlusCompareNormalizedKeys);
148 for (i=0; i < lengthof(simple); i++) {
153 norm = cm_FsStringToNormStringAlloc(simple[i].str, -1, NULL);
154 CHECK_IF(norm != NULL);
158 data.cname = cm_FsStringToClientStringAlloc(simple[i].str, -1, NULL);
159 data.fsname = cm_FsStrDup(simple[i].str);
160 data.shortform = FALSE;
161 cm_SetFid(&data.fid, 1, 2, i, 4);
163 insert(t, key, data);
165 if (!cm_Is8Dot3(data.cname)) {
166 wchar_t wshortName[13];
172 cm_Gen8Dot3NameIntW(data.cname, &dfid, wshortName, NULL);
174 key.name = wshortName;
175 data.cname = cm_FsStringToClientStringAlloc(simple[i].str, -1, NULL);
176 data.fsname = cm_FsStrDup(simple[i].str);
177 data.shortform = TRUE;
179 insert(t, key, data);
185 for (i=0; i < lengthof(simple); i++) {
187 normchar_t * entry = NULL;
189 Nptr leafNode = NONODE;
191 cm_fid_t * cfid = &fid;
193 TRACE1(L"Test row %d\n", i);
195 entry = cm_ClientStringToNormStringAlloc(simple[i].lookup, -1, NULL);
198 leafNode = bplus_Lookup(t, key);
199 if (leafNode != NONODE) {
201 Nptr firstDataNode, dataNode, nextDataNode;
205 slot = getSlot(t, leafNode);
206 if (slot <= BTERROR) {
207 rc = (slot == BTERROR ? EINVAL : ENOENT);
210 firstDataNode = getnode(leafNode, slot);
212 for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
214 if (!comparekeys(t)(key, getdatakey(dataNode), EXACT_MATCH) ) {
218 nextDataNode = getdatanext(dataNode);
222 *cfid = getdatavalue(dataNode).fid;
224 } else if (count == 1) {
225 *cfid = getdatavalue(firstDataNode).fid;
226 rc = CM_ERROR_INEXACT_MATCH;
228 rc = CM_ERROR_AMBIGUOUS_FILENAME;
238 IS(rc == simple[i].rc);
239 if (rc == simple[i].rc)
245 int wmain(int argc, wchar_t ** argv)
247 TRACE1(L"\n\nRunning BPLUS tests...\n\n");
248 if (initialize_tests())
251 RUNTEST(simple_test);
254 TRACE1(L"# of test Succeeded: %d\n", n_succeeded);
255 TRACE1(L"# of test Failed: %d\n", n_failed);