23#include "../scenegraph/Viewer.h"
26#ifndef USE_SNAPSHOT_TESTING
28void fwl_set_modeRecord()
31void fwl_set_modeFixture()
34void fwl_set_modePlayback()
37void fwl_set_nameTest(
char *nameTest)
40void fwl_set_testPath(
char *testPath)
46#ifdef USE_SNAPSHOT_TESTING
113void set_snapshotModeTesting(
int value);
114int isSnapshotModeTesting();
133struct playbackRecord {
143typedef struct tSnapshotTesting{
146static tSnapshotTesting SnapshotTesting;
149typedef struct pSnapshotTesting{
151 char* recordingFName;
159 struct playbackRecord* playback;
162 struct keypressTuple keypressQueue[50];
163 int keypressQueueCount;
164 struct mouseTuple mouseQueue[50];
168void *SnapshotTesting_constructor(){
169 void *v = MALLOCV(
sizeof(
struct pSnapshotTesting));
170 memset(v,0,
sizeof(
struct pSnapshotTesting));
173void SnapshotTesting_init(
struct tSnapshotTesting *t){
176 t->prv = SnapshotTesting_constructor();
178 ppSnapshotTesting p = (ppSnapshotTesting)t->prv;
179 p->recordingFile = NULL;
180 p->recordingFName = NULL;
181 p->modeRecord = FALSE;
182 p->modeFixture = FALSE;
183 p->modePlayback = FALSE;
187 p->playbackCount = 0;
191 p->keypressQueueCount=0;
192 p->mouseQueueCount=0;
195void SnapshotTesting_setHandlers();
197static int rtestinit = 0;
198static ppSnapshotTesting get_ppSnapshotTesting(){
200 SnapshotTesting_init(&SnapshotTesting);
202 ppSnapshotTesting p = (ppSnapshotTesting)SnapshotTesting.prv;
203 SnapshotTesting_setHandlers();
205 return (ppSnapshotTesting)SnapshotTesting.prv;
217int dequeueKeyPress(ppSnapshotTesting p,
int *
key,
int *type){
218 if(p->keypressQueueCount > 0){
220 p->keypressQueueCount--;
221 *
key = p->keypressQueue[0].key;
222 *type = p->keypressQueue[0].type;
223 for(i=0;i<p->keypressQueueCount;i++){
224 p->keypressQueue[i].key = p->keypressQueue[i+1].key;
225 p->keypressQueue[i].type = p->keypressQueue[i+1].type;
232void queueKeyPress(ppSnapshotTesting p,
int key,
int type){
233 if(p->keypressQueueCount < 50){
234 p->keypressQueue[p->keypressQueueCount].key =
key;
235 p->keypressQueue[p->keypressQueueCount].type = type;
236 p->keypressQueueCount++;
240int dequeueMouse(ppSnapshotTesting p,
int *mev,
unsigned int *button,
float *x,
float *y){
241 if(p->mouseQueueCount > 0){
243 p->mouseQueueCount--;
244 *mev = p->mouseQueue[0].mev;
245 *button = p->mouseQueue[0].button;
246 *x = p->mouseQueue[0].x;
247 *y = p->mouseQueue[0].y;
248 for(i=0;i<p->mouseQueueCount;i++){
249 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
250 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
251 p->mouseQueue[i].x = p->mouseQueue[i+1].x;
252 p->mouseQueue[i].y = p->mouseQueue[i+1].y;
258int dequeueMouseMulti(ppSnapshotTesting p,
int *mev,
unsigned int *button,
int *ix,
int *iy,
int *ID){
259 if(p->mouseQueueCount > 0){
261 p->mouseQueueCount--;
262 *mev = p->mouseQueue[0].mev;
263 *button = p->mouseQueue[0].button;
264 *ix = p->mouseQueue[0].ix;
265 *iy = p->mouseQueue[0].iy;
266 *ID = p->mouseQueue[0].ID;
267 for(i=0;i<p->mouseQueueCount;i++){
268 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
269 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
270 p->mouseQueue[i].ix = p->mouseQueue[i+1].ix;
271 p->mouseQueue[i].iy = p->mouseQueue[i+1].iy;
272 p->mouseQueue[i].ID = p->mouseQueue[i+1].ID;
279void queueMouseMulti(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const int ix,
const int iy,
int ID){
280 if(p->mouseQueueCount < 50){
281 p->mouseQueue[p->mouseQueueCount].mev = mev;
282 p->mouseQueue[p->mouseQueueCount].button = button;
283 p->mouseQueue[p->mouseQueueCount].ix = ix;
284 p->mouseQueue[p->mouseQueueCount].iy = iy;
285 p->mouseQueue[p->mouseQueueCount].ID = ID;
286 p->mouseQueueCount++;
289void queueMouse(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const float x,
const float y){
290 if(p->mouseQueueCount < 50){
291 p->mouseQueue[p->mouseQueueCount].mev = mev;
292 p->mouseQueue[p->mouseQueueCount].button = button;
293 p->mouseQueue[p->mouseQueueCount].x = x;
294 p->mouseQueue[p->mouseQueueCount].y = y;
295 p->mouseQueueCount++;
300void handleTESTING(
const int mev,
const unsigned int button,
const float x,
const float y)
305 p = get_ppSnapshotTesting();
308 if(p->modeRecord || p->modeFixture || p->modePlayback){
310 queueMouse(p,mev,button,x,y);
315 handle0(mev, button, x, y);
317void fwl_do_keyPress0(
int key,
int type);
318void fwl_do_rawKeyPressTESTING(
int key,
int type) {
322 p = get_ppSnapshotTesting();
325 queueKeyPress(p,
key,type);
327 fwl_do_keyPress0(
key,type);
330int fwl_handle_mouse0(
const int mev,
const unsigned int button,
int x,
int y,
int windex);
331int fwl_handle_aqua_TESTING(
const int mev,
const unsigned int button,
int x,
int y,
int windex)
336 p = get_ppSnapshotTesting();
338 if(p->modeRecord || p->modeFixture || p->modePlayback){
340 queueMouseMulti(p,mev,button,x,y,windex);
345 return fwl_handle_mouse0(mev, button, x, y, windex);
348void fwl_set_modeRecord()
353 p = get_ppSnapshotTesting();
354 p->modeRecord = TRUE;
356void fwl_set_modeFixture()
361 p = get_ppSnapshotTesting();
362 p->modeFixture = TRUE;
364void fwl_set_modePlayback()
369 p = get_ppSnapshotTesting();
370 p->modePlayback = TRUE;
372void fwl_set_nameTest(
char *nameTest)
377 p = get_ppSnapshotTesting();
378 p->nameTest = STRDUP(nameTest);
380void fwl_set_testPath(
char *testPath)
386 p = get_ppSnapshotTesting();
387 p->testPath = STRDUP(testPath);
388 ierr = chdir(p->testPath);
391 mkdir(p->testPath, 0755);
392 ierr = chdir(p->testPath);
398 printf(
"current working directory= %s\n", cwd);
403char *nameLogFileFolderTESTING(
char *logfilename,
int size){
407 p = get_ppSnapshotTesting();
409 if(p->modePlayback || p->modeFixture){
411 strcat(logfilename,
"playback");
413 strcat(logfilename,
"fixture");
414 fw_mkdir(logfilename);
415 strcat(logfilename,
"/");
418 strcat(logfilename,p->nameTest);
419 }
else if(tg->Mainloop.scene_name){
421 strcat(logfilename,tg->Mainloop.scene_name);
422 if(tg->Mainloop.scene_suff){
423 strcat(logfilename,
"_");
424 strcat(logfilename,tg->Mainloop.scene_suff);
428 nameLogFileFolderNORMAL(logfilename,size);
434int fw_mkdir(
const char* path);
435void fwl_RenderSceneUpdateScene0(
double dtime);
436void fwl_RenderSceneUpdateSceneTARGETWINDOWS();
437void fwl_RenderSceneUpdateSceneTESTING() {
444 p = get_ppSnapshotTesting();
447 dtime = Time1970sec();
448 if((p->modeRecord || p->modeFixture || p->modePlayback))
470 char buff[1000], keystrokes[200], mouseStr[1000];
473 char sceneName[1000];
486 if(!p->fwplayOpened){
487 char recordingName[1000];
490 recordingName[0] =
'\0';
492 if(tg->Mainloop.scene_name){
493 strcat(sceneName,tg->Mainloop.scene_name);
494 if(tg->Mainloop.scene_suff){
495 strcat(sceneName,
".");
496 strcat(sceneName,tg->Mainloop.scene_suff);
499 if(namingMethod==3 || namingMethod==4){
500 strcpy(recordingName,
"recording");
501 fw_mkdir(recordingName);
502 strcat(recordingName,
"/");
506 strcat(recordingName,p->nameTest);
508 strcat(recordingName,tg->Mainloop.scene_name);
509 k = strlen(recordingName);
512 j = strlen(tg->Mainloop.scene_suff);
514 strcat(recordingName,
"_");
515 strcat(recordingName,tg->Mainloop.scene_suff);
521 fw_mkdir(recordingName);
522 strcat(recordingName,
"/recording");
525 strcat(recordingName,
"recording");
526 strcat(recordingName,
".fwplay");
527 p->recordingFName = STRDUP(recordingName);
529 if(p->modeFixture || p->modePlayback){
531 p->recordingFile = fopen(p->recordingFName,
"r");
532 if(p->recordingFile == NULL){
533 printf(
"ouch recording file %s not found\n", p->recordingFName);
536 if( fgets(buff, 1000, p->recordingFile) != NULL){
537 char window_widthxheight[100], equals[50];
540 if( sscanf(buff,
"%s %s %d, %d\n",window_widthxheight,equals, &width,&height) == 4) {
541 if(width != tg->display.screenWidth || height != tg->display.screenHeight){
543 printf(
"Ouch - the test playback window size is different than recording:\n");
544 printf(
"recording %d x %d playback %d x %d\n",width,height,
545 tg->display.screenWidth,tg->display.screenHeight);
546 printf(
"hit Enter:");
551 if( fgets(buff, 1000, p->recordingFile) != NULL){
552 char scenefile[100], equals[50];
554 if( sscanf(buff,
"%s %s %s \n",scenefile,equals, sceneName) == 3) {
555 if(!tg->Mainloop.scene_name){
557 char* local_name = NULL;
559 if(strlen(sceneName)) url = STRDUP(sceneName);
561 splitpath_local_suffix(url, &local_name, &suff);
562 gglobal()->Mainloop.url = url;
563 gglobal()->Mainloop.scene_name = local_name;
564 gglobal()->Mainloop.scene_suff = suff;
565 fwl_resource_push_single_request(url);
573 int doEvents = (!fwl_isinputThreadParsing()) && (!fwl_isTextureParsing()) && fwl_isInputThreadInitialized();
578 if(dtime - tg->Mainloop.TickTime < .5)
return;
584 if(p->frameNum == 1){
589 printf(
"current working directory= %s\n", cwd);
591 p->recordingFile = fopen(p->recordingFName,
"w");
592 if(p->recordingFile == NULL){
593 printf(
"ouch recording file %s not found\n", p->recordingFName);
597 fprintf(p->recordingFile,
"window_wxh = %d, %d \n",tg->display.screenWidth,tg->display.screenHeight);
598 fprintf(p->recordingFile,
"scenefile = %s \n",tg->Mainloop.url);
600 strcpy(keystrokes,
"\"");
601 while(dequeueKeyPress(p,&
key,&type)){
602 sprintf(temp,
"%d,%d,",
key,type);
603 strcat(keystrokes,temp);
605 strcat(keystrokes,
"\"");
606 strcpy(mouseStr,
"\"");
608 while(dequeueMouseMulti(p,&mev, &button, &ix, &iy, &ID)){
609 sprintf(temp,
"%d,%d,%d,%d,%d;",mev,button,ix,iy,ID);
610 strcat(mouseStr,temp);
613 strcat(mouseStr,
"\"");
614 fprintf(p->recordingFile,
"%d %.6lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
617 sprintf(temp,
"%.6lf",dtime);
618 sscanf(temp,
"%lf",&dtime);
622 if(p->modeFixture || p->modePlayback){
625 if( fgets( buff, 1000, p->recordingFile ) != NULL ) {
626 if(sscanf(buff,
"%d %lf %s %s\n",&p->frameNum,&dtime,keystrokes,mouseStr) == 4){
627 if(0) printf(
"%d %lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
631 if(p->modeFixture) folder =
"fixture";
632 if(p->modePlayback) folder =
"playback";
635 if(p->modeRecord || p->modeFixture || p->modePlayback){
636 if(strlen(keystrokes)>2){
641 curr = &keystrokes[1];
642 while(curr && strlen(curr)>1){
646 sscanf(curr,
"%d",&
key);
647 next = strchr(curr,
',');
649 sscanf(curr,
"%d",&type);
650 next = strchr(curr,
',');
652 if(p->modeFixture || p->modePlayback){
662 char *suff =
".snap";
664 sprintf(snapfile,
"%d",p->frameNum);
665 if(namingMethod == 0){
668 strcpy(snappath,folder);
669 strcat(snappath,suff);
670 fwl_set_SnapFile(snappath);
677 strcpy(snappath,tg->Mainloop.scene_name);
678 k = strlen(snappath);
681 j = strlen(tg->Mainloop.scene_suff);
683 strcat(snappath,
"_");
684 strcat(snappath,tg->Mainloop.scene_suff);
687 strcat(snappath,
"/");
688 strcat(snappath,folder);
691 strcat(snappath,
"/");
692 strcat(snappath,snapfile);
693 strcat(snappath,suff);
695 fwl_set_SnapFile(snappath);
697 if(namingMethod == 2){
703 strcpy(snappath,tg->Mainloop.scene_name);
704 k = strlen(snappath);
706 j= strlen(tg->Mainloop.scene_suff);
708 strcat(snappath,
"_");
709 strcat(snappath,tg->Mainloop.scene_suff);
711 strcat(snappath,
"_");
713 strcat(snappath,folder);
714 strcat(snappath,
"_");
715 strcat(snappath,snapfile);
716 strcat(snappath,suff);
717 fwl_set_SnapFile(snappath);
719 if(namingMethod == 3){
725 strcpy(snappath,folder);
727 strcat(snappath,
"/");
728 strcat(snappath,tg->Mainloop.scene_name);
729 k = strlen(tg->Mainloop.scene_name);
731 j= strlen(tg->Mainloop.scene_suff);
733 strcat(snappath,
"_");
734 strcat(snappath,tg->Mainloop.scene_suff);
736 strcat(snappath,
"_");
738 strcat(snappath,snapfile);
739 strcat(snappath,suff);
740 fwl_set_SnapFile(snappath);
742 if(namingMethod == 4){
748 set_snapshotModeTesting(TRUE);
753 strcpy(snappath,folder);
755 fwl_set_SnapTmp(snappath);
759 strcat(snappath,p->nameTest);
761 if(tg->Mainloop.scene_name){
762 strcat(snappath,tg->Mainloop.scene_name);
763 if(tg->Mainloop.scene_suff)
765 strcat(snappath,sep);
766 strcat(snappath,tg->Mainloop.scene_suff);
770 fwl_set_SnapFile(snappath);
775 fwl_do_keyPress0(
key, type);
779 if(strlen(mouseStr)>2){
784 len = strlen(mouseStr);
788 if(mouseStr[i] ==
';')
break;
790 sscanf(&mouseStr[ii],
"%d,%d,%d,%d,%d;",&mev,&button,&ix,&iy,&ID);
792 fwl_handle_mouse0(mev, button, ix, iy, ID);
799 fwl_RenderSceneUpdateSceneTARGETWINDOWS();
802extern void (*fwl_do_rawKeyPressPTR)(
int key,
int type);
803extern int (*fwl_handle_mousePTR)(
const int mev,
const unsigned int button,
int x,
int y,
int windex);
804extern void (*fwl_RenderSceneUpdateScenePTR)();
805extern void (*handlePTR)(
const int mev,
const unsigned int button,
const float x,
const float y);
806extern char * (*nameLogFileFolderPTR)(
char *logfilename,
int size);
807void SnapshotTesting_setHandlers(){
808 fwl_do_rawKeyPressPTR = fwl_do_rawKeyPressTESTING;
809 fwl_handle_mousePTR = fwl_handle_aqua_TESTING;
810 fwl_RenderSceneUpdateScenePTR = fwl_RenderSceneUpdateSceneTESTING;
812 nameLogFileFolderPTR = nameLogFileFolderTESTING;