void tst_QMailMessagePart::setHeaderField() { QString addr1("*****@*****.**"); QString addr2("*****@*****.**"); QString ownHdr("hello"); QMailMessage m; m.setHeaderField("To", addr2); QCOMPARE(m.headerFieldText("to"), addr2); QCOMPARE(m.headerField("to").content(), addr2.toLatin1()); // Ensure overwrite m.setHeaderField("To", addr1); m.setHeaderField("X-My-Own-Header", ownHdr); QCOMPARE(m.headerFieldText("to"), addr1); QCOMPARE(m.headerField("to").content(), addr1.toLatin1()); QCOMPARE(m.headerFieldText("X-My-Own-Header"), ownHdr); QCOMPARE(m.headerField("X-My-Own-Header").content(), ownHdr.toLatin1()); QCOMPARE(m.to(), (QList<QMailAddress>() << QMailAddress(addr1))); QCOMPARE(m.recipients(), (QList<QMailAddress>() << QMailAddress(addr1))); QMailMessageMetaData mtdata = *static_cast<QMailMessageMetaData*>(&m); QCOMPARE(mtdata.recipients(), (QList<QMailAddress>() << QMailAddress(addr1))); m.setHeaderField("Cc", addr2); QCOMPARE(m.recipients(), (QList<QMailAddress>() << QMailAddress(addr1) << QMailAddress(addr2))); mtdata = *static_cast<QMailMessageMetaData*>(&m); QCOMPARE(mtdata.recipients(), (QList<QMailAddress>() << QMailAddress(addr1) << QMailAddress(addr2))); QCOMPARE(m.cc(), (QList<QMailAddress>() << QMailAddress(addr2))); QString addr3("*****@*****.**"); m.setHeaderField("Bcc", addr3); QCOMPARE(m.recipients(), (QList<QMailAddress>() << QMailAddress(addr1) << QMailAddress(addr2) << QMailAddress(addr3))); mtdata = *static_cast<QMailMessageMetaData*>(&m); QCOMPARE(mtdata.recipients(), (QList<QMailAddress>() << QMailAddress(addr1) << QMailAddress(addr2) << QMailAddress(addr3))); QCOMPARE(m.bcc(), (QList<QMailAddress>() << QMailAddress(addr3))); QString rfc822 = m.toRfc2822(); QMailMessage m2 = QMailMessage::fromRfc2822(rfc822.toLatin1()); QCOMPARE(m2.headerFieldText("to"), addr1); QCOMPARE(m2.headerField("to").content(), addr1.toLatin1()); QCOMPARE(m2.headerFieldText("X-My-Own-Header"), ownHdr); QCOMPARE(m2.headerField("X-My-Own-Header").content(), ownHdr.toLatin1()); QCOMPARE(m2.to(), (QList<QMailAddress>() << QMailAddress(addr1))); m2.setTo(QList<QMailAddress>() << QMailAddress(addr2)); QCOMPARE(m2.headerFieldText("to"), addr2); QCOMPARE(m2.headerField("to").content(), addr2.toLatin1()); QCOMPARE(m2.to(), (QList<QMailAddress>() << QMailAddress(addr2))); }
int main(int argc, char **argv) { struct in_addr localhost; localhost.s_addr = htonl(0x7f000001); msrp::Ipv4Address addr1("192.168.0.12:5060"); msrp::Ipv4Address addr2("192.168.0.20",1234); msrp::Ipv4Address addr3(localhost,2); std::ostringstream buf; std::cout << addr1 << std::endl; buf << addr1; if (buf.str() != "192.168.0.12:5060") { std::cerr << "Failed at line " << __LINE__ << std::endl; exit (-1); } buf.str(""); std::cout << addr2 << std::endl; buf << addr2; if (buf.str() != "192.168.0.20:1234") { std::cerr << "Failed at line " << __LINE__ << std::endl; exit (-1); } buf.str(""); std::cout << addr3 << std::endl; buf << addr3; if (buf.str() != "127.0.0.1:2") { std::cerr << "Failed at line " << __LINE__ << std::endl; exit (-1); } buf.str(""); assert(addr1.getAddressType() == msrp::Address::IPV4); assert(addr2.getAddressType() == msrp::Address::IPV4); assert(addr3.getAddressType() == msrp::Address::IPV4); assert(addr1.getPort() == 5060); assert(addr2.getPort() == 1234); assert(addr3.getPort() == 2); return 0; }
enum TVerdict CEsockTest19_9::easyTestStepL() { TInetAddr addr, addrOut; TBuf<39> buf; // getting the IP address // set an IPv6 address const TIp6Addr KInet6Addr19_3 = {{{0xff,0xff,0,0,0,0,0,0,0,0,0,0,0x1,0x78,0,0x1}}}; addr.SetAddress(KInet6Addr19_3); // get the address - check the return value is 0 TESTL(addr.Address()==0); // set up an IPv4 compatible address TInetAddr addr2(INET_ADDR(140, 179, 229, 12), 23); addr2.ConvertToV4Compat(); // check conversion addr2.OutputWithScope(buf); TESTL(buf==_L("::140.179.229.12")); // get the address - check it is returned as an IPv4 address addrOut.SetAddress(addr2.Address()); addrOut.OutputWithScope(buf); TESTL(buf==_L("140.179.229.12")); // set up an IPv4 mapped address TInetAddr addr3(INET_ADDR(140, 179, 193, 121), 24); addr3.ConvertToV4Mapped(); // check conversion addr3.OutputWithScope(buf); TESTL(buf==_L("140.179.193.121")); // get the address - check it is returned as an IPv4 address addrOut.SetAddress(addr3.Address()); addrOut.OutputWithScope(buf); TESTL(buf==_L("140.179.193.121")); return EPass; }
void test() { namespace ip = std::experimental::net::ip; try { std::error_code ec; std::string string_value; // address constructors. ip::address addr1; const ip::address_v4 const_addr_v4; ip::address addr2(const_addr_v4); const ip::address_v6 const_addr_v6; ip::address addr3(const_addr_v6); ip::address addr4("127.0.0.1"); ip::address addr5("127.0.0.1", ec); ip::address addr6(string_value); ip::address addr7(string_value, ec); // address functions. bool b = addr1.is_v4(); (void)b; b = addr1.is_v6(); (void)b; b = addr1.is_loopback(); (void)b; b = addr1.is_unspecified(); (void)b; b = addr1.is_multicast(); (void)b; ip::address_v4 addr_v4_value = ip::address_cast<ip::address_v4>(addr1); (void)addr_v4_value; ip::address_v6 addr_v6_value = ip::address_cast<ip::address_v6>(addr1); (void)addr_v6_value; string_value = addr1.to_string(); string_value = addr1.to_string(ec); // address comparisons. b = (addr1 == addr2); (void)b; b = (addr1 != addr2); (void)b; b = (addr1 < addr2); (void)b; b = (addr1 > addr2); (void)b; b = (addr1 <= addr2); (void)b; b = (addr1 >= addr2); (void)b; // address creation functions. addr1 = ip::make_address("127.0.0.1"); addr1 = ip::make_address("127.0.0.1", ec); addr1 = ip::make_address(string_value); addr1 = ip::make_address(string_value, ec); // address I/O. std::ostringstream os; os << addr1; std::wostringstream wos; wos << addr1; } catch (std::exception&) { } }
TVerdict CresolvertpcollisionorlooplStep::doTestStepL() { SetTestStepResult(EFail); CRtpCollisionMng *collMgr = NULL; CRtpSourceEntry *entry = NULL; INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL()")); /* Normal Call */ TRAPD(res,collMgr = CRtpCollisionMng::NewL(iRtpController,iSSRC1,iCname1)); if(KErrNone != res) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() (iRtpController,iSSRC1,iCname1) Failed")); return TestStepResult(); } entry = collMgr->FindEntry(iSSRC1); /* Set the RTP and RTCP Source address */ TInetAddr addrLocal(iLocalIpAddr,iPort1); entry->SetRtpSourceAddr(addrLocal); addrLocal.SetPort(iPort1 + 1); entry->SetRtcpSourceAddr(addrLocal); //A dummy SSRC is given and a New Source is Created */ TRAP(res,entry = collMgr->CreateNewSourceL(iSSRC2)); if(res != KErrNone) { /* Failed .. Return */ INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed")); delete collMgr; return TestStepResult(); } /* Set the RTP and RTCP Source address */ TInetAddr addr(iIpAddr1,iPort1); entry->SetRtpSourceAddr(addr); addr.SetPort(iPort1+1); entry->SetRtcpSourceAddr(addr); //A dummy SSRC is given and a New Source is Created */ TRAP(res,entry = collMgr->CreateNewSourceL(iSSRC3)); if(res != KErrNone) { /* Failed .. Return */ INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed")); delete collMgr; return TestStepResult(); } /* Set the RTP and RTCP Source address */ TInetAddr addr2(iIpAddr2,iPort2); entry->SetRtpSourceAddr(addr2); addr2.SetPort(iPort2+1); entry->SetRtcpSourceAddr(addr2); /* Now check a Normal recv from BABE2 */ entry = collMgr->FindEntry(iSSRC2); if(collMgr->IsCollisionOrLoopback(entry,addr,ERtcp)) { /* This was not a Collision and was flagged as a Collision.*/ INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed-Normal Rec Flagged as Collision")); delete collMgr; return TestStepResult(); } entry = collMgr->FindEntry(iSSRC2); /* Simulating a Collision. Make a Dummy IP Address */ TInetAddr addr3(iIpAddr3,iPort1); if(!collMgr->IsCollisionOrLoopback(entry,addr3,ERtp)) { /* This was a Collision and was flagged as not a Collision.*/ INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Collision Not Detected")); delete collMgr; return TestStepResult(); } entry = collMgr->FindEntry(iSSRC2); /* Simulating a Collision. Make a Dummy IP Address */ TInetAddr addr_rtcp(iIpAddr3,iPort1+1); if(!collMgr->IsCollisionOrLoopback(entry,addr_rtcp,ERtcp)) { /* This was a Collision and was flagged as not a Collision.*/ INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Collision Not Detected")); delete collMgr; return TestStepResult(); } /* Calling Resolve Collision */ if(collMgr->ResolveRtpCollisionOrLoopL(iSSRC2,addr3,ERtp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Collision TRUE for processing :(")); delete collMgr; return TestStepResult(); } /* Calling Resolve Collision ..Our Address Given*/ if(!collMgr->ResolveRtpCollisionOrLoopL(iSSRC1,addr3,ERtp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Local Collision FALSE for processing :(")); delete collMgr; return TestStepResult(); } if(collMgr->GetLocalEntry()->SRC() == iSSRC1) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Local SSRC not Changed :(")); delete collMgr; return TestStepResult(); } TInt changedSSRC = collMgr->GetLocalEntry()->SRC(); /* Calling Resolve Collision ..Our Address Given*/ if(!collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtp|KIsAlreadySending)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Local Collision FALSE for processing :(")); delete collMgr; return TestStepResult(); } if(collMgr->GetLocalEntry()->SRC() == changedSSRC) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Local SSRC not Changed :(")); delete collMgr; return TestStepResult(); } /* Try a Loop Test .. Now */ /* Calling Resolve Collision ..Give the new SSRC and Old Addresss */ if(collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Loop Detection 1 :(")); delete collMgr; return TestStepResult(); } if(collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtp|KIsAlreadySending)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Loop Detection 2 :(")); delete collMgr; return TestStepResult(); } /* Calling again */ /* Calling Resolve Collision ..Give the new SSRC and Old Addresss */ if(collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtp|KIsAlreadySending)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Loop Detection 3 :(")); delete collMgr; return TestStepResult(); } /* Calling Resolve Collision ..Give the new SSRC and Old Addresss */ if(collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Loop Detection 4 :(")); delete collMgr; return TestStepResult(); } if(collMgr->ResolveRtpCollisionOrLoopL(collMgr->GetLocalEntry()->SRC(),addr3,ERtcp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Loop Detection 5 :(")); delete collMgr; return TestStepResult(); } /* We have received only one RTP from the colliding Source. What if we receive an RTCP from a Different source With the same SSRC ? */ /*This condition tickles an old issue. So lets keep it that way */ #if 0 TInetAddr addr4(iIpAddr4,iPort4); entry = collMgr->FindEntry(iSSRC1); if(!collMgr->IsCollisionOrLoopback(entry,addr4,ERtcp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Incorrect Collision Detection")); delete collMgr; return TestStepResult(); } /* Now receiving an RTCP from the same Source.. See it that is not flagged as a Collision */ addr3.SetPort(iPort1+1); entry = collMgr->FindEntry(iSSRC1); if(collMgr->IsCollisionOrLoopback(entry,addr3,ERtcp)) { INFO_PRINTF1(_L("CresolvertpcollisionorlooplStep::doStepL() - Failed - Incorrect Collision Dectection")); delete collMgr; return TestStepResult(); } #endif SetTestStepResult(EPass); delete collMgr; return TestStepResult(); }