21 #ifndef USE_SNAPSHOT_TESTING
23 void fwl_set_modeRecord()
26 void fwl_set_modeFixture()
29 void fwl_set_modePlayback()
32 void fwl_set_nameTest(
char *nameTest)
35 #endif //ifndef USE_SNAPSHOT_TESTING
38 #ifdef USE_SNAPSHOT_TESTING
103 #include <internal.h>
104 void set_snapshotModeTesting(
int value);
105 int isSnapshotModeTesting();
111 struct keypressTuple{
124 struct playbackRecord {
134 typedef struct tSnapshotTesting{
137 static tSnapshotTesting SnapshotTesting;
140 typedef struct pSnapshotTesting{
142 char* recordingFName;
149 struct playbackRecord* playback;
152 struct keypressTuple keypressQueue[50];
153 int keypressQueueCount;
154 struct mouseTuple mouseQueue[50];
157 }* ppSnapshotTesting;
158 void *SnapshotTesting_constructor(){
159 void *v = MALLOCV(
sizeof(
struct pSnapshotTesting));
160 memset(v,0,
sizeof(
struct pSnapshotTesting));
163 void SnapshotTesting_init(
struct tSnapshotTesting *t){
166 t->prv = SnapshotTesting_constructor();
168 ppSnapshotTesting p = (ppSnapshotTesting)t->prv;
169 p->recordingFile = NULL;
170 p->recordingFName = NULL;
171 p->modeRecord = FALSE;
172 p->modeFixture = FALSE;
173 p->modePlayback = FALSE;
176 p->playbackCount = 0;
180 p->keypressQueueCount=0;
181 p->mouseQueueCount=0;
184 void SnapshotTesting_setHandlers();
186 static int rtestinit = 0;
187 static ppSnapshotTesting get_ppSnapshotTesting(){
189 SnapshotTesting_init(&SnapshotTesting);
191 ppSnapshotTesting p = (ppSnapshotTesting)SnapshotTesting.prv;
192 SnapshotTesting_setHandlers();
194 return (ppSnapshotTesting)SnapshotTesting.prv;
197 int dequeueKeyPress(ppSnapshotTesting p,
int *
key,
int *type){
198 if(p->keypressQueueCount > 0){
200 p->keypressQueueCount--;
201 *key = p->keypressQueue[0].key;
202 *type = p->keypressQueue[0].type;
203 for(i=0;i<p->keypressQueueCount;i++){
204 p->keypressQueue[i].key = p->keypressQueue[i+1].key;
205 p->keypressQueue[i].type = p->keypressQueue[i+1].type;
212 void queueKeyPress(ppSnapshotTesting p,
int key,
int type){
213 if(p->keypressQueueCount < 50){
214 p->keypressQueue[p->keypressQueueCount].key = key;
215 p->keypressQueue[p->keypressQueueCount].type = type;
216 p->keypressQueueCount++;
220 int dequeueMouse(ppSnapshotTesting p,
int *mev,
unsigned int *button,
float *x,
float *y){
221 if(p->mouseQueueCount > 0){
223 p->mouseQueueCount--;
224 *mev = p->mouseQueue[0].mev;
225 *button = p->mouseQueue[0].button;
226 *x = p->mouseQueue[0].x;
227 *y = p->mouseQueue[0].y;
228 for(i=0;i<p->mouseQueueCount;i++){
229 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
230 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
231 p->mouseQueue[i].x = p->mouseQueue[i+1].x;
232 p->mouseQueue[i].y = p->mouseQueue[i+1].y;
238 int dequeueMouseMulti(ppSnapshotTesting p,
int *mev,
unsigned int *button,
int *ix,
int *iy,
int *ID){
239 if(p->mouseQueueCount > 0){
241 p->mouseQueueCount--;
242 *mev = p->mouseQueue[0].mev;
243 *button = p->mouseQueue[0].button;
244 *ix = p->mouseQueue[0].ix;
245 *iy = p->mouseQueue[0].iy;
246 *ID = p->mouseQueue[0].ID;
247 for(i=0;i<p->mouseQueueCount;i++){
248 p->mouseQueue[i].mev = p->mouseQueue[i+1].mev;
249 p->mouseQueue[i].button = p->mouseQueue[i+1].button;
250 p->mouseQueue[i].ix = p->mouseQueue[i+1].ix;
251 p->mouseQueue[i].iy = p->mouseQueue[i+1].iy;
252 p->mouseQueue[i].ID = p->mouseQueue[i+1].ID;
259 void queueMouseMulti(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const int ix,
const int iy,
int ID){
260 if(p->mouseQueueCount < 50){
261 p->mouseQueue[p->mouseQueueCount].mev = mev;
262 p->mouseQueue[p->mouseQueueCount].button = button;
263 p->mouseQueue[p->mouseQueueCount].ix = ix;
264 p->mouseQueue[p->mouseQueueCount].iy = iy;
265 p->mouseQueue[p->mouseQueueCount].ID = ID;
266 p->mouseQueueCount++;
269 void queueMouse(ppSnapshotTesting p,
const int mev,
const unsigned int button,
const float x,
const float y){
270 if(p->mouseQueueCount < 50){
271 p->mouseQueue[p->mouseQueueCount].mev = mev;
272 p->mouseQueue[p->mouseQueueCount].button = button;
273 p->mouseQueue[p->mouseQueueCount].x = x;
274 p->mouseQueue[p->mouseQueueCount].y = y;
275 p->mouseQueueCount++;
280 void handleTESTING(
const int mev,
const unsigned int button,
const float x,
const float y)
285 p = get_ppSnapshotTesting();
288 if(p->modeRecord || p->modeFixture || p->modePlayback){
290 queueMouse(p,mev,button,x,y);
295 handle0(mev, button, x, y);
297 void fwl_do_keyPress0(
int key,
int type);
298 void fwl_do_rawKeyPressTESTING(
int key,
int type) {
302 p = get_ppSnapshotTesting();
305 queueKeyPress(p,key,type);
307 fwl_do_keyPress0(key,type);
310 void fwl_handle_aqua_multiNORMAL(
const int mev,
const unsigned int button,
int x,
int y,
int ID);
311 void fwl_handle_aqua_multiTESTING(
const int mev,
const unsigned int button,
int x,
int y,
int ID)
316 p = get_ppSnapshotTesting();
318 if(p->modeRecord || p->modeFixture || p->modePlayback){
320 queueMouseMulti(p,mev,button,x,y,ID);
325 fwl_handle_aqua_multiNORMAL(mev, button, x, y, ID);
328 void fwl_set_modeRecord()
333 p = get_ppSnapshotTesting();
334 p->modeRecord = TRUE;
336 void fwl_set_modeFixture()
341 p = get_ppSnapshotTesting();
342 p->modeFixture = TRUE;
344 void fwl_set_modePlayback()
349 p = get_ppSnapshotTesting();
350 p->modePlayback = TRUE;
352 void fwl_set_nameTest(
char *nameTest)
357 p = get_ppSnapshotTesting();
358 p->nameTest = STRDUP(nameTest);
361 char *nameLogFileFolderTESTING(
char *logfilename,
int size){
365 p = get_ppSnapshotTesting();
367 if(p->modePlayback || p->modeFixture){
369 strcat(logfilename,
"playback");
371 strcat(logfilename,
"fixture");
372 fw_mkdir(logfilename);
373 strcat(logfilename,
"/");
376 strcat(logfilename,p->nameTest);
377 }
else if(tg->Mainloop.scene_name){
379 strcat(logfilename,tg->Mainloop.scene_name);
380 if(tg->Mainloop.scene_suff){
381 strcat(logfilename,
"_");
382 strcat(logfilename,tg->Mainloop.scene_suff);
386 nameLogFileFolderNORMAL(logfilename,size);
392 int fw_mkdir(
char* path);
393 void fwl_RenderSceneUpdateScene0(
double dtime);
394 void fwl_RenderSceneUpdateSceneTESTING() {
401 p = get_ppSnapshotTesting();
404 dtime = Time1970sec();
405 if((p->modeRecord || p->modeFixture || p->modePlayback))
427 char buff[1000], keystrokes[200], mouseStr[1000];
430 char sceneName[1000];
443 if(!p->fwplayOpened){
444 char recordingName[1000];
447 recordingName[0] =
'\0';
449 if(tg->Mainloop.scene_name){
450 strcat(sceneName,tg->Mainloop.scene_name);
451 if(tg->Mainloop.scene_suff){
452 strcat(sceneName,
".");
453 strcat(sceneName,tg->Mainloop.scene_suff);
456 if(namingMethod==3 || namingMethod==4){
457 strcpy(recordingName,
"recording");
458 fw_mkdir(recordingName);
459 strcat(recordingName,
"/");
463 strcat(recordingName,p->nameTest);
465 strcat(recordingName,tg->Mainloop.scene_name);
466 k = strlen(recordingName);
469 j = strlen(tg->Mainloop.scene_suff);
471 strcat(recordingName,
"_");
472 strcat(recordingName,tg->Mainloop.scene_suff);
478 fw_mkdir(recordingName);
479 strcat(recordingName,
"/recording");
482 strcat(recordingName,
"recording");
483 strcat(recordingName,
".fwplay");
484 p->recordingFName = STRDUP(recordingName);
486 if(p->modeFixture || p->modePlayback){
488 p->recordingFile = fopen(p->recordingFName,
"r");
489 if(p->recordingFile == NULL){
490 printf(
"ouch recording file %s not found\n", p->recordingFName);
493 if( fgets(buff, 1000, p->recordingFile) != NULL){
494 char window_widthxheight[100], equals[50];
497 if( sscanf(buff,
"%s %s %d, %d\n",window_widthxheight,equals, &width,&height) == 4) {
498 if(width != tg->display.screenWidth || height != tg->display.screenHeight){
500 printf(
"Ouch - the test playback window size is different than recording:\n");
501 printf(
"recording %d x %d playback %d x %d\n",width,height,
502 tg->display.screenWidth,tg->display.screenHeight);
503 printf(
"hit Enter:");
508 if( fgets(buff, 1000, p->recordingFile) != NULL){
509 char scenefile[100], equals[50];
511 if( sscanf(buff,
"%s %s %s \n",scenefile,equals, sceneName) == 3) {
512 if(!tg->Mainloop.scene_name){
514 char* local_name = NULL;
516 if(strlen(sceneName)) url = STRDUP(sceneName);
518 splitpath_local_suffix(url, &local_name, &suff);
519 gglobal()->Mainloop.url = url;
520 gglobal()->Mainloop.scene_name = local_name;
521 gglobal()->Mainloop.scene_suff = suff;
522 fwl_resource_push_single_request(url);
530 int doEvents = (!fwl_isinputThreadParsing()) && (!fwl_isTextureParsing()) && fwl_isInputThreadInitialized();
535 if(dtime - tg->Mainloop.TickTime < .5)
return;
541 if(p->frameNum == 1){
542 p->recordingFile = fopen(p->recordingFName,
"w");
543 if(p->recordingFile == NULL){
544 printf(
"ouch recording file %s not found\n", p->recordingFName);
548 fprintf(p->recordingFile,
"window_wxh = %d, %d \n",tg->display.screenWidth,tg->display.screenHeight);
549 fprintf(p->recordingFile,
"scenefile = %s \n",tg->Mainloop.url);
551 strcpy(keystrokes,
"\"");
552 while(dequeueKeyPress(p,&key,&type)){
553 sprintf(temp,
"%d,%d,",key,type);
554 strcat(keystrokes,temp);
556 strcat(keystrokes,
"\"");
557 strcpy(mouseStr,
"\"");
559 while(dequeueMouseMulti(p,&mev, &button, &ix, &iy, &ID)){
560 sprintf(temp,
"%d,%d,%d,%d,%d;",mev,button,ix,iy,ID);
561 strcat(mouseStr,temp);
564 strcat(mouseStr,
"\"");
565 fprintf(p->recordingFile,
"%d %.6lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
568 sprintf(temp,
"%.6lf",dtime);
569 sscanf(temp,
"%lf",&dtime);
573 if(p->modeFixture || p->modePlayback){
576 if( fgets( buff, 1000, p->recordingFile ) != NULL ) {
577 if(sscanf(buff,
"%d %lf %s %s\n",&p->frameNum,&dtime,keystrokes,mouseStr) == 4){
578 if(0) printf(
"%d %lf %s %s\n",p->frameNum,dtime,keystrokes,mouseStr);
582 if(p->modeFixture) folder =
"fixture";
583 if(p->modePlayback) folder =
"playback";
586 if(p->modeRecord || p->modeFixture || p->modePlayback){
587 if(strlen(keystrokes)>2){
592 curr = &keystrokes[1];
593 while(curr && strlen(curr)>1){
597 sscanf(curr,
"%d",&key);
598 next = strchr(curr,
',');
600 sscanf(curr,
"%d",&type);
601 next = strchr(curr,
',');
603 if(p->modeFixture || p->modePlayback){
613 char *suff =
".snap";
615 sprintf(snapfile,
"%d",p->frameNum);
616 if(namingMethod == 0){
619 strcpy(snappath,folder);
620 strcat(snappath,suff);
621 fwl_set_SnapFile(snappath);
628 strcpy(snappath,tg->Mainloop.scene_name);
629 k = strlen(snappath);
632 j = strlen(tg->Mainloop.scene_suff);
634 strcat(snappath,
"_");
635 strcat(snappath,tg->Mainloop.scene_suff);
638 strcat(snappath,
"/");
639 strcat(snappath,folder);
642 strcat(snappath,
"/");
643 strcat(snappath,snapfile);
644 strcat(snappath,suff);
646 fwl_set_SnapFile(snappath);
648 if(namingMethod == 2){
654 strcpy(snappath,tg->Mainloop.scene_name);
655 k = strlen(snappath);
657 j= strlen(tg->Mainloop.scene_suff);
659 strcat(snappath,
"_");
660 strcat(snappath,tg->Mainloop.scene_suff);
662 strcat(snappath,
"_");
664 strcat(snappath,folder);
665 strcat(snappath,
"_");
666 strcat(snappath,snapfile);
667 strcat(snappath,suff);
668 fwl_set_SnapFile(snappath);
670 if(namingMethod == 3){
676 strcpy(snappath,folder);
678 strcat(snappath,
"/");
679 strcat(snappath,tg->Mainloop.scene_name);
680 k = strlen(tg->Mainloop.scene_name);
682 j= strlen(tg->Mainloop.scene_suff);
684 strcat(snappath,
"_");
685 strcat(snappath,tg->Mainloop.scene_suff);
687 strcat(snappath,
"_");
689 strcat(snappath,snapfile);
690 strcat(snappath,suff);
691 fwl_set_SnapFile(snappath);
693 if(namingMethod == 4){
699 set_snapshotModeTesting(TRUE);
704 strcpy(snappath,folder);
706 fwl_set_SnapTmp(snappath);
710 strcat(snappath,p->nameTest);
712 if(tg->Mainloop.scene_name){
713 strcat(snappath,tg->Mainloop.scene_name);
714 if(tg->Mainloop.scene_suff)
716 strcat(snappath,sep);
717 strcat(snappath,tg->Mainloop.scene_suff);
721 fwl_set_SnapFile(snappath);
726 fwl_do_keyPress0(key, type);
729 if(strlen(mouseStr)>2){
734 len = strlen(mouseStr);
738 if(mouseStr[i] ==
';')
break;
740 sscanf(&mouseStr[ii],
"%d,%d,%d,%d,%d;",&mev,&button,&ix,&iy,&ID);
741 fwl_handle_aqua_multiNORMAL(mev,button,ix,iy,ID);
749 fwl_RenderSceneUpdateScene0(dtime);
751 extern void (*fwl_do_rawKeyPressPTR)(
int key,
int type);
752 extern void (*fwl_handle_aqua_multiPTR)(
const int mev,
const unsigned int button,
int x,
int y,
int ID);
753 extern void (*fwl_RenderSceneUpdateScenePTR)();
754 extern void (*handlePTR)(
const int mev,
const unsigned int button,
const float x,
const float y);
755 extern char * (*nameLogFileFolderPTR)(
char *logfilename,
int size);
756 void SnapshotTesting_setHandlers(){
757 fwl_do_rawKeyPressPTR = fwl_do_rawKeyPressTESTING;
758 fwl_handle_aqua_multiPTR = fwl_handle_aqua_multiTESTING;
759 fwl_RenderSceneUpdateScenePTR = fwl_RenderSceneUpdateSceneTESTING;
760 handlePTR = handleTESTING;
761 nameLogFileFolderPTR = nameLogFileFolderTESTING;
764 #endif //USE_SNAPSHOT_TESTING