void TestHistogram::test_serialize() { (*testhisto_int).save_serialize("serialize_test.dat"); Histogram<int, int, BinningNumber<int> > testhisto_load; testhisto_load.load_serialize("serialize_test.dat"); CPPUNIT_ASSERT_EQUAL((*testhisto_int)[1], testhisto_load[1]); CPPUNIT_ASSERT_EQUAL((*testhisto_int)[2], testhisto_load[2]); CPPUNIT_ASSERT_EQUAL((*testhisto_int)[3], testhisto_load[3]); CPPUNIT_ASSERT_EQUAL((*testhisto_int)[4], testhisto_load[4]); CPPUNIT_ASSERT_EQUAL((*testhisto_int)[5], testhisto_load[5]); CPPUNIT_ASSERT_EQUAL((*testhisto_int).get_binning().get_binning_width(), testhisto_load.get_binning().get_binning_width()); CPPUNIT_ASSERT_EQUAL((*testhisto_int).get_binning().get_binning_reference(), testhisto_load.get_binning().get_binning_reference()); (*testhisto_double).save_serialize("serialize_test.dat"); Histogram<double, double, BinningNumber<double> > testhisto_load_double; testhisto_load_double.load_serialize("serialize_test.dat"); CPPUNIT_ASSERT_EQUAL((*testhisto_double)[1.0], testhisto_load_double[1.0]); CPPUNIT_ASSERT_EQUAL((*testhisto_double)[2.0], testhisto_load_double[2.0]); CPPUNIT_ASSERT_EQUAL((*testhisto_double)[3.0], testhisto_load_double[3.0]); CPPUNIT_ASSERT_EQUAL((*testhisto_double)[4.0], testhisto_load_double[4.0]); CPPUNIT_ASSERT_EQUAL((*testhisto_double)[5.0], testhisto_load_double[5.0]); CPPUNIT_ASSERT_EQUAL((*testhisto_double).get_binning().get_binning_width(), testhisto_load_double.get_binning().get_binning_width()); CPPUNIT_ASSERT_EQUAL((*testhisto_double).get_binning().get_binning_reference(), testhisto_load_double.get_binning().get_binning_reference()); }
void ComponentTest::thre_slots_and_two_signals_result_in_3_max_port_count() { Component *comp = ComponentFactory::produce("", {"", "", ""}, {"", ""}); CPPUNIT_ASSERT_EQUAL(size_t(3), comp->maxPortCount()); ComponentFactory::dispose(comp); }
void SpinCtrlDoubleTestCase::Digits() { m_spin->SetDigits(5); CPPUNIT_ASSERT_EQUAL(5, m_spin->GetDigits()); }
void DEFAULTPACKETSTREAMERTF::testProcessData() { DefaultPacketFactory *factory = new DefaultPacketFactory(); DefaultPacketStreamer *streamer = new DefaultPacketStreamer(factory); DataBuffer *buffer = new DataBuffer; StreamingContext *context = streamer->createContext(); CPPUNIT_ASSERT(context); DefaultPacket *packet = new DefaultPacket; DefaultPacket *result = NULL; size_t bodyLength; CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); packet->setBody("",0); CPPUNIT_ASSERT(streamer->encode(packet, buffer)); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(context->isCompleted()); result = dynamic_cast<DefaultPacket*>(context->getPacket()); CPPUNIT_ASSERT(result); CPPUNIT_ASSERT(!result->getBody(bodyLength)); CPPUNIT_ASSERT_EQUAL((size_t)0, bodyLength); context->reset(); packet->setBody("a",1); CPPUNIT_ASSERT(streamer->encode(packet, buffer)); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(context->isCompleted()); result = dynamic_cast<DefaultPacket*>(context->getPacket()); CPPUNIT_ASSERT(result); CPPUNIT_ASSERT(result->getBody(bodyLength)); CPPUNIT_ASSERT_EQUAL('a', *(result->getBody(bodyLength))); CPPUNIT_ASSERT_EQUAL((size_t)1, bodyLength); context->reset(); packet->setBody("ab",2); CPPUNIT_ASSERT(streamer->encode(packet, buffer)); packet->setBody("a",1); CPPUNIT_ASSERT(streamer->encode(packet, buffer)); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(context->isCompleted()); result = dynamic_cast<DefaultPacket*>(context->getPacket()); CPPUNIT_ASSERT(result); CPPUNIT_ASSERT(result->getBody(bodyLength)); CPPUNIT_ASSERT_EQUAL('a', *(result->getBody(bodyLength))); CPPUNIT_ASSERT_EQUAL('b', *(result->getBody(bodyLength) + 1)); CPPUNIT_ASSERT_EQUAL((size_t)2, bodyLength); context->reset(); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(context->isCompleted()); result = dynamic_cast<DefaultPacket*>(context->getPacket()); CPPUNIT_ASSERT(result); CPPUNIT_ASSERT(result->getBody(bodyLength)); CPPUNIT_ASSERT_EQUAL('a', *(result->getBody(bodyLength))); CPPUNIT_ASSERT_EQUAL((size_t)1, bodyLength); context->reset(); delete streamer; delete factory; delete buffer; delete packet; delete context; }
/*============================================================================== * FUNCTION: DfaTest::testMeetInt * OVERVIEW: Test meeting IntegerTypes with various other types *============================================================================*/ void DfaTest::testMeetInt () { IntegerType i32(32, 1); IntegerType j32(32, 0); IntegerType u32(32, -1); IntegerType xint(0); IntegerType j16(16, 0); SizeType s32(32); SizeType s64(64); FloatType flt(32); PointerType pt(&flt); VoidType v; bool ch = false; i32.meetWith(&i32, ch, false); CPPUNIT_ASSERT(ch == false); std::ostringstream ost1; ost1<< &i32; std::string actual(ost1.str()); std::string expected("i32"); CPPUNIT_ASSERT_EQUAL(expected, actual); i32.meetWith(&j32, ch, false); CPPUNIT_ASSERT(ch == false); j32.meetWith(&i32, ch, false); CPPUNIT_ASSERT(ch == true); std::ostringstream ost2; ost2<< &i32; actual = ost2.str(); expected = "i32"; CPPUNIT_ASSERT_EQUAL(expected, actual); ch = false; j32.setSigned(0); j32.meetWith(&v, ch, false); CPPUNIT_ASSERT(ch == false); std::ostringstream ost2a; ost2a<< &j32; actual = ost2a.str(); expected = "j32"; CPPUNIT_ASSERT_EQUAL(expected, actual); ch = false; j32.meetWith(&u32, ch, false); CPPUNIT_ASSERT(ch == true); std::ostringstream ost3; ost3<< &j32; actual = ost3.str(); expected = "u32"; CPPUNIT_ASSERT_EQUAL(expected, actual); ch = false; u32.meetWith(&s32, ch, false); CPPUNIT_ASSERT(ch == false); std::ostringstream ost4; ost4<< &u32; actual = ost4.str(); expected = "u32"; CPPUNIT_ASSERT_EQUAL(expected, actual); u32.meetWith(&s64, ch, false); CPPUNIT_ASSERT(ch == true); std::ostringstream ost5; ost5<< &u32; actual = ost5.str(); expected = "u64"; CPPUNIT_ASSERT_EQUAL(expected, actual); ch = false; Type* res = i32.meetWith(&flt, ch, false); CPPUNIT_ASSERT(ch == true); std::ostringstream ost6; ost6<< res; actual = ost6.str(); expected = "union"; CPPUNIT_ASSERT_EQUAL(expected, actual); ch = false; res = i32.meetWith(&pt, ch, false); CPPUNIT_ASSERT(ch == true); std::ostringstream ost7; ost7<< res; actual = ost7.str(); expected = "union"; CPPUNIT_ASSERT_EQUAL(expected, actual); }
void ConfigTest::testSetCommentMark(void) { Config config; config.setCommentMark('\\'); CPPUNIT_ASSERT_EQUAL('\\', config.getCommentMark()); }
/*============================================================================== * FUNCTION: LoaderTest::testWinLoad * OVERVIEW: Test loading Windows programs *============================================================================*/ void LoaderTest::testWinLoad () { std::ostringstream ost; #if 0 /* FIXME: these tests should use non-proprietary programs */ // Load Windows program calc.exe BinaryFileFactory bff; BinaryFile* pBF = bff.Load(CALC_WINDOWS); CPPUNIT_ASSERT(pBF != NULL); int n; SectionInfo* si; n = pBF->GetNumSections(); ost << "Number of sections = " << std::dec << n << "\r\n"; for (int i=0; i < n; i++) { si = pBF->GetSectionInfo(i); ost << si->pSectionName << "\t"; } // Note: the string below needs to have embedded tabs. Edit with caution! std::string expected("Number of sections = 5\r\n" ".text .rdata .data .rsrc .reloc "); std::string actual(ost.str()); CPPUNIT_ASSERT_EQUAL(expected, actual); ADDRESS addr = pBF->GetMainEntryPoint(); CPPUNIT_ASSERT(addr != NO_ADDRESS); // Test symbol table (imports) const char* s = pBF->SymbolByAddress(0x1292060U); if (s == 0) actual = "<not found>"; else actual = std::string(s); expected = std::string("SetEvent"); CPPUNIT_ASSERT_EQUAL(expected, actual); ADDRESS a = pBF->GetAddressByName("SetEvent"); ADDRESS expectedAddr = 0x1292060; CPPUNIT_ASSERT_EQUAL(expectedAddr, a); pBF->UnLoad(); bff.UnLoad(); // Test loading the "new style" exes, as found in winXP etc pBF = bff.Load(CALC_WINXP); CPPUNIT_ASSERT(pBF != NULL); addr = pBF->GetMainEntryPoint(); std::ostringstream ost1; ost1 << std::hex << addr; actual = ost1.str(); expected = "1001f51"; CPPUNIT_ASSERT_EQUAL(expected, actual); pBF->UnLoad(); bff.UnLoad(); // Test loading the calc.exe found in Windows 2000 (more NT based) pBF = bff.Load(CALC_WIN2000); CPPUNIT_ASSERT(pBF != NULL); expected = "1001680"; addr = pBF->GetMainEntryPoint(); std::ostringstream ost2; ost2 << std::hex << addr; actual = ost2.str(); CPPUNIT_ASSERT_EQUAL(expected, actual); pBF->UnLoad(); bff.UnLoad(); // Test loading the lpq.exe program - console mode PE file pBF = bff.Load(LPQ_WINDOWS); CPPUNIT_ASSERT(pBF != NULL); addr = pBF->GetMainEntryPoint(); std::ostringstream ost3; ost3 << std::hex << addr; actual = ost3.str(); expected = "18c1000"; CPPUNIT_ASSERT_EQUAL(expected, actual); pBF->UnLoad(); bff.UnLoad(); #endif // Borland BinaryFileFactory bff; BinaryFile* pBF = bff.Load(SWITCH_BORLAND); CPPUNIT_ASSERT(pBF != NULL); ADDRESS addr = pBF->GetMainEntryPoint(); std::ostringstream ost4; ost4 << std::hex << addr; std::string actual(ost4.str()); std::string expected("401150"); CPPUNIT_ASSERT_EQUAL(expected, actual); pBF->UnLoad(); bff.UnLoad(); }
void TestPluginManager::setCurrentPluginNeg() { Plugin *before = testPluginManager->getCurrentPlugin(); testPluginManager->setCurrentPlugin(-1); CPPUNIT_ASSERT_EQUAL(before,testPluginManager->getCurrentPlugin()); }
void TestPluginManager::setCurrentPluginSup() { Plugin *before = testPluginManager->getCurrentPlugin(); int size = testPluginManager->getPlugins()->size(); testPluginManager->setCurrentPlugin(size); CPPUNIT_ASSERT_EQUAL(before,testPluginManager->getCurrentPlugin()); }
void FontMapperTestCase::NamesAndDesc() { static const wxChar *charsets[] = { // some valid charsets _T("us-ascii" ), _T("iso8859-1" ), _T("iso-8859-12" ), _T("koi8-r" ), _T("utf-7" ), _T("cp1250" ), _T("windows-1252"), // and now some bogus ones _T("" ), _T("cp1249" ), _T("iso--8859-1" ), _T("iso-8859-19" ), }; static const wxChar *names[] = { // some valid charsets _T("default" ), _T("iso-8859-1" ), _T("iso-8859-12" ), _T("koi8-r" ), _T("utf-7" ), _T("windows-1250"), _T("windows-1252"), // and now some bogus ones _T("default" ), _T("unknown--1" ), _T("unknown--1" ), _T("unknown--1" ), }; static const wxChar *descriptions[] = { // some valid charsets _T("Default encoding" ), _T("Western European (ISO-8859-1)" ), _T("Indian (ISO-8859-12)" ), _T("KOI8-R" ), _T("Unicode 7 bit (UTF-7)" ), _T("Windows Central European (CP 1250)"), _T("Windows Western European (CP 1252)"), // and now some bogus ones _T("Default encoding" ), _T("Unknown encoding (-1)" ), _T("Unknown encoding (-1)" ), _T("Unknown encoding (-1)" ), }; wxFontMapperBase& fmap = *wxFontMapperBase::Get(); for ( size_t n = 0; n < WXSIZEOF(charsets); n++ ) { wxFontEncoding enc = fmap.CharsetToEncoding(charsets[n]); CPPUNIT_ASSERT_EQUAL( names[n], fmap.GetEncodingName(enc).Lower() ); CPPUNIT_ASSERT_EQUAL( descriptions[n], fmap.GetEncodingDescription(enc) ); } }
void TestPluginManager::setCurrentPluginSame() { Plugin *before = testPluginManager->getCurrentPlugin(); int index = testPluginManager->getPlugins()->indexOf(before); testPluginManager->setCurrentPlugin(index); CPPUNIT_ASSERT_EQUAL(before,testPluginManager->getCurrentPlugin()); }
void VectorsTestCase::Resize() { wxVector<CountedObject> v; v.resize(3); CPPUNIT_ASSERT_EQUAL( 3, v.size() ); CPPUNIT_ASSERT_EQUAL( 3, CountedObject::GetCount() ); CPPUNIT_ASSERT_EQUAL( 0, v[0].GetValue() ); CPPUNIT_ASSERT_EQUAL( 0, v[1].GetValue() ); CPPUNIT_ASSERT_EQUAL( 0, v[2].GetValue() ); v.resize(1); CPPUNIT_ASSERT_EQUAL( 1, v.size() ); CPPUNIT_ASSERT_EQUAL( 1, CountedObject::GetCount() ); v.resize(4, CountedObject(17)); CPPUNIT_ASSERT_EQUAL( 4, v.size() ); CPPUNIT_ASSERT_EQUAL( 4, CountedObject::GetCount() ); CPPUNIT_ASSERT_EQUAL( 0, v[0].GetValue() ); CPPUNIT_ASSERT_EQUAL( 17, v[1].GetValue() ); CPPUNIT_ASSERT_EQUAL( 17, v[2].GetValue() ); CPPUNIT_ASSERT_EQUAL( 17, v[3].GetValue() ); }
void TestHistogram::test_operator_access() { // Test the get-operation CPPUNIT_ASSERT_EQUAL(4, (*testhisto_int)[0]); CPPUNIT_ASSERT_EQUAL(4, (*testhisto_int)[1]); CPPUNIT_ASSERT_EQUAL(4, (*testhisto_int)[2]); CPPUNIT_ASSERT_EQUAL(5, (*testhisto_int)[3]); CPPUNIT_ASSERT_EQUAL(1, (*testhisto_int)[7]); CPPUNIT_ASSERT_EQUAL(1, (*testhisto_int)[8]); CPPUNIT_ASSERT_EQUAL(5, (*testhisto_int)[9]); CPPUNIT_ASSERT_EQUAL(0.8, (*testhisto_double)[0.0]); CPPUNIT_ASSERT_EQUAL(0.8, (*testhisto_double)[1.0]); CPPUNIT_ASSERT_EQUAL(0.8, (*testhisto_double)[1.4]); CPPUNIT_ASSERT_EQUAL(0.8, (*testhisto_double)[2.1]); CPPUNIT_ASSERT_EQUAL(1.0, (*testhisto_double)[2.5]); CPPUNIT_ASSERT_EQUAL(4.8, (*testhisto_double)[5.4]); CPPUNIT_ASSERT_EQUAL(2.1, (*testhisto_double)[7.9]); // Test the set-operation (*testhisto_int)[1] = 4; (*testhisto_int)[2] = 1; (*testhisto_int)[10] = 5; (*testhisto_int)[13] = 3; CPPUNIT_ASSERT_EQUAL(1, (*testhisto_int)[0]); CPPUNIT_ASSERT_EQUAL(5, (*testhisto_int)[9]); CPPUNIT_ASSERT_EQUAL(3, (*testhisto_int)[12]); (*testhisto_double)[1.0] = 4.0; (*testhisto_double)[2.0] = 1.0; (*testhisto_double)[10.0] = 5.0; CPPUNIT_ASSERT_EQUAL(1.0, (*testhisto_double)[1.5]); CPPUNIT_ASSERT_EQUAL(5.0, (*testhisto_double)[10.0]); }
void TestHistogram::test_operator_fill() { // Test the increment by one at a given bin (*testhisto_int) << 1; (*testhisto_int) << 1; (*testhisto_int) << 2; (*testhisto_int) << 5; (*testhisto_int) << 6; CPPUNIT_ASSERT_EQUAL(7, (*testhisto_int)[0]); CPPUNIT_ASSERT_EQUAL(6, (*testhisto_int)[3]); CPPUNIT_ASSERT_EQUAL(2, (*testhisto_int)[6]); CPPUNIT_ASSERT_EQUAL(5, (*testhisto_int)[9]); (*testhisto_double) << 1.0; (*testhisto_double) << 1.0; (*testhisto_double) << 2.0; (*testhisto_double) << 5.0; (*testhisto_double) << 6.0; CPPUNIT_ASSERT_EQUAL(3.8, (*testhisto_double)[0.0]); CPPUNIT_ASSERT_EQUAL(1.0, (*testhisto_double)[2.5]); CPPUNIT_ASSERT_EQUAL(6.8, (*testhisto_double)[5.0]); CPPUNIT_ASSERT_EQUAL(2.1, (*testhisto_double)[7.5]); // Test the increment by a std::pair (*testhisto_int) << std::pair<int, int>(3,5); (*testhisto_int) << std::pair<int, int>(5,2); (*testhisto_int) << std::pair<int, int>(7,5); CPPUNIT_ASSERT_EQUAL(7, (*testhisto_int)[0]); CPPUNIT_ASSERT_EQUAL(13, (*testhisto_int)[3]); CPPUNIT_ASSERT_EQUAL(7, (*testhisto_int)[6]); CPPUNIT_ASSERT_EQUAL(5, (*testhisto_int)[9]); (*testhisto_double) << std::pair<double, double>(3.0,5.0); (*testhisto_double) << std::pair<double, double>(5.0,2.0); (*testhisto_double) << std::pair<double, double>(7.0,5.0); CPPUNIT_ASSERT_EQUAL(3.8, (*testhisto_double)[0.0]); CPPUNIT_ASSERT_EQUAL(6.0, (*testhisto_double)[2.5]); CPPUNIT_ASSERT_EQUAL(13.8, (*testhisto_double)[5.0]); CPPUNIT_ASSERT_EQUAL(2.1, (*testhisto_double)[7.5]); }
void ConfigTest::testSetCommentEnabled(void) { Config config; config.setCommentEnabled(true); CPPUNIT_ASSERT_EQUAL(true, config.getCommentEnabled()); }
void ConfigTest::testGetDelimitMark(void) { Config config; CPPUNIT_ASSERT_EQUAL(DEFAULT_DELIMIT_MARK, config.getDelimitMark()); }
void ConfigTest::testGetCommentMark(void) { Config config; CPPUNIT_ASSERT_EQUAL(DEFAULT_COMMENT_MARK, config.getCommentMark()); }
void ConfigTest::testSetDelimitMark(void) { Config config; config.setDelimitMark('\t'); CPPUNIT_ASSERT_EQUAL('\t', config.getDelimitMark()); }
void CMCUCommonTest::TestParsePath() { LPCTSTR strPath = _T( "\\12345/abcd\\thinkingl.keda.com" ); TFileNameInfo tInfo = ParsePath( strPath ); TFileNameInfo tInfo2; CPPUNIT_ASSERT( ParsePath( strPath, tInfo2 ) ); // 两种方式的结果必须一样. CPPUNIT_ASSERT_EQUAL( tInfo, tInfo2 ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strBaseName, tstring(_T( "thinkingl.keda" )) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strDirectory, tstring( _T( "\\12345\\abcd\\" ) ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strExtName, tstring( _T( "com" ) ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strFileName, tstring( _T( "thinkingl.keda.com" ) ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strFilePath, tstring( strPath ) ); LPCTSTR strPath2 = _T( "abc" ); CPPUNIT_ASSERT( ParsePath( strPath2, tInfo ) ); tInfo2 = ParsePath( strPath2 ); CPPUNIT_ASSERT_EQUAL( tInfo2, tInfo ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strBaseName, tstring( strPath2 ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strDirectory, tstring( _T( "" ) ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strExtName, tstring( _T( "" ) ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strFileName, tstring( strPath2 ) ); CPPUNIT_ASSERT_EQUAL( tInfo.m_strFilePath, tstring( strPath2 ) ); }
void ConfigTest::testGetQuoteEnabled(void) { Config config; CPPUNIT_ASSERT_EQUAL(DEFAULT_QUOTE_ENABLED, config.getQuoteEnabled()); }
void osaTripleBufferTest::TestLogic(void) { int value1 = 0; int value2 = 0; int value3 = 0; int * slot1 = &value1; int * slot2 = &value2; int * slot3 = &value3; osaTripleBuffer<int> tripleBuffer(slot1, slot2, slot3); // test initial configuration CPPUNIT_ASSERT_EQUAL(tripleBuffer.LastWriteNode->Pointer, slot1); CPPUNIT_ASSERT_EQUAL(tripleBuffer.LastWriteNode->Next->Pointer, slot2); CPPUNIT_ASSERT_EQUAL(tripleBuffer.LastWriteNode->Next->Next->Pointer, slot3); // write while nobody's reading tripleBuffer.BeginWrite(); { *(tripleBuffer.GetWritePointer()) = 1; } tripleBuffer.EndWrite(); // read to make sure, no ongoing write tripleBuffer.BeginRead(); { CPPUNIT_ASSERT_EQUAL(1, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); // very long write, read a couple of times in between to make sure value doesn't change tripleBuffer.BeginWrite(); { // read before change tripleBuffer.BeginRead(); { CPPUNIT_ASSERT_EQUAL(1, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); // change *(tripleBuffer.GetWritePointer()) = 2; // read after change but before release tripleBuffer.BeginRead(); { CPPUNIT_ASSERT_EQUAL(1, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); } tripleBuffer.EndWrite(); // read after release tripleBuffer.BeginRead(); { CPPUNIT_ASSERT_EQUAL(2, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); // very long read tripleBuffer.BeginRead(); { // read before change CPPUNIT_ASSERT_EQUAL(2, *(tripleBuffer.GetReadPointer())); // lock to write tripleBuffer.BeginWrite(); { *(tripleBuffer.GetWritePointer()) = 3; } tripleBuffer.EndWrite(); // read again CPPUNIT_ASSERT_EQUAL(2, *(tripleBuffer.GetReadPointer())); // lock to write again tripleBuffer.BeginWrite(); { *(tripleBuffer.GetWritePointer()) = 4; } tripleBuffer.EndWrite(); // read onceagain CPPUNIT_ASSERT_EQUAL(2, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); // final read tripleBuffer.BeginRead(); { CPPUNIT_ASSERT_EQUAL(4, *(tripleBuffer.GetReadPointer())); } tripleBuffer.EndRead(); }
void ConfigTest::testSetQuoteEnabled(void) { Config config; config.setQuoteEnabled(false); CPPUNIT_ASSERT_EQUAL(false, config.getQuoteEnabled()); }
void DEFAULTPACKETSTREAMERTF::testProcessDataMultiStep() { DefaultPacketFactory *factory = new DefaultPacketFactory(); DefaultPacketStreamer *streamer = new DefaultPacketStreamer(factory); DataBuffer *buffer = new DataBuffer; StreamingContext *context = streamer->createContext(); CPPUNIT_ASSERT(context); DefaultPacket *packet = new DefaultPacket; DefaultPacket *result = NULL; size_t bodyLength; /*need to multi step here*/ buffer->writeInt32(ANET_PACKET_FLAG); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeInt32(0xabcd); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeInt32(1); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeInt32(10); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeBytes("1", 1); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeBytes("2", 1); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(!context->isCompleted()); buffer->writeBytes("34567890", 8); CPPUNIT_ASSERT(streamer->processData(buffer, context)); CPPUNIT_ASSERT(!context->isBroken()); CPPUNIT_ASSERT(context->isCompleted()); result = dynamic_cast<DefaultPacket*>(context->getPacket()); CPPUNIT_ASSERT(result); CPPUNIT_ASSERT(result->getBody(bodyLength)); CPPUNIT_ASSERT_EQUAL((size_t)10, bodyLength); CPPUNIT_ASSERT_EQUAL(0xabcdu, result->getChannelId()); CPPUNIT_ASSERT_EQUAL(1, result->getPacketHeader()->_pcode); context->reset(); delete streamer; delete factory; delete buffer; delete packet; delete context; }
void ConfigTest::testGetQuoteMark(void) { Config config; CPPUNIT_ASSERT_EQUAL(DEFAULT_QUOTE_MARK, config.getQuoteMark()); }
void WrapperFactoryTest::testUnknown() { struct IntFactory { static int * timesOne(int * factor) { int * result = new int; *result = *factor * 1; return result; } static int * timesTwo(int * factor) { int * result = new int; *result = *factor * 2; return result; } static int * timesThree(int * factor) { int * result = new int; *result = *factor * 3; return result; } }; typedef std::function<int * (int *)> IntCreator; { Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::ExceptionFallback> factory; factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; int * productA = factory.create(3, &one); int * productB = factory.create(2, &two); int * productC = factory.create(1, &three); CPPUNIT_ASSERT(productA != nullptr); CPPUNIT_ASSERT(productB != nullptr); CPPUNIT_ASSERT(productC != nullptr); CPPUNIT_ASSERT_EQUAL(3, *productA); CPPUNIT_ASSERT_EQUAL(4, *productB); CPPUNIT_ASSERT_EQUAL(3, *productC); delete productC; delete productB; delete productA; typedef Util::FallbackPolicies::ExceptionFallback<int *, int>::Exception FactoryException; CPPUNIT_ASSERT_THROW(factory.create(0, &one), FactoryException); CPPUNIT_ASSERT_THROW(factory.create(4, &two), FactoryException); CPPUNIT_ASSERT_THROW(factory.create(17, &three), FactoryException); } { Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::NULLFallback> factory; factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(0, &one)); CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(4, &two)); CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(17, &three)); CPPUNIT_ASSERT_NO_THROW(factory.create(0, &one)); CPPUNIT_ASSERT_NO_THROW(factory.create(4, &two)); CPPUNIT_ASSERT_NO_THROW(factory.create(17, &three)); } { std::ostringstream outputStream; Util::FallbackPolicies::DefaultCreatorFallback<int *, int> fallback(2, outputStream); Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::DefaultCreatorFallback> factory(fallback); factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; int * productA = factory.create(0, &one); int * productB = factory.create(4, &two); int * productC = factory.create(17, &three); CPPUNIT_ASSERT(outputStream.good()); CPPUNIT_ASSERT(!outputStream.str().empty()); CPPUNIT_ASSERT(productA != nullptr); CPPUNIT_ASSERT(productB != nullptr); CPPUNIT_ASSERT(productC != nullptr); CPPUNIT_ASSERT_EQUAL(2, *productA); CPPUNIT_ASSERT_EQUAL(4, *productB); CPPUNIT_ASSERT_EQUAL(6, *productC); delete productC; delete productB; delete productA; } }
void ConfigTest::testSetQuoteMark(void) { Config config; config.setQuoteMark('\''); CPPUNIT_ASSERT_EQUAL('\'', config.getQuoteMark()); }
static bool checkGenericArraysEqual(const GenericArray & expected, const GenericArray & actual) { CPPUNIT_ASSERT_EQUAL(expected.size(), actual.size()); return std::equal(expected.cbegin(), expected.cend(), actual.cbegin(), &checkGenericsEqual); }
void ConfigTest::testGetCommentEnabled(void) { Config config; CPPUNIT_ASSERT_EQUAL(DEFAULT_COMMENT_ENABLED, config.getCommentEnabled()); }
void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style) { delete m_text; CreateText(style); // Asking for invalid index should fail. WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(1) ); // Getting position shouldn't return wxDefaultPosition except if the method // is not implemented at all in the current port. const wxPoint pos0 = m_text->PositionToCoords(0); if ( pos0 == wxDefaultPosition ) { #if defined(__WXMSW__) || defined(__WXGTK20__) CPPUNIT_FAIL( "PositionToCoords() unexpectedly failed." ); #endif return; } CPPUNIT_ASSERT(pos0.x >= 0); CPPUNIT_ASSERT(pos0.y >= 0); m_text->SetValue("Hello"); wxYield(); // Let GTK layout the control correctly. // Position of non-first character should be positive. const long posHello4 = m_text->PositionToCoords(4).x; CPPUNIT_ASSERT( posHello4 > 0 ); // Asking for position beyond the last character should succeed and return // reasonable result. CPPUNIT_ASSERT( m_text->PositionToCoords(5).x > posHello4 ); // But asking for the next position should fail. WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(6) ); // Test getting the coordinates of the last character when it is in the // beginning of a new line to exercise MSW code which has specific logic // for it. m_text->AppendText("\n"); const wxPoint posLast = m_text->PositionToCoords(m_text->GetLastPosition()); CPPUNIT_ASSERT_EQUAL( pos0.x, posLast.x ); CPPUNIT_ASSERT( posLast.y > 0 ); // Add enough contents to the control to make sure it has a scrollbar. m_text->SetValue("First line" + wxString(50, '\n') + "Last line"); m_text->SetInsertionPoint(0); wxYield(); // Let GTK layout the control correctly. // This shouldn't change anything for the first position coordinates. CPPUNIT_ASSERT_EQUAL( pos0, m_text->PositionToCoords(0) ); // And the last one must be beyond the window boundary and so not be // visible -- but getting its coordinate should still work. CPPUNIT_ASSERT ( m_text->PositionToCoords(m_text->GetLastPosition()).y > TEXT_HEIGHT ); // Now make it scroll to the end and check that the first position now has // negative offset as its above the visible part of the window while the // last position is in its bounds. m_text->SetInsertionPointEnd(); CPPUNIT_ASSERT( m_text->PositionToCoords(0).y < 0 ); CPPUNIT_ASSERT ( m_text->PositionToCoords(m_text->GetInsertionPoint()).y <= TEXT_HEIGHT ); }
void TestHistogram::test_initialise_empty() { Histogram<double, double, BinningNumber<double> > initialised_testhisto_double; initialised_testhisto_double.initialise_empty(*testhisto_double); CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(initialised_testhisto_double.size())); CPPUNIT_ASSERT(initialised_testhisto_double.find(0.0) != initialised_testhisto_double.end()); CPPUNIT_ASSERT(initialised_testhisto_double.find(2.5) != initialised_testhisto_double.end()); CPPUNIT_ASSERT(initialised_testhisto_double.find(5.0) != initialised_testhisto_double.end()); CPPUNIT_ASSERT(initialised_testhisto_double.find(7.5) != initialised_testhisto_double.end()); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double.find(0.0)->second); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double.find(2.5)->second); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double.find(5.0)->second); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double.find(7.5)->second); CPPUNIT_ASSERT_EQUAL(2.5, initialised_testhisto_double.get_binning_width()); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double.get_binning_reference()); Histogram<double, int, BinningNumber<double> > initialised_testhisto_double_int; initialised_testhisto_double_int.initialise_empty(*testhisto_double); CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(initialised_testhisto_double_int.size())); CPPUNIT_ASSERT(initialised_testhisto_double_int.find(0.0) != initialised_testhisto_double_int.end()); CPPUNIT_ASSERT(initialised_testhisto_double_int.find(2.5) != initialised_testhisto_double_int.end()); CPPUNIT_ASSERT(initialised_testhisto_double_int.find(5.0) != initialised_testhisto_double_int.end()); CPPUNIT_ASSERT(initialised_testhisto_double_int.find(7.5) != initialised_testhisto_double_int.end()); CPPUNIT_ASSERT_EQUAL(0, initialised_testhisto_double_int.find(0.0)->second); CPPUNIT_ASSERT_EQUAL(0, initialised_testhisto_double_int.find(2.5)->second); CPPUNIT_ASSERT_EQUAL(0, initialised_testhisto_double_int.find(5.0)->second); CPPUNIT_ASSERT_EQUAL(0, initialised_testhisto_double_int.find(7.5)->second); CPPUNIT_ASSERT_EQUAL(2.5, initialised_testhisto_double_int.get_binning_width()); CPPUNIT_ASSERT_EQUAL(0.0, initialised_testhisto_double_int.get_binning_reference()); }