/// @internal /// @brief Determine which tests need to be run and run them virtual void RunTests() { if (RunAutomaticTests==RunInteractiveTests && RunInteractiveTests==false) // enforce running automatic tests if no type of test is specified { RunAutomaticTests=true; } if (RunAll) { for(map<String,UnitTestGroup*>::iterator Iter=TestGroups.begin(); Iter!=TestGroups.end(); ++Iter) { TestGroupsToRun.push_back(Iter->first); } } if(ExecuteInThisMemorySpace) // Should we be executing the test right now? { for(std::vector<Mezzanine::String>::iterator CurrentTestName=TestGroupsToRun.begin(); CurrentTestName!=TestGroupsToRun.end(); ++CurrentTestName ) // Actually run the tests { try{ TestGroups[*CurrentTestName]->RunTests(RunAutomaticTests, RunInteractiveTests); } catch (std::exception e) { TestError << std::endl << e.what() << std::endl; // maybe we should log or somehting. } (*this) += *(TestGroups[*CurrentTestName]); } }else{ // No, We should be executing the test in a place that cannot possibly crash this program for(std::vector<Mezzanine::String>::iterator CurrentTestName=TestGroupsToRun.begin(); CurrentTestName!=TestGroupsToRun.end(); ++CurrentTestName ) { ClearTempFile(); if(system(String(CommandName + " " + *CurrentTestName + " " + MemSpaceArg + " " + Mezzanine::String(RunAutomaticTests?"automatic ":"") + Mezzanine::String(RunInteractiveTests?"interactive ":"")).c_str())) // Run a single unit test as another process { this->AddTestResult(String("Process::" + *CurrentTestName), Testing::Failed); }else { this->AddTestResult(String("Process::" + *CurrentTestName), Success); } try { (*this) += GetResultsFromTempFile(); } catch (std::exception& e) { TestError << e.what() << endl; } } DeleteTempFile(); } // \if(ExecuteInThisMemorySpace) } // \function
XFILE::CFile *CXBMCTestUtils::CreateCorruptedFile(std::string const& strFileName, std::string const& suffix) { XFILE::CFile inputfile, *tmpfile = CreateTempFile(suffix); unsigned char buf[20], tmpchar; unsigned int size, i; if (tmpfile && inputfile.Open(strFileName)) { srand(time(NULL)); while ((size = inputfile.Read(buf, sizeof(buf))) > 0) { for (i = 0; i < size; i++) { if ((rand() % RAND_MAX) < (probability * RAND_MAX)) { tmpchar = buf[i]; do { buf[i] = (rand() % 256); } while (buf[i] == tmpchar); } } if (tmpfile->Write(buf, size) < 0) { inputfile.Close(); tmpfile->Close(); DeleteTempFile(tmpfile); return NULL; } } inputfile.Close(); tmpfile->Close(); return tmpfile; } delete tmpfile; return NULL; }
bool RDRenderer::renderToCart(unsigned cartnum,int cutnum,RDLogEvent *log, RDSettings *s,const QTime &start_time, bool ignore_stops,QString *err_msg, int first_line,int last_line, const QTime &first_time,const QTime &last_time) { QString temp_output_filename; char tempdir[PATH_MAX]; bool ok=false; if(first_line<0) { first_line=0; } if(last_line<0) { last_line=log->size(); } // // Check that we won't overflow the 32 bit BWF structures // when we go to import the rendered log back into the audio store // if((double)log->length(first_line,last_line-1)/1000.0>= (1073741824.0/((double)s->channels()*(double)s->sampleRate()))) { *err_msg=tr("Rendered log is too long!"); return false; } ProgressMessage(tr("Pass 1 of 2")); render_total_passes=2; // // Verify Destination // if(!RDCart::exists(cartnum)) { *err_msg=tr("no such cart"); return false; } if(!RDCut::exists(cartnum,cutnum)) { *err_msg=tr("no such cut"); return false; } // // Get Temporary File // strncpy(tempdir,RDTempDirectory::basePath()+"/rdrenderXXXXXX",PATH_MAX); temp_output_filename=QString(mkdtemp(tempdir))+"/log.wav"; ProgressMessage(tr("Using temporary file")+" \""+temp_output_filename+"\"."); // // Render It // if(!Render(temp_output_filename,log,s,start_time,ignore_stops,err_msg, first_line,last_line,first_time,last_time)) { return false; } // // Convert It // ProgressMessage(tr("Pass 2 of 2")); ProgressMessage(tr("Importing cart")); ok=ImportCart(temp_output_filename,cartnum,cutnum,s->channels(),err_msg); DeleteTempFile(temp_output_filename); emit lineStarted(log->size()+1,log->size()+1); if(!ok) { return false; } return true; }
bool RDRenderer::renderToFile(const QString &outfile,RDLogEvent *log, RDSettings *s,const QTime &start_time, bool ignore_stops,QString *err_msg, int first_line,int last_line, const QTime &first_time,const QTime &last_time) { QString temp_output_filename; char tempdir[PATH_MAX]; bool ok=false; FILE *f=NULL; bool ret; // // Verify Destination // if((f=fopen(outfile,"w"))==NULL) { *err_msg=tr("unable to open output file")+" ["+QString(strerror(errno))+"]"; return false; } fclose(f); if(((s->format()!=RDSettings::Pcm16)&&(s->format()!=RDSettings::Pcm24))|| (s->normalizationLevel()!=0)) { ProgressMessage("Pass 1 of 2"); render_total_passes=2; // // Get Temporary File // strncpy(tempdir,RDTempDirectory::basePath()+"/rdrenderXXXXXX",PATH_MAX); temp_output_filename=QString(mkdtemp(tempdir))+"/log.wav"; ProgressMessage(tr("Using temporary file")+" \""+temp_output_filename+"\"."); // // Render It // if(!Render(temp_output_filename,log,s,start_time,ignore_stops,err_msg, first_line,last_line,first_time,last_time)) { return false; } // // Convert It // ProgressMessage(tr("Pass 2 of 2")); ProgressMessage(tr("Writing output file")); ok=ConvertAudio(temp_output_filename,outfile,s,err_msg); DeleteTempFile(temp_output_filename); emit lineStarted(log->size()+1,log->size()+1); if(!ok) { return false; } } else { ProgressMessage(tr("Pass 1 of 1")); render_total_passes=1; ret=Render(outfile,log,s,start_time,ignore_stops,err_msg, first_line,last_line,first_time,last_time); emit lineStarted(log->size(),log->size()); return ret; } return true; }