/* **************************************************************************** * * fill - */ TEST(StatusCode, fill) { StatusCode sc; StatusCode sc2(SccOk, "Details"); StatusCode ec(SccBadRequest, "Very bad request :-)"); std::string out; utInit(); sc.fill(SccForbidden, "D"); EXPECT_EQ(sc.code, SccForbidden); EXPECT_STREQ(sc.reasonPhrase.c_str(), "Forbidden"); EXPECT_STREQ(sc.details.c_str(), "D"); sc.fill(&sc2); EXPECT_EQ(sc.code, SccOk); EXPECT_STREQ(sc.reasonPhrase.c_str(), "OK"); EXPECT_STREQ(sc.details.c_str(), "Details"); sc.fill(&ec); EXPECT_EQ(sc.code, SccBadRequest); EXPECT_STREQ(sc.reasonPhrase.c_str(), "Bad Request"); EXPECT_STREQ(sc.details.c_str(), "Very bad request :-)"); utExit(); }
/* **************************************************************************** * * render - */ TEST(StatusCode, render) { StatusCode sc1; StatusCode sc2(SccOk, ""); StatusCode sc3(SccOk, "DETAILS"); StatusCode sc4(SccOk, "DETAILS"); std::string out; const char* outfile1 = "ngsi.statusCode.render1.valid.xml"; const char* outfile2 = "ngsi.statusCode.render2.valid.xml"; const char* outfile3 = "ngsi.statusCode.render3.valid.xml"; const char* outfile4 = "ngsi.statusCode.render4.middle.json"; utInit(); out = sc1.render(XML, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); out = sc2.render(XML, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); out = sc3.render(XML, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); out = sc4.render(JSON, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); sc1.release(); // just to exercise the code ... utExit(); }
void TDEConfigTest::allTests() { writeConfigFile(); TDEConfig sc2( "tdeconfigtest" ); TDEConfigGroup sc3( &sc2, "AAA"); bool bImmutable = sc3.entryIsImmutable("stringEntry1"); CHECK( bImmutable, false ); //tqWarning("sc3.entryIsImmutable() 1: %s", bImmutable ? "true" : "false"); sc2.setGroup("AAA"); CHECK( sc2.hasKey( "stringEntry1" ), true ); CHECK( sc2.readEntry( "stringEntry1" ), TQString( STRINGENTRY1 ) ); CHECK( sc2.entryIsImmutable("stringEntry1"), bImmutable ); CHECK( sc2.hasKey( "stringEntry2" ), false ); CHECK( sc2.readEntry( "stringEntry2", "bla" ), TQString( "bla" ) ); CHECK( sc2.hasDefault( "stringEntry1" ), false ); sc2.setGroup("Hello"); CHECK( sc2.readEntry( "Test" ), TQString::fromLocal8Bit( LOCAL8BITENTRY ) ); CHECK( sc2.readEntry("Test2", "Fietsbel").isEmpty(), true ); CHECK( sc2.readEntry( "stringEntry1" ), TQString( STRINGENTRY1 ) ); CHECK( sc2.readEntry( "stringEntry2" ), TQString( STRINGENTRY2 ) ); CHECK( sc2.readEntry( "stringEntry3" ), TQString( STRINGENTRY3 ) ); CHECK( sc2.readEntry( "stringEntry4" ), TQString( STRINGENTRY4 ) ); CHECK( sc2.hasKey( "stringEntry5" ), false); CHECK( sc2.readEntry( "stringEntry5", "test" ), TQString( "test" ) ); CHECK( sc2.hasKey( "stringEntry6" ), false); CHECK( sc2.readEntry( "stringEntry6", "foo" ), TQString( "foo" ) ); CHECK( sc2.readBoolEntry( "boolEntry1" ), BOOLENTRY1 ); CHECK( sc2.readBoolEntry( "boolEntry2" ), BOOLENTRY2 ); #if 0 TQString s; s = sc2.readEntry( "keywith=equalsign" ); fprintf(stderr, "comparing keywith=equalsign %s with %s -> ", STRINGENTRY1, s.latin1()); if (s == STRINGENTRY1) fprintf(stderr, "OK\n"); else { fprintf(stderr, "not OK\n"); exit(-1); } #endif sc2.setGroup("Bye"); CHECK( sc2.readPointEntry( "pointEntry" ), POINTENTRY ); CHECK( sc2.readSizeEntry( "sizeEntry" ), SIZEENTRY); CHECK( sc2.readRectEntry( "rectEntry" ), RECTENTRY ); CHECK( sc2.readDateTimeEntry( "dateTimeEntry" ).toString(), DATETIMEENTRY.toString() ); CHECK( sc2.readListEntry( "stringListEntry").join( "," ), STRINGLISTENTRY.join( "," ) ); }
int main(void) { for (int i = 0; i < 100; i+=12) { Counter::ScopeCounter<> sc("bla"); COUNT_THIS_SCOPE(__PRETTY_FUNCTION__); std::cout << i << '\n'; sc("main loop 2"); } Counter::ScopeCounter<1> sc("only shows when HAVE_COUNTERS > 1"); return 0; Counter::ScopeCounter<> sc2("doesn't show"); }
int main() { boost::signal<void (const std::string&)> sig; some_slot_type sc1("sc1"); some_slot_type sc2("sc2"); boost::signals::connection c1=sig.connect(sc1); boost::signals::connection c2=sig.connect(sc2); // 比较 std::cout << "c1==c2: " << (c1==c2) << '\n'; std::cout << "c1<c2: " << (c1<c2) << '\n'; // 检查连接 if (c1.connected()) std::cout << "c1 is connected to a signal\n"; // 交换并断开 sig("Hello there"); c1.swap(c2); sig("We've swapped the connections"); c1.disconnect(); sig("Disconnected c1, which referred to sc2 after the swap"); }
// // Main // int overlapLongMain(int argc, char** argv) { parseOverlapLongOptions(argc, argv); // Open output file std::ostream* pASQGWriter = createWriter(opt::outFile); // Build and write the ASQG header ASQG::HeaderRecord headerRecord; headerRecord.setOverlapTag(opt::minOverlap); headerRecord.setErrorRateTag(opt::errorRate); headerRecord.setInputFileTag(opt::readsFile); headerRecord.setTransitiveTag(true); headerRecord.write(*pASQGWriter); // Determine which index files to use. If a target file was provided, // use the index of the target reads std::string indexPrefix; if(!opt::targetFile.empty()) indexPrefix = stripFilename(opt::targetFile); else indexPrefix = stripFilename(opt::readsFile); BWT* pBWT = new BWT(indexPrefix + BWT_EXT, opt::sampleRate); SampledSuffixArray* pSSA = new SampledSuffixArray(indexPrefix + SAI_EXT, SSA_FT_SAI); Timer* pTimer = new Timer(PROGRAM_IDENT); pBWT->printInfo(); // Read the sequence file and write vertex records for each // Also store the read names in a vector of strings ReadTable reads; SeqReader* pReader = new SeqReader(opt::readsFile, SRF_NO_VALIDATION); SeqRecord record; while(pReader->get(record)) { reads.addRead(record.toSeqItem()); ASQG::VertexRecord vr(record.id, record.seq.toString()); vr.write(*pASQGWriter); if(reads.getCount() % 100000 == 0) printf("Read %zu sequences\n", reads.getCount()); } delete pReader; pReader = NULL; BWTIndexSet index; index.pBWT = pBWT; index.pSSA = pSSA; index.pReadTable = &reads; // Make a prefix for the temporary hits files size_t n_reads = reads.getCount(); omp_set_num_threads(opt::numThreads); #pragma omp parallel for for(size_t read_idx = 0; read_idx < n_reads; ++read_idx) { const SeqItem& curr_read = reads.getRead(read_idx); printf("read %s %zubp\n", curr_read.id.c_str(), curr_read.seq.length()); SequenceOverlapPairVector sopv = KmerOverlaps::retrieveMatches(curr_read.seq.toString(), opt::seedLength, opt::minOverlap, 1 - opt::errorRate, 100, index); printf("Found %zu matches\n", sopv.size()); for(size_t i = 0; i < sopv.size(); ++i) { std::string match_id = reads.getRead(sopv[i].match_idx).id; // We only want to output each edge once so skip this overlap // if the matched read has a lexicographically lower ID if(curr_read.id > match_id) continue; std::string ao = ascii_overlap(sopv[i].sequence[0], sopv[i].sequence[1], sopv[i].overlap, 50); printf("\t%s\t[%d %d] ID=%s OL=%d PI:%.2lf C=%s\n", ao.c_str(), sopv[i].overlap.match[0].start, sopv[i].overlap.match[0].end, match_id.c_str(), sopv[i].overlap.getOverlapLength(), sopv[i].overlap.getPercentIdentity(), sopv[i].overlap.cigar.c_str()); // Convert to ASQG SeqCoord sc1(sopv[i].overlap.match[0].start, sopv[i].overlap.match[0].end, sopv[i].overlap.length[0]); SeqCoord sc2(sopv[i].overlap.match[1].start, sopv[i].overlap.match[1].end, sopv[i].overlap.length[1]); // KmerOverlaps returns the coordinates of the overlap after flipping the reads // to ensure the strand matches. The ASQG file wants the coordinate of the original // sequencing strand. Flip here if necessary if(sopv[i].is_reversed) sc2.flip(); // Convert the SequenceOverlap the ASQG's overlap format Overlap ovr(curr_read.id, sc1, match_id, sc2, sopv[i].is_reversed, -1); ASQG::EdgeRecord er(ovr); er.setCigarTag(sopv[i].overlap.cigar); er.setPercentIdentityTag(sopv[i].overlap.getPercentIdentity()); #pragma omp critical { er.write(*pASQGWriter); } } } // Cleanup delete pReader; delete pBWT; delete pSSA; delete pASQGWriter; delete pTimer; if(opt::numThreads > 1) pthread_exit(NULL); return 0; }