liberscribble/test/test.c File Reference

#include <scb.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <driver.h>

Go to the source code of this file.

Defines

#define _DEBUG   1
#define SLEEP   0
#define TRACE(x, args...)   fprintf(stderr, "(SCB_TEST)" __FILE__ ":%d,%s() " x "\n", __LINE__, __FUNCTION__ , ##args)

Functions

void timestart ()
void timeend ()
void testStrokes ()
void testDataStruct ()
void openDirectly (const char *p)
void openAll (const char *p)
void testDocSave ()
void testDocLoad (const char *pathName)
void checkMemoryLeak ()
void testFastDraw ()
void testdll ()
int main (int argc, char *argv[])

Variables

GTimer * timeStamp = NULL


Define Documentation

#define _DEBUG   1

Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.

Definition at line 28 of file test.c.

#define SLEEP   0

Definition at line 30 of file test.c.

#define TRACE ( x,
args...   )     fprintf(stderr, "(SCB_TEST)" __FILE__ ":%d,%s() " x "\n", __LINE__, __FUNCTION__ , ##args)

Definition at line 33 of file test.c.


Function Documentation

void checkMemoryLeak (  ) 

Definition at line 298 of file test.c.

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 }

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 439 of file test.c.

00440 {
00441     // checkMemoryLeak();
00442     // testDoc();
00443     
00444     //timestart();
00445     //testDocSave();
00446     //timeend();
00447     // testDocLoad("/scb.xml");
00448     // testDataStruct();
00449     // testStrokes();
00450     
00451     /*
00452     if (argc >= 2)
00453     {
00454         if ('1' == *argv[1])
00455         {
00456             openDirectly("/scb.xml");
00457         }
00458         else if ('2' == *argv[1])
00459         {
00460             openAll("/scb.xml");
00461         }
00462     } 
00463     */       
00464     /*
00465     int i = 0;
00466     //for(; i < 1000; ++i)
00467     {
00468         testFastDraw();
00469     }      
00470     */
00471     // testFBIO  ();
00472     // testFastDraw();
00473     testdll();
00474     return 0;
00475 }

Here is the call graph for this function:

void openAll ( const char *  p  ) 

Definition at line 199 of file test.c.

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 }

Here is the call graph for this function:

void openDirectly ( const char *  p  ) 

Definition at line 180 of file test.c.

00181 {
00182     // open directly with p1
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     //page = scb_doc_open_page_directly(&path, &id);
00192     timeend();
00193 
00194   
00195 
00196     TRACE("done!!!!");
00197 }

Here is the call graph for this function:

void testDataStruct (  ) 

Definition at line 105 of file test.c.

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     // add pages
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         // add strokes
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     //scb_pages_dump(pages);
00139     TRACE("add test done! Have a rest!");
00140     sleep(SLEEP);
00141     
00142     // remove pages
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     //scb_pages_dump(pages);
00150     TRACE("remove test done! new count %d Have a rest!", scb_pages_get_count(pages));
00151     sleep(SLEEP);
00152     
00153     
00154     // detach
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     //scb_pages_dump(pages);
00164     sleep(SLEEP);
00165     
00166     TRACE("dump tmp");
00167     //scb_pages_dump(&tmp);
00168     sleep(SLEEP);
00169 
00170  
00171     scb_pages_free(&tmp);
00172     scb_pages_free(pages);
00173     scb_doc_free(doc);
00174 }

Here is the call graph for this function:

void testdll (  ) 

Definition at line 431 of file test.c.

00432 {
00433  //   scb_doc_test();
00434     PointsBufPtr ptr = (PointsBufPtr)1;
00435     scb_driver_draw(ptr);
00436 }

Here is the call graph for this function:

void testDocLoad ( const char *  pathName  ) 

Definition at line 282 of file test.c.

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     //scb_doc_dump(doc);
00294     scb_doc_free(doc);
00295 }

Here is the call graph for this function:

void testDocSave (  ) 

Definition at line 226 of file test.c.

00227 {
00228     static const int PAGES      = 20;       // total pages
00229     static const int STROKES    = 100;      //  strokes per page
00230     static const int POINTS     = 100;      // points per stroke
00231 
00232     // doc
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     // page list
00243     ScbPagesPtr pages = scb_doc_get_pages(doc);
00244 
00245     // add some pages
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         // add strokes
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     //   scb_pages_dump(pages);
00276     strcpy(doc->path.scbname, "/scb.xml");
00277     scb_doc_save(doc);
00278     TRACE("Save done");
00279     scb_doc_free(doc);
00280 }

Here is the call graph for this function:

void testFastDraw (  ) 

Definition at line 310 of file test.c.

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 }

Here is the call graph for this function:

void testStrokes (  ) 

Definition at line 61 of file test.c.

00062 {
00063     static const int STROKES = 5;    // stroke count per strokes
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         // add points
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     // ok, now test 
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 }

Here is the call graph for this function:

void timeend (  ) 

Definition at line 49 of file test.c.

00050 {
00051     if (NULL == timeStamp) return;
00052     g_timer_stop(timeStamp);
00053     gulong microSecs = 0;
00054     gdouble secs = g_timer_elapsed(timeStamp, &microSecs);
00055     TRACE("time %f", secs);
00056 }

void timestart (  ) 

Definition at line 40 of file test.c.

00041 {
00042     if (NULL == timeStamp)
00043     {
00044         timeStamp = g_timer_new();
00045     }
00046     g_timer_start(timeStamp);  
00047 }


Variable Documentation

GTimer* timeStamp = NULL

Definition at line 38 of file test.c.


Generated on Sun Dec 14 17:15:13 2008 by  doxygen 1.5.6