21#ifndef USE_SNAPSHOT_TESTING
23void fwl_set_modeRecord()
26void fwl_set_modeFixture()
29void fwl_set_modePlayback()
32void fwl_set_nameTest(
char *nameTest)
35void fwl_set_testPath(
char *testPath)
41#ifdef USE_SNAPSHOT_TESTING
108void set_snapshotModeTesting(
int value);
109int isSnapshotModeTesting();
128struct playbackRecord {
138typedef struct tSnapshotTesting{
141static tSnapshotTesting SnapshotTesting;
144typedef struct pSnapshotTesting{
146 char* recordingFName;
154 struct playbackRecord* playback;
157 struct keypressTuple keypressQueue[50];
158 int keypressQueueCount;
159 struct mouseTuple mouseQueue[50];
163void *SnapshotTesting_constructor(){
164 void *v = MALLOCV(
sizeof(
struct pSnapshotTesting));
165 memset(v,0,
sizeof(
struct pSnapshotTesting));
168void SnapshotTesting_init(
struct tSnapshotTesting *t){
171 t->prv = SnapshotTesting_constructor();
173 ppSnapshotTesting p = (ppSnapshotTesting)t->prv;
174 p->recordingFile = NULL;
175 p->recordingFName = NULL;
176 p->modeRecord = FALSE;
177 p->modeFixture = FALSE;
178 p->modePlayback = FALSE;
182 p->playbackCount = 0;
186 p->keypressQueueCount=0;
187 p->mouseQueueCount=0;
190void SnapshotTesting_setHandlers();
192static int rtestinit = 0;
193static ppSnapshotTesting get_ppSnapshotTesting(){
195 SnapshotTesting_init(&SnapshotTesting);
197 ppSnapshotTesting p = (ppSnapshotTesting)SnapshotTesting.prv;
198 SnapshotTesting_setHandlers();
200 return (ppSnapshotTesting)SnapshotTesting.prv;
212int dequeueKeyPress(ppSnapshotTesting p,
int *
key,
int *type){
213 if(p->keypressQueueCount > 0){
215 p->keypressQueueCount--;
216 *
key = p->keypressQueue[0].key;
217 *type = p->keypressQueue[0].type;
218 for(i=0;i<p->keypressQueueCount;i++){
219 p->keypressQueue[i].key = p->keypressQueue[i+1].key;
220 p->keypressQueue[i].type = p->keypressQueue[i+1].type;
227void queueKeyPress(ppSnapshotTesting p,
int key,
int type){
228 if(p->keypressQueueCount < 50){
229 p->keypressQueue[p->keypressQueueCount].key =
key;
230 p->keypressQueue[p->keypressQueueCount].type = type;
231 p->keypressQueueCount++;
235int dequeueMouse(ppSnapshotTesting p,
int *mev,
unsigned int *button,
float *x,
float *y){
236 if(p->mouseQueueCount > 0){
238 p->mouseQueueCount--;
239 *mev = p->mouseQueue[0].mev;
240 *button = p->mouseQueue[0].button;
241 *x = p->mouseQueue[0].x;
242 *y = p->mouseQueue[0].y;
243 for(i=0;i<p->mouseQueueCount;i++){
244 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
245 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
246 p->mouseQueue[i].x = p->mouseQueue[i+1].x;
247 p->mouseQueue[i].y = p->mouseQueue[i+1].y;
253int dequeueMouseMulti(ppSnapshotTesting p,
int *mev,
unsigned int *button,
int *ix,
int *iy,
int *ID){
254 if(p->mouseQueueCount > 0){
256 p->mouseQueueCount--;
257 *mev = p->mouseQueue[0].mev;
258 *button = p->mouseQueue[0].button;
259 *ix = p->mouseQueue[0].ix;
260 *iy = p->mouseQueue[0].iy;
261 *ID = p->mouseQueue[0].ID;
262 for(i=0;i<p->mouseQueueCount;i++){
263 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
264 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
265 p->mouseQueue[i].ix = p->mouseQueue[i+1].ix;
266 p->mouseQueue[i].iy = p->mouseQueue[i+1].iy;
267 p->mouseQueue[i].ID = p->mouseQueue[i+1].ID;
274void queueMouseMulti(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const int ix,
const int iy,
int ID){
275 if(p->mouseQueueCount < 50){
276 p->mouseQueue[p->mouseQueueCount].mev = mev;
277 p->mouseQueue[p->mouseQueueCount].button = button;
278 p->mouseQueue[p->mouseQueueCount].ix = ix;
279 p->mouseQueue[p->mouseQueueCount].iy = iy;
280 p->mouseQueue[p->mouseQueueCount].ID = ID;
281 p->mouseQueueCount++;
284void queueMouse(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const float x,
const float y){
285 if(p->mouseQueueCount < 50){
286 p->mouseQueue[p->mouseQueueCount].mev = mev;
287 p->mouseQueue[p->mouseQueueCount].button = button;
288 p->mouseQueue[p->mouseQueueCount].x = x;
289 p->mouseQueue[p->mouseQueueCount].y = y;
290 p->mouseQueueCount++;
295void handleTESTING(
const int mev,
const unsigned int button,
const float x,
const float y)
300 p = get_ppSnapshotTesting();
303 if(p->modeRecord || p->modeFixture || p->modePlayback){
305 queueMouse(p,mev,button,x,y);
310 handle0(mev, button, x, y);
312void fwl_do_keyPress0(
int key,
int type);
313void fwl_do_rawKeyPressTESTING(
int key,
int type) {
317 p = get_ppSnapshotTesting();
320 queueKeyPress(p,
key,type);
322 fwl_do_keyPress0(
key,type);
325int fwl_handle_mouse0(
const int mev,
const unsigned int button,
int x,
int y,
int windex);
326int fwl_handle_aqua_TESTING(
const int mev,
const unsigned int button,
int x,
int y,
int windex)
331 p = get_ppSnapshotTesting();
333 if(p->modeRecord || p->modeFixture || p->modePlayback){
335 queueMouseMulti(p,mev,button,x,y,windex);
340 return fwl_handle_mouse0(mev, button, x, y, windex);
343void fwl_set_modeRecord()
348 p = get_ppSnapshotTesting();
349 p->modeRecord = TRUE;
351void fwl_set_modeFixture()
356 p = get_ppSnapshotTesting();
357 p->modeFixture = TRUE;
359void fwl_set_modePlayback()
364 p = get_ppSnapshotTesting();
365 p->modePlayback = TRUE;
367void fwl_set_nameTest(
char *nameTest)
372 p = get_ppSnapshotTesting();
373 p->nameTest = STRDUP(nameTest);
375void fwl_set_testPath(
char *testPath)
381 p = get_ppSnapshotTesting();
382 p->testPath = STRDUP(testPath);
383 ierr = chdir(p->testPath);
387 ierr = chdir(p->testPath);
393 printf(
"current working directory= %s\n", cwd);
398char *nameLogFileFolderTESTING(
char *logfilename,
int size){
402 p = get_ppSnapshotTesting();
404 if(p->modePlayback || p->modeFixture){
406 strcat(logfilename,
"playback");
408 strcat(logfilename,
"fixture");
409 fw_mkdir(logfilename);
410 strcat(logfilename,
"/");
413 strcat(logfilename,p->nameTest);
414 }
else if(tg->Mainloop.scene_name){
416 strcat(logfilename,tg->Mainloop.scene_name);
417 if(tg->Mainloop.scene_suff){
418 strcat(logfilename,
"_");
419 strcat(logfilename,tg->Mainloop.scene_suff);
423 nameLogFileFolderNORMAL(logfilename,size);
429int fw_mkdir(
const char* path);
430void fwl_RenderSceneUpdateScene0(
double dtime);
431void fwl_RenderSceneUpdateSceneTARGETWINDOWS();
432void fwl_RenderSceneUpdateSceneTESTING() {
439 p = get_ppSnapshotTesting();
442 dtime = Time1970sec();
443 if((p->modeRecord || p->modeFixture || p->modePlayback))
465 char buff[1000], keystrokes[200], mouseStr[1000];
468 char sceneName[1000];
481 if(!p->fwplayOpened){
482 char recordingName[1000];
485 recordingName[0] =
'\0';
487 if(tg->Mainloop.scene_name){
488 strcat(sceneName,tg->Mainloop.scene_name);
489 if(tg->Mainloop.scene_suff){
490 strcat(sceneName,
".");
491 strcat(sceneName,tg->Mainloop.scene_suff);
494 if(namingMethod==3 || namingMethod==4){
495 strcpy(recordingName,
"recording");
496 fw_mkdir(recordingName);
497 strcat(recordingName,
"/");
501 strcat(recordingName,p->nameTest);
503 strcat(recordingName,tg->Mainloop.scene_name);
504 k = strlen(recordingName);
507 j = strlen(tg->Mainloop.scene_suff);
509 strcat(recordingName,
"_");
510 strcat(recordingName,tg->Mainloop.scene_suff);
516 fw_mkdir(recordingName);
517 strcat(recordingName,
"/recording");
520 strcat(recordingName,
"recording");
521 strcat(recordingName,
".fwplay");
522 p->recordingFName = STRDUP(recordingName);
524 if(p->modeFixture || p->modePlayback){
526 p->recordingFile = fopen(p->recordingFName,
"r");
527 if(p->recordingFile == NULL){
528 printf(
"ouch recording file %s not found\n", p->recordingFName);
531 if( fgets(buff, 1000, p->recordingFile) != NULL){
532 char window_widthxheight[100], equals[50];
535 if( sscanf(buff,
"%s %s %d, %d\n",window_widthxheight,equals, &width,&height) == 4) {
536 if(width != tg->display.screenWidth || height != tg->display.screenHeight){
538 printf(
"Ouch - the test playback window size is different than recording:\n");
539 printf(
"recording %d x %d playback %d x %d\n",width,height,
540 tg->display.screenWidth,tg->display.screenHeight);
541 printf(
"hit Enter:");
546 if( fgets(buff, 1000, p->recordingFile) != NULL){
547 char scenefile[100], equals[50];
549 if( sscanf(buff,
"%s %s %s \n",scenefile,equals, sceneName) == 3) {
550 if(!tg->Mainloop.scene_name){
552 char* local_name = NULL;
554 if(strlen(sceneName)) url = STRDUP(sceneName);
556 splitpath_local_suffix(url, &local_name, &suff);
557 gglobal()->Mainloop.url = url;
558 gglobal()->Mainloop.scene_name = local_name;
559 gglobal()->Mainloop.scene_suff = suff;
560 fwl_resource_push_single_request(url);
568 int doEvents = (!fwl_isinputThreadParsing()) && (!fwl_isTextureParsing()) && fwl_isInputThreadInitialized();
573 if(dtime - tg->Mainloop.TickTime < .5)
return;
579 if(p->frameNum == 1){
584 printf(
"current working directory= %s\n", cwd);
586 p->recordingFile = fopen(p->recordingFName,
"w");
587 if(p->recordingFile == NULL){
588 printf(
"ouch recording file %s not found\n", p->recordingFName);
592 fprintf(p->recordingFile,
"window_wxh = %d, %d \n",tg->display.screenWidth,tg->display.screenHeight);
593 fprintf(p->recordingFile,
"scenefile = %s \n",tg->Mainloop.url);
595 strcpy(keystrokes,
"\"");
596 while(dequeueKeyPress(p,&
key,&type)){
597 sprintf(temp,
"%d,%d,",
key,type);
598 strcat(keystrokes,temp);
600 strcat(keystrokes,
"\"");
601 strcpy(mouseStr,
"\"");
603 while(dequeueMouseMulti(p,&mev, &button, &ix, &iy, &ID)){
604 sprintf(temp,
"%d,%d,%d,%d,%d;",mev,button,ix,iy,ID);
605 strcat(mouseStr,temp);
608 strcat(mouseStr,
"\"");
609 fprintf(p->recordingFile,
"%d %.6lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
612 sprintf(temp,
"%.6lf",dtime);
613 sscanf(temp,
"%lf",&dtime);
617 if(p->modeFixture || p->modePlayback){
620 if( fgets( buff, 1000, p->recordingFile ) != NULL ) {
621 if(sscanf(buff,
"%d %lf %s %s\n",&p->frameNum,&dtime,keystrokes,mouseStr) == 4){
622 if(0) printf(
"%d %lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
626 if(p->modeFixture) folder =
"fixture";
627 if(p->modePlayback) folder =
"playback";
630 if(p->modeRecord || p->modeFixture || p->modePlayback){
631 if(strlen(keystrokes)>2){
636 curr = &keystrokes[1];
637 while(curr && strlen(curr)>1){
641 sscanf(curr,
"%d",&
key);
642 next = strchr(curr,
',');
644 sscanf(curr,
"%d",&type);
645 next = strchr(curr,
',');
647 if(p->modeFixture || p->modePlayback){
657 char *suff =
".snap";
659 sprintf(snapfile,
"%d",p->frameNum);
660 if(namingMethod == 0){
663 strcpy(snappath,folder);
664 strcat(snappath,suff);
665 fwl_set_SnapFile(snappath);
672 strcpy(snappath,tg->Mainloop.scene_name);
673 k = strlen(snappath);
676 j = strlen(tg->Mainloop.scene_suff);
678 strcat(snappath,
"_");
679 strcat(snappath,tg->Mainloop.scene_suff);
682 strcat(snappath,
"/");
683 strcat(snappath,folder);
686 strcat(snappath,
"/");
687 strcat(snappath,snapfile);
688 strcat(snappath,suff);
690 fwl_set_SnapFile(snappath);
692 if(namingMethod == 2){
698 strcpy(snappath,tg->Mainloop.scene_name);
699 k = strlen(snappath);
701 j= strlen(tg->Mainloop.scene_suff);
703 strcat(snappath,
"_");
704 strcat(snappath,tg->Mainloop.scene_suff);
706 strcat(snappath,
"_");
708 strcat(snappath,folder);
709 strcat(snappath,
"_");
710 strcat(snappath,snapfile);
711 strcat(snappath,suff);
712 fwl_set_SnapFile(snappath);
714 if(namingMethod == 3){
720 strcpy(snappath,folder);
722 strcat(snappath,
"/");
723 strcat(snappath,tg->Mainloop.scene_name);
724 k = strlen(tg->Mainloop.scene_name);
726 j= strlen(tg->Mainloop.scene_suff);
728 strcat(snappath,
"_");
729 strcat(snappath,tg->Mainloop.scene_suff);
731 strcat(snappath,
"_");
733 strcat(snappath,snapfile);
734 strcat(snappath,suff);
735 fwl_set_SnapFile(snappath);
737 if(namingMethod == 4){
743 set_snapshotModeTesting(TRUE);
748 strcpy(snappath,folder);
750 fwl_set_SnapTmp(snappath);
754 strcat(snappath,p->nameTest);
756 if(tg->Mainloop.scene_name){
757 strcat(snappath,tg->Mainloop.scene_name);
758 if(tg->Mainloop.scene_suff)
760 strcat(snappath,sep);
761 strcat(snappath,tg->Mainloop.scene_suff);
765 fwl_set_SnapFile(snappath);
770 fwl_do_keyPress0(
key, type);
774 if(strlen(mouseStr)>2){
779 len = strlen(mouseStr);
783 if(mouseStr[i] ==
';')
break;
785 sscanf(&mouseStr[ii],
"%d,%d,%d,%d,%d;",&mev,&button,&ix,&iy,&ID);
787 fwl_handle_mouse0(mev, button, ix, iy, ID);
794 fwl_RenderSceneUpdateSceneTARGETWINDOWS();
797extern void (*fwl_do_rawKeyPressPTR)(
int key,
int type);
798extern int (*fwl_handle_mousePTR)(
const int mev,
const unsigned int button,
int x,
int y,
int windex);
799extern void (*fwl_RenderSceneUpdateScenePTR)();
800extern void (*handlePTR)(
const int mev,
const unsigned int button,
const float x,
const float y);
801extern char * (*nameLogFileFolderPTR)(
char *logfilename,
int size);
802void SnapshotTesting_setHandlers(){
803 fwl_do_rawKeyPressPTR = fwl_do_rawKeyPressTESTING;
804 fwl_handle_mousePTR = fwl_handle_aqua_TESTING;
805 fwl_RenderSceneUpdateScenePTR = fwl_RenderSceneUpdateSceneTESTING;
807 nameLogFileFolderPTR = nameLogFileFolderTESTING;