void CInfiniteMediatorTest::testSkipSome() { tearDown(); int nToSkip=4; std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); std::string modeloutfname("./model-skip-run-0000-00.evt"); // Generate the file to compare against that we manually skipped over setUpSkipTestFile(nToSkip, proto+infname, modeloutfname); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(new CTransparentFilter); m_mediator->setSkipCount(nToSkip); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } CPPUNIT_ASSERT( filesEqual(modeloutfname,outfname) ); // cleanup remove(outfname.c_str()); remove(modeloutfname.c_str()); }
void CInfiniteMediatorTest::testFilterReturnsNULL() { tearDown(); // Set up the mediator std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy2-run-0000-00.evt"); // std::ifstream ifile (infname.c_str()); // std::ofstream ofile (outfname.c_str()); // m_source = new CIStreamDataSource(ifile); // m_sink = new COStreamDataSink(ofile); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_filter = new CNullFilter; m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(m_filter); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } struct stat st; stat(outfname.c_str(), &st); CPPUNIT_ASSERT_EQUAL( 0, int(st.st_size) ); remove(outfname.c_str()); }
void CInfiniteMediatorTest::testProcessSome() { tearDown(); int nToProcess=11; std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_filter = new CTestFilter; m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(m_filter); m_mediator->setProcessCount(nToProcess); m_mediator->mainLoop(); CPPUNIT_ASSERT_EQUAL(nToProcess, static_cast<CTestFilter*>(m_filter)->getNProcessed()); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } remove(outfname.c_str()); }
void CInfiniteMediatorTest::testSkipNone() { tearDown(); // This should have no effect on any default behavior // We will simply test this as the TransparentMainLoop m_mediator = new CInfiniteMediator(0,0,0); m_mediator->setSkipCount(0); std::string proto("file://"); std::string infname("./run-0000-00.evt"); std::string outfname("./copy-run-0000-00.evt"); try { URL uri(proto+infname); m_source = new CFileDataSource(uri, std::vector<uint16_t>()); m_sink = new CFileDataSink(outfname); m_mediator->setDataSource(m_source); m_mediator->setDataSink(m_sink); m_mediator->setFilter(new CTransparentFilter); m_mediator->mainLoop(); // kill all of the sinks and sources tearDown(); // set up defaults so that we don't segfault at tearDown setUp(); } catch (CException& exc) { std::stringstream errmsg; errmsg << "Caught exception:" << exc.ReasonText(); CPPUNIT_FAIL(errmsg.str().c_str()); } catch (int errcode) { std::stringstream errmsg; errmsg << "Caught integer " << errcode; CPPUNIT_FAIL(errmsg.str().c_str()); } catch (std::string errmsg) { CPPUNIT_FAIL(errmsg.c_str()); } CPPUNIT_ASSERT( filesEqual(infname,outfname) ); remove(outfname.c_str()); }
struct file_list *locate_files(char *fpath,char *prefix, double stime,double etime) { char filename[1024]; char tmp[256]; char dir[256]; char fname[256]; char ofname[256]; char *flist[4096]; int fcnt=0; int status; int dyval; struct dirent **dlist=NULL; int yr,mo,dy,hr,mt; double sc; int m; int state=0; int syr,eyr; int sdyval,edyval; struct file_list *ptr; ptr=malloc(sizeof(struct file_list)); ptr->cnt=0; ptr->fname=NULL; ofname[0]=0; /* The yearc check should look one month either side of the desired period to make sure that we catch all possible files that might contain the requested period, even if they span directories. */ TimeEpochToYMDHMS(stime-ONE_MONTH,&syr,&mo,&dy,&hr,&mt,&sc); TimeEpochToYMDHMS(etime+ONE_MONTH,&eyr,&mo,&dy,&hr,&mt,&sc); TimeEpochToYMDHMS(stime,&yr,&mo,&dy,&hr,&mt,&sc); sdyval=yr*10000+mo*100+dy; TimeEpochToYMDHMS(etime,&yr,&mo,&dy,&hr,&mt,&sc); edyval=yr*10000+mo*100+dy; for (yr=syr;yr<=eyr;yr++) { sprintf(dir,"%s/%.4d",fpath,yr); status=scandir(dir,&dlist,dsel,alphasort); if (status<=0) continue; /* now get only the most recent version numbers of the files */ fcnt=0; for (m=0;m<status;m++) { if ((prefix !=NULL) && (infname(dlist[m]->d_name,prefix) ==0)) continue; if (fcnt==0) { flist[fcnt]=dlist[m]->d_name; fcnt++; } else { strcpy(tmp,dlist[m]->d_name); strcpy(tmp+128,flist[fcnt-1]); tmp[18]=0; tmp[128+18]=0; if (strcmp(tmp,tmp+128)==0) flist[fcnt-1]=dlist[m]->d_name; else { flist[fcnt]=dlist[m]->d_name; fcnt++; } } } for (m=0;m<fcnt;m++) { strcpy(tmp,flist[m]); strcpy(fname,flist[m]); tmp[18]=0; dyval=atoi(tmp+10); if ((dyval>=sdyval) && (state==0)) { if (ofname[0] !=0) { sprintf(filename,"%s/%s",dir,ofname); status=test_file_epoch(filename,stime,etime); if (status==1) { if (ptr->fname==NULL) ptr->fname=malloc(sizeof(char *)); else ptr->fname=realloc(ptr->fname, (ptr->cnt+1)*sizeof(char *)); ptr->fname[ptr->cnt]=malloc(strlen(filename)+1); strcpy(ptr->fname[ptr->cnt],filename); ptr->cnt++; } } state=1; } if ((state==1) && (dyval<=edyval)) { sprintf(filename,"%s/%s",dir,fname); status=test_file_epoch(filename,stime,etime); if (status==1) { if (ptr->fname==NULL) ptr->fname=malloc(sizeof(char *)); else ptr->fname=realloc(ptr->fname, (ptr->cnt+1)*sizeof(char *)); ptr->fname[ptr->cnt]=malloc(strlen(filename)+1); strcpy(ptr->fname[ptr->cnt],filename); ptr->cnt++; } } else if (state==1) state=2; strcpy(ofname,fname); } } return ptr; }
void design (void) { int updflag=0; int dx,dy,tempx,n; int lastcell=1; int tempint; int drawmode=0; char tempstr[32]; char tempfname[32]; char tempstr2[12]; char tempstr3[32]; int new_col=0; int bc_x=0,bc_y=0,bc_w=0,bc_h=0; // Block copy x,y and width,height int tx,ty; disy=0; designflag=1; gamecount=0; tempstr[0]='\0'; tempfname[0]='\0'; setorigin(); dx=objs[0].x/16; dy=objs[0].y/16; drawboard(); fontcolor (&statvp,1,0); clearvp (&statvp); do { if (drawmode) { setboard (dx,dy,lastcell); drawcell (dx,dy); updflag=1; } fontcolor (&statvp,3,0); // memory usage wprint (&statvp,248,1,2," "); ultoa (coreleft(),tempstr3,10); wprint (&statvp,290-(1+strlen(tempstr3)*6),1,2,tempstr3); tempstr3[0]='\0'; fontcolor (&statvp,1,0); wprint (&statvp,248,21,2, "# objs: "); fontcolor (&statvp,3,0); wprint (&statvp,296,21,2,itoa(numobjs,tempstr2,10)); drawshape (&gamevp,0x0100,dx*16+4,dy*16+4); do { checkctrl(0); } while ((dx1==0)&&(dy1==0)&&(key==0)&&(updflag==0)); updflag=0; modboard(dx,dy); upd_objs(0); refresh(0); purgeobjs(); if ((dx1!=0)||(dy1!=0)) { dx+=dx1*(1+fire1*(scrnxs/2-1)); dy+=dy1*(1+fire1*(scrnys/2-1)); if (dx<0) dx=0; if (dx>=boardxs) dx=boardxs-1; if (dy<0) dy=0; if (dy>=boardys) dy=boardys-1; if ((dx*16)<gamevp.vpox) { gamevp.vpox-=scrnxs*8; if (gamevp.vpox<0) gamevp.vpox=0; drawboard(); }; if ((dx*16)>=(gamevp.vpox+16*scrnxs-16)) { gamevp.vpox+=scrnxs*8; if (gamevp.vpox>=(16*(boardxs-scrnxs)+8)) gamevp.vpox=16*(boardxs-scrnxs)+8; drawboard(); }; if ((16*dy)<gamevp.vpoy) { gamevp.vpoy-=scrnys*8; if (gamevp.vpoy<0) gamevp.vpoy=0; drawboard(); }; if ((16*dy)>=(gamevp.vpoy+16*(scrnys-1))) { gamevp.vpoy+=scrnys*8; if (gamevp.vpoy>=(16*(boardys-scrnys+1))) gamevp.vpoy=(boardys-scrnys+1)*16; drawboard(); }; }; switch (toupper(key)) { case k_f1: // Mark top left corner of block bc_x=dx; bc_y=dy; break; case k_f2: // Mark bottom right corner of block and copy // block of tile numbers into temp array bc_array if(dx<bc_x) break; // 0-width or negative width rectangle (can't do that) if(dy<bc_y) break; // 0-height or negative height rectangle (can't do that) bc_w=(dx-bc_x)+1; bc_h=(dy-bc_y)+1; if((bc_w>normxs)||(bc_h>normys)) { // Too big!! bc_w=0; bc_h=0; break; }; for(ty=0; ty<bc_h; ty++) { for(tx=0; tx<bc_w; tx++) { bc_array[(ty*bc_w)+tx]=board(bc_x+tx,bc_y+ty); }; }; break; case k_f3: for(ty=0; ty<bc_h; ty++) { for(tx=0; tx<bc_w; tx++) { setboard(dx+tx, dy+ty, bc_array[(ty*bc_w)+tx]); }; }; updflag=1; break; case k_f4: do { upd_colors (); gamecount++; checkctrl0(0); } while (key==0); break; case enter: clearvp (&statvp); wprint (&statvp,2,1,1,"Put:"); fontcolor (&statvp,6,0); winput (&statvp,2,11,1,tempstr,16); strupr (tempstr); for (tempint=0; tempint<numinfotypes; tempint++) { if (strcmp (tempstr,info[tempint].na)==0) { lastcell=tempint; setboard(dx,dy,tempint); shm_want[(info[tempint].sh>>8)&0x3f]=1; shm_do(); break; }; }; updflag=1; break; case 9: drawmode=!drawmode; break; // tab case 'K': lastcell=board(dx,dy); break; case ' ': setboard(dx,dy,lastcell); updflag=1; break; case 'I': pl.score=1000; printhi (1); pl.score=0; break; case 'V': if (pl.numinv==0) addinv (inv_hero); else { pl.numinv=0; init_inv(); }; pl.score=0; pl.level=0; break; case 'H': tempint=board(dx,dy); tempx=dx; while (board(tempx,dy)==tempint) { setboard(tempx,dy,lastcell); drawcell (tempx,dy); tempx--; }; tempx=dx+1; while (board(tempx,dy)==tempint) { setboard(tempx,dy,lastcell); drawcell (tempx,dy); tempx++; }; break; case 'O': updflag=objdesign(dx,dy); break; // Object Mgmt case 'U': for (n=0; n<numobjs; n++) { // if (((kindflags[objs[n].objkind]&f_inside)==0)&& // (objs[n].inside!=NULL)) { // objs[n].inside=NULL; // sound(240); // delay(500); // nosound(); // }; setobjsize (n); }; break; case 'Z': infname ("Clear?",tempfname); if (toupper(tempfname[0])=='Y') { init_brd(); init_objs(); drawboard(); }; break; case 'L': infname ("Load:",tempfname); if (tempfname[0]!='\0') { loadboard (tempfname); setorigin(); dx=objs[0].x/16; dy=objs[0].y/16; drawboard(); }; break; case 'Y': // Disalign Y clearvp (&statvp); wprint (&statvp,2,1,1,"Dis Y:"); itoa (disy,tempstr,10); winput (&statvp,2,11,1,tempstr,16); disy=atoi (tempstr); strupr (tempstr); break; case 'N': infname ("New board?",tempfname); if (toupper (tempfname[0])=='Y') { zapobjs(); init_brd(); }; break; case 'S': infname ("Save:",tempfname); if (tempfname[0]!='\0') saveboard (tempfname); break; case 'C': clearvp (&statvp); wprint (&statvp,2,1,1,"New Color:"); fontcolor (&statvp,6,0); itoa (new_col,tempstr,10); winput (&statvp,2,11,1,tempstr,16); new_col=atoi (tempstr); switch (new_col) { case 0: setcolor (250,0,0,0); setcolor (251,0,0,0); break; // reset all case 1: setcolor (251,0,0,0); break; // reset #251 case 2: setcolor (250,0,0,32); // dk. blue sky setcolor (251,0,0,32); break; case 3: // lt. blue sky setcolor (176,8,16,25); setcolor (177,8,20,29); setcolor (178,12,24,33); setcolor (179,16,28,41); setcolor (180,20,32,45); setcolor (181,24,40,49); setcolor (182,28,44,57); setcolor (183,36,48,60); setcolor (250,36,48,60); setcolor (251,36,48,60); break; case 4: // yellow sky setcolor (176,32,0,0); setcolor (177,40,0,0); setcolor (178,52,0,0); setcolor (179,60,0,0); setcolor (180,60,28,0); setcolor (181,60,40,0); setcolor (182,60,52,0); setcolor (183,60,60,0); setcolor (250,60,60,0); setcolor (251,60,60,0); break; case 5: // emerald sky setcolor (176,0,12,12); setcolor (177,0,18,17); setcolor (178,0,25,23); setcolor (179,0,32,27); setcolor (180,0,39,32); setcolor (181,0,46,35); setcolor (182,0,53,38); setcolor (183,0,60,40); setcolor (250,0,60,40); setcolor (251,0,60,40); break; case 6: setcolor (250,32,32,24); // olive green setcolor (251,32,32,24); break; case 7: // violet sky setcolor (176,13,5,22); setcolor (177,18,8,27); setcolor (178,23,13,33); setcolor (179,29,19,39); setcolor (180,35,25,45); setcolor (181,42,32,51); setcolor (182,49,40,57); setcolor (183,57,50,63); setcolor (250,57,50,63); setcolor (251,57,50,63); break; case 8: setcolor (250,23,23,23); // factory grey setcolor (251,23,23,23); break; case 9: setcolor (250,12,23,63); // royal blue setcolor (251,12,23,63); break; case 10: setcolor (250,20,20,23); // factory grey v3 setcolor (251,20,20,23); break; }; }; } while (key!=escape);