Initialize SSL in unittest_main.cc.

Instead of having each test individually initialize and tear down SSL
move this to unittest_main.cc so that all tests are properly
initialized and new tests "don't have to think about it".

R=pthatcher@webrtc.org
BUG=

Review URL: https://webrtc-codereview.appspot.com/30549004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7316 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org
2014-09-28 11:36:45 +00:00
parent 3a10d2f64f
commit 34f2a9ea72
25 changed files with 8 additions and 173 deletions

View File

@@ -97,14 +97,6 @@ static cricket::SessionDescription* CreateCricketSessionDescription() {
class JsepSessionDescriptionTest : public testing::Test { class JsepSessionDescriptionTest : public testing::Test {
protected: protected:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
virtual void SetUp() { virtual void SetUp() {
int port = 1234; int port = 1234;
rtc::SocketAddress address("127.0.0.1", port++); rtc::SocketAddress address("127.0.0.1", port++);

View File

@@ -919,9 +919,6 @@ class P2PTestConductor : public testing::Test {
receiving_client_->VerifyLocalIceUfragAndPassword(); receiving_client_->VerifyLocalIceUfragAndPassword();
} }
P2PTestConductor() {
rtc::InitializeSSL(NULL);
}
~P2PTestConductor() { ~P2PTestConductor() {
if (initiating_client_) { if (initiating_client_) {
initiating_client_->set_signaling_message_receiver(NULL); initiating_client_->set_signaling_message_receiver(NULL);
@@ -929,7 +926,6 @@ class P2PTestConductor : public testing::Test {
if (receiving_client_) { if (receiving_client_) {
receiving_client_->set_signaling_message_receiver(NULL); receiving_client_->set_signaling_message_receiver(NULL);
} }
rtc::CleanupSSL();
} }
bool CreateTestClients() { bool CreateTestClients() {

View File

@@ -134,7 +134,6 @@ class PeerConnectionEndToEndTest
"caller")), "caller")),
callee_(new rtc::RefCountedObject<PeerConnectionTestWrapper>( callee_(new rtc::RefCountedObject<PeerConnectionTestWrapper>(
"callee")) { "callee")) {
rtc::InitializeSSL(NULL);
} }
void CreatePcs() { void CreatePcs() {
@@ -262,10 +261,6 @@ class PeerConnectionEndToEndTest
kMaxWait); kMaxWait);
} }
~PeerConnectionEndToEndTest() {
rtc::CleanupSSL();
}
protected: protected:
rtc::scoped_refptr<PeerConnectionTestWrapper> caller_; rtc::scoped_refptr<PeerConnectionTestWrapper> caller_;
rtc::scoped_refptr<PeerConnectionTestWrapper> callee_; rtc::scoped_refptr<PeerConnectionTestWrapper> callee_;

View File

@@ -229,17 +229,12 @@ class MockPeerConnectionObserver : public PeerConnectionObserver {
class PeerConnectionInterfaceTest : public testing::Test { class PeerConnectionInterfaceTest : public testing::Test {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
rtc::InitializeSSL(NULL);
pc_factory_ = webrtc::CreatePeerConnectionFactory( pc_factory_ = webrtc::CreatePeerConnectionFactory(
rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL,
NULL); NULL);
ASSERT_TRUE(pc_factory_.get() != NULL); ASSERT_TRUE(pc_factory_.get() != NULL);
} }
virtual void TearDown() {
rtc::CleanupSSL();
}
void CreatePeerConnection() { void CreatePeerConnection() {
CreatePeerConnection("", "", NULL); CreatePeerConnection("", "", NULL);
} }

View File

@@ -330,14 +330,6 @@ class WebRtcSessionTest : public testing::Test {
allocator_->set_step_delay(cricket::kMinimumStepDelay); allocator_->set_step_delay(cricket::kMinimumStepDelay);
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
void AddInterface(const SocketAddress& addr) { void AddInterface(const SocketAddress& addr) {
network_manager_.AddInterface(addr); network_manager_.AddInterface(addr);
} }

View File

@@ -83,14 +83,6 @@ class FakeDataReceiver : public sigslot::has_slots<> {
class RtpDataMediaChannelTest : public testing::Test { class RtpDataMediaChannelTest : public testing::Test {
protected: protected:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
virtual void SetUp() { virtual void SetUp() {
// Seed needed for each test to satisfy expectations. // Seed needed for each test to satisfy expectations.
iface_.reset(new cricket::FakeNetworkInterface()); iface_.reset(new cricket::FakeNetworkInterface());

View File

@@ -229,11 +229,6 @@ class SctpDataMediaChannelTest : public testing::Test,
LOG(LS_WARNING) << "Unabled to initialize NSS."; LOG(LS_WARNING) << "Unabled to initialize NSS.";
} }
#endif // HAVE_NSS_SSL_H #endif // HAVE_NSS_SSL_H
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
} }
virtual void SetUp() { virtual void SetUp() {

View File

@@ -377,14 +377,6 @@ class DtlsTestClient : public sigslot::has_slots<> {
class DtlsTransportChannelTest : public testing::Test { class DtlsTransportChannelTest : public testing::Test {
public: public:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
DtlsTransportChannelTest() : DtlsTransportChannelTest() :
client1_("P1", rtc::Thread::Current(), client1_("P1", rtc::Thread::Current(),
rtc::Thread::Current()), rtc::Thread::Current()),

View File

@@ -366,14 +366,6 @@ class P2PTransportChannelTestBase : public testing::Test,
static const Result kLocalTcpToPrflxTcp; static const Result kLocalTcpToPrflxTcp;
static const Result kPrflxTcpToLocalTcp; static const Result kPrflxTcpToLocalTcp;
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
rtc::NATSocketServer* nat() { return nss_.get(); } rtc::NATSocketServer* nat() { return nss_.get(); }
rtc::FirewallSocketServer* fw() { return ss_.get(); } rtc::FirewallSocketServer* fw() { return ss_.get(); }

View File

@@ -357,15 +357,6 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
} }
protected: protected:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
void TestLocalToLocal() { void TestLocalToLocal() {
Port* port1 = CreateUdpPort(kLocalAddr1); Port* port1 = CreateUdpPort(kLocalAddr1);
Port* port2 = CreateUdpPort(kLocalAddr2); Port* port2 = CreateUdpPort(kLocalAddr2);

View File

@@ -93,15 +93,6 @@ class RelayPortTest : public testing::Test,
} }
protected: protected:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
virtual void SetUp() { virtual void SetUp() {
// The relay server needs an external socket to work properly. // The relay server needs an external socket to work properly.
rtc::AsyncUDPSocket* ext_socket = rtc::AsyncUDPSocket* ext_socket =

View File

@@ -53,14 +53,6 @@ static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce...";
class RelayServerTest : public testing::Test { class RelayServerTest : public testing::Test {
public: public:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
RelayServerTest() RelayServerTest()
: main_(rtc::Thread::Current()), ss_(main_->socketserver()), : main_(rtc::Thread::Current()), ss_(main_->socketserver()),
username_(rtc::CreateRandomString(12)), username_(rtc::CreateRandomString(12)),

View File

@@ -128,14 +128,10 @@ class StunPortTest : public testing::Test,
protected: protected:
static void SetUpTestCase() { static void SetUpTestCase() {
rtc::InitializeSSL();
// Ensure the RNG is inited. // Ensure the RNG is inited.
rtc::InitRandom(NULL, 0); rtc::InitRandom(NULL, 0);
} }
static void TearDownTestCase() {
rtc::CleanupSSL();
}
void OnPortComplete(cricket::Port* port) { void OnPortComplete(cricket::Port* port) {
ASSERT_FALSE(done_); ASSERT_FALSE(done_);

View File

@@ -37,14 +37,6 @@ using namespace cricket;
class StunRequestTest : public testing::Test, class StunRequestTest : public testing::Test,
public sigslot::has_slots<> { public sigslot::has_slots<> {
public: public:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
StunRequestTest() StunRequestTest()
: manager_(rtc::Thread::Current()), : manager_(rtc::Thread::Current()),
request_count_(0), response_(NULL), request_count_(0), response_(NULL),

View File

@@ -47,10 +47,6 @@ class TransportDescriptionFactoryTest : public testing::Test {
id2_(new rtc::FakeSSLIdentity("User2")) { id2_(new rtc::FakeSSLIdentity("User2")) {
} }
// Make sure SSL is set up as it's used by the tests.
static void SetUpTestCase() { rtc::InitializeSSL(); }
static void TearDownTestCase() { rtc::CleanupSSL(); }
void CheckDesc(const TransportDescription* desc, const std::string& type, void CheckDesc(const TransportDescription* desc, const std::string& type,
const std::string& opt, const std::string& ice_ufrag, const std::string& opt, const std::string& ice_ufrag,
const std::string& ice_pwd, const std::string& dtls_alg) { const std::string& ice_pwd, const std::string& dtls_alg) {

View File

@@ -124,14 +124,6 @@ class TurnPortTest : public testing::Test,
network_.AddIP(rtc::IPAddress(INADDR_ANY)); network_.AddIP(rtc::IPAddress(INADDR_ANY));
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
virtual void OnMessage(rtc::Message* msg) { virtual void OnMessage(rtc::Message* msg) {
ASSERT(msg->message_id == MSG_TESTFINISH); ASSERT(msg->message_id == MSG_TESTFINISH);
if (msg->message_id == MSG_TESTFINISH) if (msg->message_id == MSG_TESTFINISH)

View File

@@ -97,14 +97,6 @@ std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) {
class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> {
public: public:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
PortAllocatorTest() PortAllocatorTest()
: pss_(new rtc::PhysicalSocketServer), : pss_(new rtc::PhysicalSocketServer),
vss_(new rtc::VirtualSocketServer(pss_.get())), vss_(new rtc::VirtualSocketServer(pss_.get())),

View File

@@ -143,14 +143,6 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
error_(T::MediaChannel::ERROR_NONE) { error_(T::MediaChannel::ERROR_NONE) {
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
void CreateChannels(int flags1, int flags2) { void CreateChannels(int flags1, int flags2) {
CreateChannels(new typename T::MediaChannel(NULL), CreateChannels(new typename T::MediaChannel(NULL),
new typename T::MediaChannel(NULL), new typename T::MediaChannel(NULL),

View File

@@ -204,14 +204,6 @@ class MediaSessionDescriptionFactoryTest : public testing::Test {
tdf2_.set_identity(&id2_); tdf2_.set_identity(&id2_);
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
// Create a video StreamParamsVec object with: // Create a video StreamParamsVec object with:
// - one video stream with 3 simulcast streams and FEC, // - one video stream with 3 simulcast streams and FEC,
StreamParamsVec CreateComplexVideoStreamParamsVec() { StreamParamsVec CreateComplexVideoStreamParamsVec() {

View File

@@ -2764,12 +2764,7 @@ MediaSessionClientTest* JingleTest() {
cricket::PROTOCOL_JINGLE); cricket::PROTOCOL_JINGLE);
} }
class MediaSessionTest : public ::testing::Test { class MediaSessionTest : public ::testing::Test {};
protected:
// Make sure SSL is set up as it's used by the tests.
static void SetUpTestCase() { rtc::InitializeSSL(); }
static void TearDownTestCase() { rtc::CleanupSSL(); }
};
TEST_F(MediaSessionTest, JingleGoodInitiateWithRtcpFb) { TEST_F(MediaSessionTest, JingleGoodInitiateWithRtcpFb) {
rtc::scoped_ptr<MediaSessionClientTest> test(JingleTest()); rtc::scoped_ptr<MediaSessionClientTest> test(JingleTest());

View File

@@ -16,16 +16,7 @@
namespace rtc { namespace rtc {
class RandomTest : public testing::Test { class RandomTest : public testing::Test {};
public:
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
};
TEST_F(RandomTest, TestCreateRandomId) { TEST_F(RandomTest, TestCreateRandomId) {
CreateRandomId(); CreateRandomId();

View File

@@ -247,14 +247,6 @@ class SSLAdapterTestBase : public testing::Test,
handshake_wait_(kTimeout) { handshake_wait_(kTimeout) {
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
void SetHandshakeWait(int wait) { void SetHandshakeWait(int wait) {
handshake_wait_ = wait; handshake_wait_ = wait;
} }

View File

@@ -45,14 +45,6 @@ class SSLIdentityTest : public testing::Test {
~SSLIdentityTest() { ~SSLIdentityTest() {
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
virtual void SetUp() { virtual void SetUp() {
identity1_.reset(SSLIdentity::Generate("test1")); identity1_.reset(SSLIdentity::Generate("test1"));
identity2_.reset(SSLIdentity::Generate("test2")); identity2_.reset(SSLIdentity::Generate("test2"));

View File

@@ -194,14 +194,6 @@ class SSLStreamAdapterTestBase : public testing::Test,
rtc::SetRandomTestMode(false); rtc::SetRandomTestMode(false);
} }
static void SetUpTestCase() {
rtc::InitializeSSL();
}
static void TearDownTestCase() {
rtc::CleanupSSL();
}
// Recreate the client/server identities with the specified validity period. // Recreate the client/server identities with the specified validity period.
// |not_before| and |not_after| are offsets from the current time in number // |not_before| and |not_after| are offsets from the current time in number
// of seconds. // of seconds.

View File

@@ -18,6 +18,7 @@
#include "webrtc/base/fileutils.h" #include "webrtc/base/fileutils.h"
#include "webrtc/base/gunit.h" #include "webrtc/base/gunit.h"
#include "webrtc/base/logging.h" #include "webrtc/base/logging.h"
#include "webrtc/base/ssladapter.h"
DEFINE_bool(help, false, "prints this message"); DEFINE_bool(help, false, "prints this message");
DEFINE_string(log, "", "logging options to use"); DEFINE_string(log, "", "logging options to use");
@@ -85,8 +86,13 @@ int main(int argc, char** argv) {
rtc::LogMessage::ConfigureLogging(FLAG_log, "unittest.log"); rtc::LogMessage::ConfigureLogging(FLAG_log, "unittest.log");
} }
// Initialize SSL which are used by several tests.
rtc::InitializeSSL();
int res = RUN_ALL_TESTS(); int res = RUN_ALL_TESTS();
rtc::CleanupSSL();
// clean up logging so we don't appear to leak memory. // clean up logging so we don't appear to leak memory.
rtc::LogMessage::ConfigureLogging("", ""); rtc::LogMessage::ConfigureLogging("", "");