23#include "../scenegraph/Viewer.h"
26#ifndef USE_SNAPSHOT_TESTING
31void fwl_set_modeFixture()
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);
358void fwl_set_modeFixture()
363 p = get_ppSnapshotTesting();
364 p->modeFixture = TRUE;
376void fwl_set_nameTest(
char *nameTest)
381 p = get_ppSnapshotTesting();
382 p->nameTest = STRDUP(nameTest);
384void fwl_set_testPath(
char *testPath)
390 p = get_ppSnapshotTesting();
391 p->testPath = STRDUP(testPath);
392 ierr = chdir(p->testPath);
395 mkdir(p->testPath, 0755);
396 ierr = chdir(p->testPath);
402 printf(
"current working directory= %s\n", cwd);
407char *nameLogFileFolderTESTING(
char *logfilename,
int size){
409 ttglobal tg = gglobal();
411 p = get_ppSnapshotTesting();
413 if(p->modePlayback || p->modeFixture){
415 strcat(logfilename,
"playback");
417 strcat(logfilename,
"fixture");
418 fw_mkdir(logfilename);
419 strcat(logfilename,
"/");
422 strcat(logfilename,p->nameTest);
423 }
else if(tg->Mainloop.scene_name){
425 strcat(logfilename,tg->Mainloop.scene_name);
426 if(tg->Mainloop.scene_suff){
427 strcat(logfilename,
"_");
428 strcat(logfilename,tg->Mainloop.scene_suff);
432 nameLogFileFolderNORMAL(logfilename,size);
438int fw_mkdir(
const char* path);
439void fwl_RenderSceneUpdateScene0(
double dtime);
440void fwl_RenderSceneUpdateSceneTARGETWINDOWS();
441void fwl_RenderSceneUpdateSceneTESTING() {
446 ttglobal tg = gglobal();
448 p = get_ppSnapshotTesting();
451 dtime = Time1970sec();
452 if((p->modeRecord || p->modeFixture || p->modePlayback))
474 char buff[1000], keystrokes[200], mouseStr[1000];
477 char sceneName[1000];
490 if(!p->fwplayOpened){
491 char recordingName[1000];
494 recordingName[0] =
'\0';
496 if(tg->Mainloop.scene_name){
497 strcat(sceneName,tg->Mainloop.scene_name);
498 if(tg->Mainloop.scene_suff){
499 strcat(sceneName,
".");
500 strcat(sceneName,tg->Mainloop.scene_suff);
503 if(namingMethod==3 || namingMethod==4){
504 strcpy(recordingName,
"recording");
505 fw_mkdir(recordingName);
506 strcat(recordingName,
"/");
510 strcat(recordingName,p->nameTest);
512 strcat(recordingName,tg->Mainloop.scene_name);
513 k = strlen(recordingName);
516 j = strlen(tg->Mainloop.scene_suff);
518 strcat(recordingName,
"_");
519 strcat(recordingName,tg->Mainloop.scene_suff);
525 fw_mkdir(recordingName);
526 strcat(recordingName,
"/recording");
529 strcat(recordingName,
"recording");
530 strcat(recordingName,
".fwplay");
531 p->recordingFName = STRDUP(recordingName);
533 if(p->modeFixture || p->modePlayback){
535 p->recordingFile = fopen(p->recordingFName,
"r");
536 if(p->recordingFile == NULL){
537 printf(
"ouch recording file %s not found\n", p->recordingFName);
540 if( fgets(buff, 1000, p->recordingFile) != NULL){
541 char window_widthxheight[100], equals[50];
544 if( sscanf(buff,
"%s %s %d, %d\n",window_widthxheight,equals, &width,&height) == 4) {
545 if(width != tg->display.screenWidth || height != tg->display.screenHeight){
547 printf(
"Ouch - the test playback window size is different than recording:\n");
548 printf(
"recording %d x %d playback %d x %d\n",width,height,
549 tg->display.screenWidth,tg->display.screenHeight);
550 printf(
"hit Enter:");
555 if( fgets(buff, 1000, p->recordingFile) != NULL){
556 char scenefile[100], equals[50];
558 if( sscanf(buff,
"%s %s %s \n",scenefile,equals, sceneName) == 3) {
559 if(!tg->Mainloop.scene_name){
561 char* local_name = NULL;
563 if(strlen(sceneName)) url = STRDUP(sceneName);
565 splitpath_local_suffix(url, &local_name, &suff);
566 gglobal()->Mainloop.url = url;
567 gglobal()->Mainloop.scene_name = local_name;
568 gglobal()->Mainloop.scene_suff = suff;
569 fwl_resource_push_single_request(url);
577 int doEvents = (!fwl_isinputThreadParsing()) && (!fwl_isTextureParsing()) && fwl_isInputThreadInitialized();
582 if(dtime - tg->Mainloop.TickTime < .5)
return;
588 if(p->frameNum == 1){
593 printf(
"current working directory= %s\n", cwd);
595 p->recordingFile = fopen(p->recordingFName,
"w");
596 if(p->recordingFile == NULL){
597 printf(
"ouch recording file %s not found\n", p->recordingFName);
601 fprintf(p->recordingFile,
"window_wxh = %d, %d \n",tg->display.screenWidth,tg->display.screenHeight);
602 fprintf(p->recordingFile,
"scenefile = %s \n",tg->Mainloop.url);
604 strcpy(keystrokes,
"\"");
605 while(dequeueKeyPress(p,&
key,&type)){
606 sprintf(temp,
"%d,%d,",
key,type);
607 strcat(keystrokes,temp);
609 strcat(keystrokes,
"\"");
610 strcpy(mouseStr,
"\"");
612 while(dequeueMouseMulti(p,&mev, &button, &ix, &iy, &ID)){
613 sprintf(temp,
"%d,%d,%d,%d,%d;",mev,button,ix,iy,ID);
614 strcat(mouseStr,temp);
617 strcat(mouseStr,
"\"");
618 fprintf(p->recordingFile,
"%d %.6lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
621 sprintf(temp,
"%.6lf",dtime);
622 sscanf(temp,
"%lf",&dtime);
626 if(p->modeFixture || p->modePlayback){
629 if( fgets( buff, 1000, p->recordingFile ) != NULL ) {
630 if(sscanf(buff,
"%d %lf %s %s\n",&p->frameNum,&dtime,keystrokes,mouseStr) == 4){
631 if(0) printf(
"%d %lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
635 if(p->modeFixture) folder =
"fixture";
636 if(p->modePlayback) folder =
"playback";
639 if(p->modeRecord || p->modeFixture || p->modePlayback){
640 if(strlen(keystrokes)>2){
645 curr = &keystrokes[1];
646 while(curr && strlen(curr)>1){
650 sscanf(curr,
"%d",&
key);
651 next = strchr(curr,
',');
653 sscanf(curr,
"%d",&type);
654 next = strchr(curr,
',');
656 if(p->modeFixture || p->modePlayback){
666 char *suff =
".snap";
668 sprintf(snapfile,
"%d",p->frameNum);
669 if(namingMethod == 0){
672 strcpy(snappath,folder);
673 strcat(snappath,suff);
674 fwl_set_SnapFile(snappath);
681 strcpy(snappath,tg->Mainloop.scene_name);
682 k = strlen(snappath);
685 j = strlen(tg->Mainloop.scene_suff);
687 strcat(snappath,
"_");
688 strcat(snappath,tg->Mainloop.scene_suff);
691 strcat(snappath,
"/");
692 strcat(snappath,folder);
695 strcat(snappath,
"/");
696 strcat(snappath,snapfile);
697 strcat(snappath,suff);
699 fwl_set_SnapFile(snappath);
701 if(namingMethod == 2){
707 strcpy(snappath,tg->Mainloop.scene_name);
708 k = strlen(snappath);
710 j= strlen(tg->Mainloop.scene_suff);
712 strcat(snappath,
"_");
713 strcat(snappath,tg->Mainloop.scene_suff);
715 strcat(snappath,
"_");
717 strcat(snappath,folder);
718 strcat(snappath,
"_");
719 strcat(snappath,snapfile);
720 strcat(snappath,suff);
721 fwl_set_SnapFile(snappath);
723 if(namingMethod == 3){
729 strcpy(snappath,folder);
731 strcat(snappath,
"/");
732 strcat(snappath,tg->Mainloop.scene_name);
733 k = strlen(tg->Mainloop.scene_name);
735 j= strlen(tg->Mainloop.scene_suff);
737 strcat(snappath,
"_");
738 strcat(snappath,tg->Mainloop.scene_suff);
740 strcat(snappath,
"_");
742 strcat(snappath,snapfile);
743 strcat(snappath,suff);
744 fwl_set_SnapFile(snappath);
746 if(namingMethod == 4){
752 set_snapshotModeTesting(TRUE);
757 strcpy(snappath,folder);
759 fwl_set_SnapTmp(snappath);
763 strcat(snappath,p->nameTest);
765 if(tg->Mainloop.scene_name){
766 strcat(snappath,tg->Mainloop.scene_name);
767 if(tg->Mainloop.scene_suff)
769 strcat(snappath,sep);
770 strcat(snappath,tg->Mainloop.scene_suff);
774 fwl_set_SnapFile(snappath);
779 fwl_do_keyPress0(
key, type);
783 if(strlen(mouseStr)>2){
788 len = strlen(mouseStr);
792 if(mouseStr[i] ==
';')
break;
794 sscanf(&mouseStr[ii],
"%d,%d,%d,%d,%d;",&mev,&button,&ix,&iy,&ID);
796 fwl_handle_mouse0(mev, button, ix, iy, ID);
803 fwl_RenderSceneUpdateSceneTARGETWINDOWS();
806extern void (*fwl_do_rawKeyPressPTR)(
int key,
int type);
807extern int (*fwl_handle_mousePTR)(
const int mev,
const unsigned int button,
int x,
int y,
int windex);
808extern void (*fwl_RenderSceneUpdateScenePTR)();
809extern void (*handlePTR)(
const int mev,
const unsigned int button,
const float x,
const float y);
810extern char * (*nameLogFileFolderPTR)(
char *logfilename,
int size);
811void SnapshotTesting_setHandlers(){
812 fwl_do_rawKeyPressPTR = fwl_do_rawKeyPressTESTING;
813 fwl_handle_mousePTR = fwl_handle_aqua_TESTING;
814 fwl_RenderSceneUpdateScenePTR = fwl_RenderSceneUpdateSceneTESTING;
816 nameLogFileFolderPTR = nameLogFileFolderTESTING;