00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include <scb.h>
00024 #include <sys/ioctl.h>
00025 #include <fcntl.h>
00026 #include <driver.h>
00027
00028 #define _DEBUG 1
00029
00030 #define SLEEP 0
00031
00032 #ifdef _DEBUG
00033 #define TRACE(x, args...) fprintf(stderr, "(SCB_TEST)" __FILE__ ":%d,%s() " x "\n", __LINE__, __FUNCTION__ , ##args)
00034 #else
00035 #define TRACE(x, args...) do {} while (0)
00036 #endif
00037
00038 GTimer * timeStamp = NULL;
00039
00040 void timestart()
00041 {
00042 if (NULL == timeStamp)
00043 {
00044 timeStamp = g_timer_new();
00045 }
00046 g_timer_start(timeStamp);
00047 }
00048
00049 void timeend()
00050 {
00051 if (NULL == timeStamp) return;
00052 g_timer_stop(timeStamp);
00053 gulong microSecs = 0;
00054 gdouble secs = g_timer_elapsed(timeStamp, µSecs);
00055 TRACE("time %f", secs);
00056 }
00057
00058
00059
00060
00061 void testStrokes()
00062 {
00063 static const int STROKES = 5;
00064 static const int POINTS = 5;
00065 ScbStrokes strokes;
00066 ScbStrokes tmp;
00067 ScbPoint point;
00068 scb_strokes_new(&strokes);
00069 scb_strokes_new(&tmp);
00070 int i, j ;
00071 for(i = 0; i < STROKES; ++i)
00072 {
00073 ScbStrokePtr stroke = scb_stroke_new();
00074
00075 for(j = 0; j < POINTS; ++j)
00076 {
00077 point.x = i ; point.y = j; point.pressure = i * j;
00078 scb_stroke_add_point(stroke, &point);
00079 }
00080 scb_strokes_add_stroke(&strokes, stroke);
00081 scb_strokes_add_stroke(&tmp, stroke);
00082
00083 }
00084 TRACE("Add done! Now test detach and remove");
00085
00086
00087 scb_strokes_detach(&tmp);
00088 TRACE("Dump strokes:");
00089 scb_strokes_dump(&strokes);
00090 TRACE("Dump tmp: should be zero!");
00091 scb_strokes_dump(&tmp);
00092 TRACE("Free all!");
00093 scb_strokes_empty(&strokes);
00094 scb_strokes_dump(&strokes);
00095
00096
00097 scb_strokes_free(&tmp);
00098
00099 scb_strokes_free(&strokes);
00100 }
00101
00102
00103
00104
00105 void testDataStruct()
00106 {
00107 static const int PAGES = 5;
00108 static const int STROKES = 5;
00109 static const int POINTS = 5;
00110
00111 ScbDocPtr doc = scb_doc_new();
00112 ScbPagesPtr pages = scb_doc_get_pages(doc);
00113
00114
00115 ScbPageId id;
00116 ScbPagePtr page = NULL;
00117 int i , j , k;
00118 for(i = 1; i <= PAGES; ++i)
00119 {
00120 scb_page_id_from_int(&id, i);
00121 page = scb_page_new();
00122 scb_page_set_id(page, &id);
00123
00124
00125 for(k = 1; k <= STROKES; ++k)
00126 {
00127 ScbStrokePtr stroke = scb_stroke_new();
00128 ScbPoint point;
00129 for(j = 1;j < POINTS; ++j)
00130 {
00131 point.x = i; point.y = j; point.pressure = i * j;
00132 scb_stroke_add_point(stroke, &point);
00133 }
00134 scb_page_add_stroke(page, stroke);
00135 }
00136 scb_pages_add_page(pages, page);
00137 }
00138
00139 TRACE("add test done! Have a rest!");
00140 sleep(SLEEP);
00141
00142
00143 for(i = 1; i <= PAGES / 2; ++i)
00144 {
00145 scb_page_id_from_int(&id, i);
00146 TRACE("go to remove page %s!", id.id);
00147 scb_pages_remove_page(pages, &id);
00148 }
00149
00150 TRACE("remove test done! new count %d Have a rest!", scb_pages_get_count(pages));
00151 sleep(SLEEP);
00152
00153
00154
00155 ScbPages tmp;
00156 scb_pages_new(&tmp);
00157 for(i = PAGES/2 + 1; i <=PAGES; ++i)
00158 {
00159 scb_page_id_from_int(&id, i);
00160 scb_pages_add_page(&tmp, scb_pages_detach_page(pages, &id));
00161 }
00162 TRACE("dump pages");
00163
00164 sleep(SLEEP);
00165
00166 TRACE("dump tmp");
00167
00168 sleep(SLEEP);
00169
00170
00171 scb_pages_free(&tmp);
00172 scb_pages_free(pages);
00173 scb_doc_free(doc);
00174 }
00175
00176
00177
00178
00179
00180 void openDirectly(const char *p)
00181 {
00182
00183 ScbPath path;
00184 ScbPageId id;
00185 ScbPagePtr page;
00186 strncpy(path.scbname, p, MAX_PATH);
00187 strncpy(id.id, "10", MAX_PAGEID_LEN);
00188
00189
00190 timestart();
00191
00192 timeend();
00193
00194
00195
00196 TRACE("done!!!!");
00197 }
00198
00199 void openAll(const char *p)
00200 {
00201 ScbPath path;
00202 ScbPageId id;
00203 ScbPagePtr page;
00204 strncpy(path.scbname, p, MAX_PATH);
00205 strncpy(id.id, "10", MAX_PAGEID_LEN);
00206
00207
00208
00209 timestart();
00210 ScbDocPtr doc = scb_doc_open(&path);
00211 ScbPagesPtr pages = scb_doc_get_pages(doc);
00212 page = scb_pages_get_page(pages, &id);
00213 timeend();
00214
00215
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 void testDocSave()
00227 {
00228 static const int PAGES = 20;
00229 static const int STROKES = 100;
00230 static const int POINTS = 100;
00231
00232
00233 TRACE("Start to create a new doc!");
00234 ScbDocPtr doc = scb_doc_new();
00235 if (NULL == doc)
00236 {
00237 TRACE("Could not construct a scribble document!");
00238 return;
00239 }
00240 TRACE("create document done!");
00241
00242
00243 ScbPagesPtr pages = scb_doc_get_pages(doc);
00244
00245
00246 ScbPageId id;
00247 ScbPagePtr page = NULL;
00248 int i , j , k;
00249 for(i = 1; i <= PAGES; ++i)
00250 {
00251 scb_page_id_from_int(&id, i);
00252 page = scb_page_new();
00253 scb_page_set_id(page, &id);
00254
00255
00256 for(k = 1; k <= STROKES; ++k)
00257 {
00258 ScbStrokePtr stroke = scb_stroke_new();
00259 ScbPoint point;
00260 for(j = 1;j < POINTS; ++j)
00261 {
00262 point.x = i; point.y = j; point.pressure = i * j;
00263 scb_stroke_add_point(stroke, &point);
00264 }
00265 scb_page_add_stroke(page, stroke);
00266 }
00267 scb_pages_add_page(pages, page);
00268 }
00269
00270 TRACE("Added pages done! Dump Page now!");
00271 TRACE("pages %d", scb_pages_get_count(pages));
00272 TRACE("Visit page %s!", id.id);
00273 page = scb_pages_get_page(pages, &id);
00274
00275
00276 strcpy(doc->path.scbname, "/scb.xml");
00277 scb_doc_save(doc);
00278 TRACE("Save done");
00279 scb_doc_free(doc);
00280 }
00281
00282 void testDocLoad(const char *pathName)
00283 {
00284 ScbPath path; strcpy(path.scbname, pathName);
00285 ScbDocPtr doc = scb_doc_open(&path);
00286
00287 if (NULL == doc)
00288 {
00289 TRACE("Could not open file %s", pathName);
00290 return;
00291 }
00292
00293
00294 scb_doc_free(doc);
00295 }
00296
00297
00298 void checkMemoryLeak()
00299 {
00300 printf("checking memory...");
00301 int i = 0;
00302 for(; i < 100000; ++ i )
00303 {
00304 testDataStruct();
00305 }
00306 printf("done, check memory!\n");
00307 sleep(20);
00308 }
00309
00310 void testFastDraw()
00311 {
00312 ScbPath path;
00313 strncpy(path.scbname, "/temp.irx", MAX_PATH);
00314 ScbDocPtr doc = scb_doc_make_sure_exist(&path);
00315
00316 ScbPageId id;
00317 scb_page_id_from_str(&id, "abcdef");
00318
00319 ScbPagePtr page = scb_doc_get_page(doc, &id);
00320 if (NULL == page)
00321 {
00322 page = scb_page_new();
00323 scb_page_set_id(page, &id);
00324 scb_doc_add_page(doc, page);
00325 }
00326
00327
00328 ScbStrokePtr stroke = scb_stroke_new();
00329
00330 stroke->style.color.pixel = 3;
00331 stroke->style.penSize = 3;
00332 static const int POINTS = 1000;
00333
00334 int i;
00335 ScbPoint point;
00336 for(i = 0; i < POINTS - 1; ++i)
00337 {
00338 point.x = i; point.y = i; point.pressure = i * i;
00339 scb_stroke_add_point(stroke, &point);
00340 scb_stroke_fast_draw_point(stroke, &point);
00341 }
00342 point.x = i; point.y = i; point.pressure = i * i;
00343 scb_stroke_add_point(stroke, &point);
00344 scb_stroke_fast_draw_point_done(stroke, &point);
00345 scb_page_add_stroke(page, stroke);
00346 scb_doc_save(doc);
00347 scb_doc_free(doc);
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 void testdll()
00432 {
00433
00434 PointsBufPtr ptr = (PointsBufPtr)1;
00435 scb_driver_draw(ptr);
00436 }
00437
00438
00439 int main(int argc, char * argv[])
00440 {
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 testdll();
00474 return 0;
00475 }