From 686131de48ded1e131e07fc524fa5b577948b91d Mon Sep 17 00:00:00 2001 From: Tristan Matthews <le.businessman@gmail.com> Date: Mon, 5 Mar 2012 21:52:34 -0500 Subject: [PATCH] tests: cleanup --- daemon/test/instantmessagingtest.cpp | 2 +- daemon/test/sdesnegotiatortest.cpp | 188 ++++++++++----------------- daemon/test/sdesnegotiatortest.h | 10 -- 3 files changed, 71 insertions(+), 129 deletions(-) diff --git a/daemon/test/instantmessagingtest.cpp b/daemon/test/instantmessagingtest.cpp index d88185d01e..2c256e0189 100644 --- a/daemon/test/instantmessagingtest.cpp +++ b/daemon/test/instantmessagingtest.cpp @@ -231,7 +231,7 @@ void InstantMessagingTest::testGetTextArea() formatedText.append("</resource-lists>"); formatedText.append("--boundary--"); - std::string message = findTextMessage(formatedText); + std::string message(findTextMessage(formatedText)); std::cout << "message " << message << std::endl; diff --git a/daemon/test/sdesnegotiatortest.cpp b/daemon/test/sdesnegotiatortest.cpp index 2330412ff1..8bca64625c 100644 --- a/daemon/test/sdesnegotiatortest.cpp +++ b/daemon/test/sdesnegotiatortest.cpp @@ -50,24 +50,17 @@ using std::cout; using std::endl; -SdesNegotiatorTest::SdesNegotiatorTest() : pattern(0), sdesnego(0), - remoteOffer(0), localCapabilities(0) -{} - void SdesNegotiatorTest::testTagPattern() { DEBUG("-------------------- SdesNegotiatorTest::testTagPattern --------------------\n"); std::string subject = "a=crypto:4"; - pattern = new sfl::Pattern("^a=crypto:(?P<tag>[0-9]{1,9})"); - *pattern << subject; - - CPPUNIT_ASSERT(pattern->matches()); - CPPUNIT_ASSERT(pattern->group("tag").compare("4") == 0); + sfl::Pattern pattern("^a=crypto:(?P<tag>[0-9]{1,9})"); + pattern << subject; - delete pattern; - pattern = NULL; + CPPUNIT_ASSERT(pattern.matches()); + CPPUNIT_ASSERT(pattern.group("tag").compare("4") == 0); } @@ -77,17 +70,14 @@ void SdesNegotiatorTest::testCryptoSuitePattern() std::string subject = "AES_CM_128_HMAC_SHA1_80"; - pattern = new sfl::Pattern("(?P<cryptoSuite>AES_CM_128_HMAC_SHA1_80|" \ + sfl::Pattern pattern("(?P<cryptoSuite>AES_CM_128_HMAC_SHA1_80|" \ "AES_CM_128_HMAC_SHA1_32|" \ "F8_128_HMAC_SHA1_80|" \ "[A-Za-z0-9_]+)"); - *pattern << subject; - - CPPUNIT_ASSERT(pattern->matches()); - CPPUNIT_ASSERT(pattern->group("cryptoSuite").compare("AES_CM_128_HMAC_SHA1_80") == 0); + pattern << subject; - delete pattern; - pattern = NULL; + CPPUNIT_ASSERT(pattern.matches()); + CPPUNIT_ASSERT(pattern.group("cryptoSuite").compare("AES_CM_128_HMAC_SHA1_80") == 0); } @@ -97,24 +87,21 @@ void SdesNegotiatorTest::testKeyParamsPattern() std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32"; - pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ + sfl::Pattern pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \ "(2\\^(?P<lifetime>[0-9]+)\\|" \ "(?P<mkiValue>[0-9]+)\\:" \ "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); - *pattern << subject; + pattern << subject; - pattern->matches(); - CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); - CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") + pattern.matches(); + CPPUNIT_ASSERT(pattern.group("srtpKeyMethod").compare("inline:")); + CPPUNIT_ASSERT(pattern.group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); - CPPUNIT_ASSERT(pattern->group("lifetime").compare("20") == 0); - CPPUNIT_ASSERT(pattern->group("mkiValue").compare("1") == 0); - CPPUNIT_ASSERT(pattern->group("mkiLength").compare("32") == 0); - - delete pattern; - pattern = NULL; + CPPUNIT_ASSERT(pattern.group("lifetime").compare("20") == 0); + CPPUNIT_ASSERT(pattern.group("mkiValue").compare("1") == 0); + CPPUNIT_ASSERT(pattern.group("mkiLength").compare("32") == 0); } @@ -122,22 +109,19 @@ void SdesNegotiatorTest::testKeyParamsPatternWithoutMKI() { DEBUG("-------------------- SdesNegotiatorTest::testKeyParamsPatternWithoutMKI --------------------\n"); - std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj"; + std::string subject("inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj"); - pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ + sfl::Pattern pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)" \ "(\\|2\\^(?P<lifetime>[0-9]+)\\|" \ "(?P<mkiValue>[0-9]+)\\:" \ "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); - *pattern << subject; - pattern->matches(); - CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); - CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") + pattern << subject; + pattern.matches(); + CPPUNIT_ASSERT(pattern.group("srtpKeyMethod").compare("inline:")); + CPPUNIT_ASSERT(pattern.group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); - - delete pattern; - pattern = NULL; } @@ -150,30 +134,19 @@ void SdesNegotiatorTest::testNegotiation() DEBUG("-------------------- SdesNegotiatorTest::testNegotiation --------------------\n"); // Add a new SDES crypto line to be processed. - remoteOffer = new std::vector<std::string>(); - remoteOffer->push_back(std::string("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")); - remoteOffer->push_back(std::string("a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32")); + std::vector<std::string> remoteOffer; + remoteOffer.push_back("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32"); + remoteOffer.push_back("a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32"); // Register the local capabilities. - localCapabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + std::vector<sfl::CryptoSuiteDefinition> localCapabilities; - for (int i = 0; i < 3; i++) { - localCapabilities->push_back(sfl::CryptoSuites[i]); - } + for (int i = 0; i < 3; ++i) + localCapabilities.push_back(sfl::CryptoSuites[i]); - sdesnego = new sfl::SdesNegotiator(*localCapabilities, *remoteOffer); + sfl::SdesNegotiator sdesnego(localCapabilities, remoteOffer); - CPPUNIT_ASSERT(sdesnego->negotiate()); - // CPPUNIT_ASSERT(sdesnego->getKeyInfo().compare("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")==0); - - delete remoteOffer; - remoteOffer = NULL; - - delete localCapabilities; - localCapabilities = NULL; - - delete sdesnego; - sdesnego = NULL; + CPPUNIT_ASSERT(sdesnego.negotiate()); } /** @@ -184,25 +157,21 @@ void SdesNegotiatorTest::testComponent() DEBUG("-------------------- SdesNegotiatorTest::testComponent --------------------\n"); // Register the local capabilities. - std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + std::vector<sfl::CryptoSuiteDefinition> capabilities; - //Support all the CryptoSuites - for (int i = 0; i < 3; i++) { - capabilities->push_back(sfl::CryptoSuites[i]); - } + // Support all the CryptoSuites + for (int i = 0; i < 3; i++) + capabilities.push_back(sfl::CryptoSuites[i]); // Make sure that if a component is missing, negotiate will fail std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:|2^20|1:32"); - std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); - cryptoOffer->push_back(cryptoLine); + std::vector<std::string> cryptoOffer; + cryptoOffer.push_back(cryptoLine); - sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); - - CPPUNIT_ASSERT(negotiator->negotiate() == false); + sfl::SdesNegotiator negotiator(capabilities, cryptoOffer); + CPPUNIT_ASSERT(!negotiator.negotiate()); } - - /** * Make sure that most simple case does not fail. */ @@ -211,37 +180,28 @@ void SdesNegotiatorTest::testMostSimpleCase() DEBUG("-------------------- SdesNegotiatorTest::testMostSimpleCase --------------------\n"); // Register the local capabilities. - std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + std::vector<sfl::CryptoSuiteDefinition> capabilities; - //Support all the CryptoSuites - for (int i = 0; i < 3; i++) { - capabilities->push_back(sfl::CryptoSuites[i]); - } + // Support all the CryptoSuites + for (int i = 0; i < 3; i++) + capabilities.push_back(sfl::CryptoSuites[i]); // Make sure taht this case works (since it's default for most application) std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); - std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); - cryptoOffer->push_back(cryptoLine); - - sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); + std::vector<std::string> cryptoOffer; + cryptoOffer.push_back(cryptoLine); - CPPUNIT_ASSERT(negotiator->negotiate() == true); + sfl::SdesNegotiator negotiator(capabilities, cryptoOffer); - CPPUNIT_ASSERT(negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_80"); - CPPUNIT_ASSERT(negotiator->getKeyMethod() == "inline"); - CPPUNIT_ASSERT(negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); - CPPUNIT_ASSERT(negotiator->getLifeTime() == ""); - CPPUNIT_ASSERT(negotiator->getMkiValue() == ""); - CPPUNIT_ASSERT(negotiator->getMkiLength() == ""); - CPPUNIT_ASSERT(negotiator->getAuthTagLength() == "80"); + CPPUNIT_ASSERT(negotiator.negotiate()); - - delete capabilities; - capabilities = NULL; - delete cryptoOffer; - cryptoOffer = NULL; - delete negotiator; - negotiator = NULL; + CPPUNIT_ASSERT(negotiator.getCryptoSuite() == "AES_CM_128_HMAC_SHA1_80"); + CPPUNIT_ASSERT(negotiator.getKeyMethod() == "inline"); + CPPUNIT_ASSERT(negotiator.getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + CPPUNIT_ASSERT(negotiator.getLifeTime().empty()); + CPPUNIT_ASSERT(negotiator.getMkiValue().empty()); + CPPUNIT_ASSERT(negotiator.getMkiLength().empty()); + CPPUNIT_ASSERT(negotiator.getAuthTagLength() == "80"); } @@ -250,34 +210,26 @@ void SdesNegotiatorTest::test32ByteKeyLength() DEBUG("-------------------- SdesNegotiatorTest::test32ByteKeyLength --------------------\n"); // Register the local capabilities. - std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + std::vector<sfl::CryptoSuiteDefinition> capabilities; //Support all the CryptoSuites - for (int i = 0; i < 3; i++) { - capabilities->push_back(sfl::CryptoSuites[i]); - } + for (int i = 0; i < 3; i++) + capabilities.push_back(sfl::CryptoSuites[i]); std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_32 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); - std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); - cryptoOffer->push_back(cryptoLine); - - sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); - - CPPUNIT_ASSERT(negotiator->negotiate() == true); - - CPPUNIT_ASSERT(negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_32"); - CPPUNIT_ASSERT(negotiator->getKeyMethod() == "inline"); - CPPUNIT_ASSERT(negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); - CPPUNIT_ASSERT(negotiator->getLifeTime() == ""); - CPPUNIT_ASSERT(negotiator->getMkiValue() == ""); - CPPUNIT_ASSERT(negotiator->getMkiLength() == ""); - CPPUNIT_ASSERT(negotiator->getAuthTagLength() == "32"); - - delete capabilities; - capabilities = NULL; - delete cryptoOffer; - cryptoOffer = NULL; - delete negotiator; - negotiator = NULL; + std::vector<std::string> cryptoOffer; + cryptoOffer.push_back(cryptoLine); + + sfl::SdesNegotiator negotiator(capabilities, cryptoOffer); + + CPPUNIT_ASSERT(negotiator.negotiate()); + + CPPUNIT_ASSERT(negotiator.getCryptoSuite() == "AES_CM_128_HMAC_SHA1_32"); + CPPUNIT_ASSERT(negotiator.getKeyMethod() == "inline"); + CPPUNIT_ASSERT(negotiator.getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + CPPUNIT_ASSERT(negotiator.getLifeTime().empty()); + CPPUNIT_ASSERT(negotiator.getMkiValue().empty()); + CPPUNIT_ASSERT(negotiator.getMkiLength().empty()); + CPPUNIT_ASSERT(negotiator.getAuthTagLength() == "32"); } diff --git a/daemon/test/sdesnegotiatortest.h b/daemon/test/sdesnegotiatortest.h index eb9bb74cde..a634f5bde0 100644 --- a/daemon/test/sdesnegotiatortest.h +++ b/daemon/test/sdesnegotiatortest.h @@ -80,8 +80,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); public: - - SdesNegotiatorTest(); /* * Code factoring - Common resources can be released here. * This method is called by unitcpp after each test @@ -103,14 +101,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase { void testMostSimpleCase(); void test32ByteKeyLength(); - - private: - NON_COPYABLE(SdesNegotiatorTest); - - sfl::Pattern *pattern; - sfl::SdesNegotiator *sdesnego; - std::vector<std::string> *remoteOffer; - std::vector<sfl::CryptoSuiteDefinition> *localCapabilities; }; /* Register our test module */ -- GitLab