📄 odtest.c
字号:
putchar('.'); fflush(stdout); if(i == dnum || i % (dnum / 10) == 0){ printfflush(" (%08d)\n", i); } } } /* close the database */ if(!odclose(odeum)){ pdperror(name); return 1; } if(!err) printfflush("ok\n\n"); return err ? 1 : 0;}/* perform combo command */int docombo(const char *name){ ODEUM *odeum; ODDOC *doc; const CBLIST *nwords, *awords; ODPAIR *pairs; char buf[DOCBUFSIZ]; int i, j, pnum; printfflush("<Combination Test>\n name=%s\n\n", name); printfflush("Creating a database with ... "); if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ pdperror(name); return 1; } printfflush("ok\n"); printfflush("Adding 20 documents including about 200 words ... "); for(i = 1; i <= 20; i++){ sprintf(buf, "%08d", i); doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); if(!odput(odeum, doc, 180 + myrand() % 40, FALSE)){ pdperror(name); oddocclose(doc); odclose(odeum); return 1; } oddocclose(doc); } printfflush("ok\n"); printfflush("Checking documents ... "); for(i = 1; i <= 20; i++){ sprintf(buf, "%08d", i); if(!(doc = odget(odeum, buf))){ pdperror(name); return 1; } nwords = oddocnwords(doc); awords = oddocawords(doc); if(!oddocuri(doc) || !oddocgetattr(doc, "title") || cblistnum(nwords) != cblistnum(awords)){ fprintf(stderr, "%s: %s: invalid document\n", progname, name); oddocclose(doc); odclose(odeum); return 1; } for(j = 0; j < cblistnum(nwords); j++){ if(strcmp(cblistval(nwords, j, NULL), cblistval(nwords, j, NULL))){ fprintf(stderr, "%s: %s: invalid words\n", progname, name); oddocclose(doc); odclose(odeum); return 1; } } oddocclose(doc); } printfflush("ok\n"); printfflush("Syncing the database ... "); if(!odsync(odeum)){ pdperror(name); odclose(odeum); return 1; } printfflush("ok\n"); printfflush("Overwriting 1 - 10 documents ... "); for(i = 1; i <= 10; i++){ sprintf(buf, "%08d", i); doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); if(!odput(odeum, doc, 180 + myrand() % 40, TRUE)){ pdperror(name); oddocclose(doc); odclose(odeum); return 1; } oddocclose(doc); } printfflush("ok\n"); printfflush("Deleting 11 - 20 documents ... "); for(i = 11; i <= 20; i++){ sprintf(buf, "%08d", i); if(!odout(odeum, buf)){ pdperror(name); odclose(odeum); return 1; } } printfflush("ok\n"); printfflush("Checking documents ... "); for(i = 1; i <= 10; i++){ sprintf(buf, "%08d", i); if(!(doc = odget(odeum, buf))){ pdperror(name); return 1; } nwords = oddocnwords(doc); awords = oddocawords(doc); if(!oddocuri(doc) || !oddocgetattr(doc, "title") || cblistnum(nwords) != cblistnum(awords)){ fprintf(stderr, "%s: %s: invalid document\n", progname, name); oddocclose(doc); odclose(odeum); return 1; } for(j = 0; j < cblistnum(nwords); j++){ if(strcmp(cblistval(nwords, j, NULL), cblistval(nwords, j, NULL))){ fprintf(stderr, "%s: %s: invalid words\n", progname, name); oddocclose(doc); odclose(odeum); return 1; } } oddocclose(doc); } if(oddnum(odeum) != 10){ fprintf(stderr, "%s: %s: invalid document number\n", progname, name); odclose(odeum); return 1; } printfflush("ok\n"); printfflush("Optimizing the database ... "); if(!odoptimize(odeum)){ pdperror(name); odclose(odeum); return 1; } printfflush("ok\n"); printfflush("Adding 10 documents including about 200 words ... "); for(i = 11; i <= 20; i++){ sprintf(buf, "%08d", i); doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); if(!odput(odeum, doc, 180 + myrand() % 40, FALSE)){ pdperror(name); oddocclose(doc); odclose(odeum); return 1; } oddocclose(doc); } printfflush("ok\n"); printfflush("Deleting 6 - 15 documents ... "); for(i = 6; i <= 15; i++){ sprintf(buf, "%08d", i); if(!odout(odeum, buf)){ pdperror(name); odclose(odeum); return 1; } } printfflush("ok\n"); printfflush("Retrieving documents 100 times ... "); for(i = 1; i <= 100; i++){ sprintf(buf, "%08d", myrand() % 1000 + 1); if((pairs = odsearch(odeum, buf, -1, &pnum)) != NULL){ for(j = 0; j < pnum; j++){ if((doc = odgetbyid(odeum, pairs[j].id)) != NULL){ oddocclose(doc); } else if(dpecode != DP_ENOITEM){ pdperror(name); odclose(odeum); return 1; } } free(pairs); } else if(dpecode != DP_ENOITEM){ pdperror(name); odclose(odeum); return 1; } } printfflush("ok\n"); printfflush("Closing the database ... "); if(!odclose(odeum)){ pdperror(name); return 1; } printfflush("ok\n"); printfflush("all ok\n\n"); return 0;}/* perform wicked command */int dowicked(const char *name, int dnum){ ODEUM *odeum; ODDOC *doc; ODPAIR *pairs; char buf[DOCBUFSIZ]; int i, j, pnum, err; printfflush("<Wicked Writing Test>\n name=%s dnum=%d\n\n", name, dnum); err = FALSE; if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ pdperror(name); return 1; } for(i = 1; i <= dnum; i++){ switch(myrand() % 8){ case 1: putchar('K'); doc = makedoc(myrand() % dnum + 1, myrand() % 10 + 10, myrand() % dnum + 500); if(!odput(odeum, doc, 5, FALSE) && dpecode != DP_EKEEP) err = TRUE; oddocclose(doc); break; case 3: putchar('D'); if(!odoutbyid(odeum, myrand() % dnum + 1) && dpecode != DP_ENOITEM) err = TRUE; break; case 4: putchar('R'); sprintf(buf, "%08d", myrand() % (dnum + 500) + 1); if((pairs = odsearch(odeum, buf, 5, &pnum)) != NULL){ if(myrand() % 5 == 0){ for(j = 0; j < pnum; j++){ if((doc = odgetbyid(odeum, pairs[j].id)) != NULL){ oddocclose(doc); } else if(dpecode != DP_ENOITEM){ err = TRUE; break; } } } free(pairs); } else if(dpecode != DP_ENOITEM){ err = TRUE; } break; default: putchar('O'); doc = makedoc(myrand() % dnum + 1, myrand() % 10 + 10, myrand() % dnum + 500); if(!odput(odeum, doc, 5, TRUE)) err = TRUE; oddocclose(doc); break; } if(i % 50 == 0) printfflush(" (%08d)\n", i); if(err){ pdperror(name); break; } } if(!odoptimize(odeum)){ pdperror(name); err = TRUE; } for(i = 1; i <= dnum; i++){ doc = makedoc(i, 5, 5); if(!odput(odeum, doc, 5, FALSE) && dpecode != DP_EKEEP){ pdperror(name); oddocclose(doc); err = TRUE; break; } oddocclose(doc); putchar(':'); if(i % 50 == 0) printfflush(" (%08d)\n", i); } if(!odoptimize(odeum)){ pdperror(name); err = TRUE; } for(i = 1; i <= dnum; i++){ sprintf(buf, "%08d", i); if(!(doc = odget(odeum, buf))){ pdperror(name); err = TRUE; break; } oddocclose(doc); putchar('='); if(i % 50 == 0) printfflush(" (%08d)\n", i); } if(!oditerinit(odeum)){ pdperror(name); err = TRUE; } for(i = 1; i <= dnum; i++){ if(!(doc = oditernext(odeum))){ pdperror(name); err = TRUE; break; } oddocclose(doc); putchar('@'); if(i % 50 == 0) printfflush(" (%08d)\n", i); } if(!odclose(odeum)){ pdperror(name); return 1; } if(!err) printfflush("ok\n\n"); return 0;}/* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -