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
diff --git a/talk/app/webrtc/jsepsessiondescription_unittest.cc b/talk/app/webrtc/jsepsessiondescription_unittest.cc
index 5f5d808..769e34a 100644
--- a/talk/app/webrtc/jsepsessiondescription_unittest.cc
+++ b/talk/app/webrtc/jsepsessiondescription_unittest.cc
@@ -97,14 +97,6 @@
 
 class JsepSessionDescriptionTest : public testing::Test {
  protected:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   virtual void SetUp() {
     int port = 1234;
     rtc::SocketAddress address("127.0.0.1", port++);
diff --git a/talk/app/webrtc/peerconnection_unittest.cc b/talk/app/webrtc/peerconnection_unittest.cc
index 977fc11..94e7731 100644
--- a/talk/app/webrtc/peerconnection_unittest.cc
+++ b/talk/app/webrtc/peerconnection_unittest.cc
@@ -919,9 +919,6 @@
     receiving_client_->VerifyLocalIceUfragAndPassword();
   }
 
-  P2PTestConductor() {
-    rtc::InitializeSSL(NULL);
-  }
   ~P2PTestConductor() {
     if (initiating_client_) {
       initiating_client_->set_signaling_message_receiver(NULL);
@@ -929,7 +926,6 @@
     if (receiving_client_) {
       receiving_client_->set_signaling_message_receiver(NULL);
     }
-    rtc::CleanupSSL();
   }
 
   bool CreateTestClients() {
diff --git a/talk/app/webrtc/peerconnectionendtoend_unittest.cc b/talk/app/webrtc/peerconnectionendtoend_unittest.cc
index 8984781..4db3fe3 100644
--- a/talk/app/webrtc/peerconnectionendtoend_unittest.cc
+++ b/talk/app/webrtc/peerconnectionendtoend_unittest.cc
@@ -134,7 +134,6 @@
                     "caller")),
         callee_(new rtc::RefCountedObject<PeerConnectionTestWrapper>(
                     "callee")) {
-    rtc::InitializeSSL(NULL);
   }
 
   void CreatePcs() {
@@ -262,10 +261,6 @@
                    kMaxWait);
   }
 
-  ~PeerConnectionEndToEndTest() {
-    rtc::CleanupSSL();
-  }
-
  protected:
   rtc::scoped_refptr<PeerConnectionTestWrapper> caller_;
   rtc::scoped_refptr<PeerConnectionTestWrapper> callee_;
diff --git a/talk/app/webrtc/peerconnectioninterface_unittest.cc b/talk/app/webrtc/peerconnectioninterface_unittest.cc
index e957b21..bf60673 100644
--- a/talk/app/webrtc/peerconnectioninterface_unittest.cc
+++ b/talk/app/webrtc/peerconnectioninterface_unittest.cc
@@ -229,17 +229,12 @@
 class PeerConnectionInterfaceTest : public testing::Test {
  protected:
   virtual void SetUp() {
-    rtc::InitializeSSL(NULL);
     pc_factory_ = webrtc::CreatePeerConnectionFactory(
         rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL,
         NULL);
     ASSERT_TRUE(pc_factory_.get() != NULL);
   }
 
-  virtual void TearDown() {
-    rtc::CleanupSSL();
-  }
-
   void CreatePeerConnection() {
     CreatePeerConnection("", "", NULL);
   }
diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc
index 388fff7..29a7b26 100644
--- a/talk/app/webrtc/webrtcsession_unittest.cc
+++ b/talk/app/webrtc/webrtcsession_unittest.cc
@@ -330,14 +330,6 @@
     allocator_->set_step_delay(cricket::kMinimumStepDelay);
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   void AddInterface(const SocketAddress& addr) {
     network_manager_.AddInterface(addr);
   }
diff --git a/talk/media/base/rtpdataengine_unittest.cc b/talk/media/base/rtpdataengine_unittest.cc
index 1f0a237..884fab4 100644
--- a/talk/media/base/rtpdataengine_unittest.cc
+++ b/talk/media/base/rtpdataengine_unittest.cc
@@ -83,14 +83,6 @@
 
 class RtpDataMediaChannelTest : public testing::Test {
  protected:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   virtual void SetUp() {
     // Seed needed for each test to satisfy expectations.
     iface_.reset(new cricket::FakeNetworkInterface());
diff --git a/talk/media/sctp/sctpdataengine_unittest.cc b/talk/media/sctp/sctpdataengine_unittest.cc
index fb00650..3729fcb 100644
--- a/talk/media/sctp/sctpdataengine_unittest.cc
+++ b/talk/media/sctp/sctpdataengine_unittest.cc
@@ -229,11 +229,6 @@
     LOG(LS_WARNING) << "Unabled to initialize NSS.";
   }
 #endif  // HAVE_NSS_SSL_H
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
   }
 
   virtual void SetUp() {
diff --git a/talk/p2p/base/dtlstransportchannel_unittest.cc b/talk/p2p/base/dtlstransportchannel_unittest.cc
index bc1cf27..64825bc 100644
--- a/talk/p2p/base/dtlstransportchannel_unittest.cc
+++ b/talk/p2p/base/dtlstransportchannel_unittest.cc
@@ -377,14 +377,6 @@
 
 class DtlsTransportChannelTest : public testing::Test {
  public:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   DtlsTransportChannelTest() :
       client1_("P1", rtc::Thread::Current(),
                rtc::Thread::Current()),
diff --git a/talk/p2p/base/p2ptransportchannel_unittest.cc b/talk/p2p/base/p2ptransportchannel_unittest.cc
index 9bfa84f..44c76ee 100644
--- a/talk/p2p/base/p2ptransportchannel_unittest.cc
+++ b/talk/p2p/base/p2ptransportchannel_unittest.cc
@@ -366,14 +366,6 @@
   static const Result kLocalTcpToPrflxTcp;
   static const Result kPrflxTcpToLocalTcp;
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   rtc::NATSocketServer* nat() { return nss_.get(); }
   rtc::FirewallSocketServer* fw() { return ss_.get(); }
 
diff --git a/talk/p2p/base/port_unittest.cc b/talk/p2p/base/port_unittest.cc
index a44a12e..efa3f65 100644
--- a/talk/p2p/base/port_unittest.cc
+++ b/talk/p2p/base/port_unittest.cc
@@ -357,15 +357,6 @@
   }
 
  protected:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
-
   void TestLocalToLocal() {
     Port* port1 = CreateUdpPort(kLocalAddr1);
     Port* port2 = CreateUdpPort(kLocalAddr2);
diff --git a/talk/p2p/base/relayport_unittest.cc b/talk/p2p/base/relayport_unittest.cc
index 25777d1..ebb16c5 100644
--- a/talk/p2p/base/relayport_unittest.cc
+++ b/talk/p2p/base/relayport_unittest.cc
@@ -93,15 +93,6 @@
   }
 
  protected:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
-
   virtual void SetUp() {
     // The relay server needs an external socket to work properly.
     rtc::AsyncUDPSocket* ext_socket =
diff --git a/talk/p2p/base/relayserver_unittest.cc b/talk/p2p/base/relayserver_unittest.cc
index 1091807..5d77ca6 100644
--- a/talk/p2p/base/relayserver_unittest.cc
+++ b/talk/p2p/base/relayserver_unittest.cc
@@ -53,14 +53,6 @@
 
 class RelayServerTest : public testing::Test {
  public:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   RelayServerTest()
       : main_(rtc::Thread::Current()), ss_(main_->socketserver()),
         username_(rtc::CreateRandomString(12)),
diff --git a/talk/p2p/base/stunport_unittest.cc b/talk/p2p/base/stunport_unittest.cc
index c5abc48..5c97ecc 100644
--- a/talk/p2p/base/stunport_unittest.cc
+++ b/talk/p2p/base/stunport_unittest.cc
@@ -128,14 +128,10 @@
 
  protected:
   static void SetUpTestCase() {
-    rtc::InitializeSSL();
     // Ensure the RNG is inited.
     rtc::InitRandom(NULL, 0);
 
   }
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
 
   void OnPortComplete(cricket::Port* port) {
     ASSERT_FALSE(done_);
diff --git a/talk/p2p/base/stunrequest_unittest.cc b/talk/p2p/base/stunrequest_unittest.cc
index 3c42214..2783aa3 100644
--- a/talk/p2p/base/stunrequest_unittest.cc
+++ b/talk/p2p/base/stunrequest_unittest.cc
@@ -37,14 +37,6 @@
 class StunRequestTest : public testing::Test,
                         public sigslot::has_slots<> {
  public:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   StunRequestTest()
       : manager_(rtc::Thread::Current()),
         request_count_(0), response_(NULL),
diff --git a/talk/p2p/base/transportdescriptionfactory_unittest.cc b/talk/p2p/base/transportdescriptionfactory_unittest.cc
index c481d51..5c17f96 100644
--- a/talk/p2p/base/transportdescriptionfactory_unittest.cc
+++ b/talk/p2p/base/transportdescriptionfactory_unittest.cc
@@ -47,10 +47,6 @@
         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,
                  const std::string& opt, const std::string& ice_ufrag,
                  const std::string& ice_pwd, const std::string& dtls_alg) {
diff --git a/talk/p2p/base/turnport_unittest.cc b/talk/p2p/base/turnport_unittest.cc
index d895cbd..c5261e4 100644
--- a/talk/p2p/base/turnport_unittest.cc
+++ b/talk/p2p/base/turnport_unittest.cc
@@ -124,14 +124,6 @@
     network_.AddIP(rtc::IPAddress(INADDR_ANY));
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   virtual void OnMessage(rtc::Message* msg) {
     ASSERT(msg->message_id == MSG_TESTFINISH);
     if (msg->message_id == MSG_TESTFINISH)
diff --git a/talk/p2p/client/portallocator_unittest.cc b/talk/p2p/client/portallocator_unittest.cc
index b1feca2..84b8d03 100644
--- a/talk/p2p/client/portallocator_unittest.cc
+++ b/talk/p2p/client/portallocator_unittest.cc
@@ -97,14 +97,6 @@
 
 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> {
  public:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   PortAllocatorTest()
       : pss_(new rtc::PhysicalSocketServer),
         vss_(new rtc::VirtualSocketServer(pss_.get())),
diff --git a/talk/session/media/channel_unittest.cc b/talk/session/media/channel_unittest.cc
index 625b802..18f1b67 100644
--- a/talk/session/media/channel_unittest.cc
+++ b/talk/session/media/channel_unittest.cc
@@ -143,14 +143,6 @@
         error_(T::MediaChannel::ERROR_NONE) {
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   void CreateChannels(int flags1, int flags2) {
     CreateChannels(new typename T::MediaChannel(NULL),
                    new typename T::MediaChannel(NULL),
diff --git a/talk/session/media/mediasession_unittest.cc b/talk/session/media/mediasession_unittest.cc
index 2d2e2c8..1b66f88 100644
--- a/talk/session/media/mediasession_unittest.cc
+++ b/talk/session/media/mediasession_unittest.cc
@@ -204,14 +204,6 @@
     tdf2_.set_identity(&id2_);
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   // Create a video StreamParamsVec object with:
   // - one video stream with 3 simulcast streams and FEC,
   StreamParamsVec CreateComplexVideoStreamParamsVec() {
diff --git a/talk/session/media/mediasessionclient_unittest.cc b/talk/session/media/mediasessionclient_unittest.cc
index 113d62c..d313f81 100644
--- a/talk/session/media/mediasessionclient_unittest.cc
+++ b/talk/session/media/mediasessionclient_unittest.cc
@@ -2764,12 +2764,7 @@
                                     cricket::PROTOCOL_JINGLE);
 }
 
-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(); }
-};
+class MediaSessionTest : public ::testing::Test {};
 
 TEST_F(MediaSessionTest, JingleGoodInitiateWithRtcpFb) {
   rtc::scoped_ptr<MediaSessionClientTest> test(JingleTest());
diff --git a/webrtc/base/helpers_unittest.cc b/webrtc/base/helpers_unittest.cc
index 7c20540..6ea0167 100644
--- a/webrtc/base/helpers_unittest.cc
+++ b/webrtc/base/helpers_unittest.cc
@@ -16,16 +16,7 @@
 
 namespace rtc {
 
-class RandomTest : public testing::Test {
- public:
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-};
+class RandomTest : public testing::Test {};
 
 TEST_F(RandomTest, TestCreateRandomId) {
   CreateRandomId();
diff --git a/webrtc/base/ssladapter_unittest.cc b/webrtc/base/ssladapter_unittest.cc
index 6d4536d..4590db9 100644
--- a/webrtc/base/ssladapter_unittest.cc
+++ b/webrtc/base/ssladapter_unittest.cc
@@ -247,14 +247,6 @@
         handshake_wait_(kTimeout) {
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   void SetHandshakeWait(int wait) {
     handshake_wait_ = wait;
   }
diff --git a/webrtc/base/sslidentity_unittest.cc b/webrtc/base/sslidentity_unittest.cc
index 1486beb..3f756ef 100644
--- a/webrtc/base/sslidentity_unittest.cc
+++ b/webrtc/base/sslidentity_unittest.cc
@@ -45,14 +45,6 @@
   ~SSLIdentityTest() {
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   virtual void SetUp() {
     identity1_.reset(SSLIdentity::Generate("test1"));
     identity2_.reset(SSLIdentity::Generate("test2"));
diff --git a/webrtc/base/sslstreamadapter_unittest.cc b/webrtc/base/sslstreamadapter_unittest.cc
index 0538314..622e309 100644
--- a/webrtc/base/sslstreamadapter_unittest.cc
+++ b/webrtc/base/sslstreamadapter_unittest.cc
@@ -194,14 +194,6 @@
     rtc::SetRandomTestMode(false);
   }
 
-  static void SetUpTestCase() {
-    rtc::InitializeSSL();
-  }
-
-  static void TearDownTestCase() {
-    rtc::CleanupSSL();
-  }
-
   // Recreate the client/server identities with the specified validity period.
   // |not_before| and |not_after| are offsets from the current time in number
   // of seconds.
diff --git a/webrtc/base/unittest_main.cc b/webrtc/base/unittest_main.cc
index 5d412d5..c9864fe 100644
--- a/webrtc/base/unittest_main.cc
+++ b/webrtc/base/unittest_main.cc
@@ -18,6 +18,7 @@
 #include "webrtc/base/fileutils.h"
 #include "webrtc/base/gunit.h"
 #include "webrtc/base/logging.h"
+#include "webrtc/base/ssladapter.h"
 
 DEFINE_bool(help, false, "prints this message");
 DEFINE_string(log, "", "logging options to use");
@@ -85,8 +86,13 @@
     rtc::LogMessage::ConfigureLogging(FLAG_log, "unittest.log");
   }
 
+  // Initialize SSL which are used by several tests.
+  rtc::InitializeSSL();
+
   int res = RUN_ALL_TESTS();
 
+  rtc::CleanupSSL();
+
   // clean up logging so we don't appear to leak memory.
   rtc::LogMessage::ConfigureLogging("", "");