Fix how we were using TbInterfaces and disallow operator=() and the copy constructor.
The reason is that this will cause a crash:
TbInterfaces foo = TbInterfaces("blah");
It relies on the generated copy constructor (or assignment operator), which copies the
pointer values from a temporary object. After |foo| in this case has been initialized
with values from the temporary object, the temp goes out of scope and is deleted.
The result is that |foo| has been initialized with pointers do a deleted object.
Also fixing expectations for the return value of VoE Release() calls after I checked
in my change that makes the VoiceEngine per-object ref counted and not per-interface.
Review URL: https://webrtc-codereview.appspot.com/509005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@2128 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/src/video_engine/test/auto_test/source/vie_autotest_base.cc b/src/video_engine/test/auto_test/source/vie_autotest_base.cc
index 32dbe7c..adc4afb 100644
--- a/src/video_engine/test/auto_test/source/vie_autotest_base.cc
+++ b/src/video_engine/test/auto_test/source/vie_autotest_base.cc
@@ -215,7 +215,9 @@
// Clean up voice engine
EXPECT_EQ(0, ptrVieNetwork->Release());
EXPECT_EQ(0, ptrViEBase->SetVoiceEngine(NULL));
- EXPECT_EQ(0, ptrVoEBase->Release());
+ // VoiceEngine reference counting is per object, not per interface, so
+ // Release should return != 0.
+ EXPECT_NE(0, ptrVoEBase->Release());
EXPECT_TRUE(webrtc::VoiceEngine::Delete(ptrVoE));
webrtc::ViEBase* ptrViEBase2 = webrtc::ViEBase::GetInterface(ptrViE);
diff --git a/src/video_engine/test/auto_test/source/vie_autotest_codec.cc b/src/video_engine/test/auto_test/source/vie_autotest_codec.cc
index 220a16f..68c44fd 100644
--- a/src/video_engine/test/auto_test/source/vie_autotest_codec.cc
+++ b/src/video_engine/test/auto_test/source/vie_autotest_codec.cc
@@ -109,7 +109,7 @@
};
void ViEAutoTest::ViECodecStandardTest() {
- TbInterfaces interfaces = TbInterfaces("ViECodecStandardTest");
+ TbInterfaces interfaces("ViECodecStandardTest");
TbCaptureDevice capture_device = TbCaptureDevice(interfaces);
int capture_id = capture_device.captureId;
@@ -273,7 +273,7 @@
ViECodecStandardTest();
ViECodecExternalCodecTest();
- TbInterfaces interfaces = TbInterfaces("ViECodecExtendedTest");
+ TbInterfaces interfaces("ViECodecExtendedTest");
webrtc::ViEBase* base = interfaces.base;
webrtc::ViECapture* capture = interfaces.capture;
webrtc::ViERender* render = interfaces.render;
diff --git a/src/video_engine/test/auto_test/source/vie_autotest_file.cc b/src/video_engine/test/auto_test/source/vie_autotest_file.cc
index 83ace52..e82fb9c 100644
--- a/src/video_engine/test/auto_test/source/vie_autotest_file.cc
+++ b/src/video_engine/test/auto_test/source/vie_autotest_file.cc
@@ -39,7 +39,7 @@
{
ViETest::Log("Starting a loopback call...");
- TbInterfaces interfaces = TbInterfaces("ViEFileStandardTest");
+ TbInterfaces interfaces("ViEFileStandardTest");
webrtc::VideoEngine* ptrViE = interfaces.video_engine;
webrtc::ViEBase* ptrViEBase = interfaces.base;
@@ -464,8 +464,9 @@
EXPECT_EQ(0, ptrViEBase->DisconnectAudioChannel(videoChannel));
EXPECT_EQ(0, ptrViEBase->SetVoiceEngine(NULL));
EXPECT_EQ(0, ptrVEBase->DeleteChannel(audioChannel));
- EXPECT_EQ(0, ptrVEBase->Release());
- EXPECT_EQ(0, ptrVECodec->Release());
+ // VoE reference counting is per-object, so we use EXPECT_NE
+ EXPECT_NE(0, ptrVEBase->Release());
+ EXPECT_NE(0, ptrVECodec->Release());
EXPECT_TRUE(webrtc::VoiceEngine::Delete(ptrVEEngine));
EXPECT_EQ(0, ptrViEBase->StopReceive(videoChannel));
diff --git a/src/video_engine/test/auto_test/source/vie_file_based_comparison_tests.cc b/src/video_engine/test/auto_test/source/vie_file_based_comparison_tests.cc
index 4b9d315..2f01381 100644
--- a/src/video_engine/test/auto_test/source/vie_file_based_comparison_tests.cc
+++ b/src/video_engine/test/auto_test/source/vie_file_based_comparison_tests.cc
@@ -87,7 +87,7 @@
ViEToFileRenderer* local_file_renderer,
ViEToFileRenderer* remote_file_renderer) {
- TbInterfaces interfaces = TbInterfaces("TestCodecs");
+ TbInterfaces interfaces("TestCodecs");
ViEFakeCamera fake_camera(interfaces.capture);
if (!fake_camera.StartCameraInNewThread(i420_video_file, width, height)) {
@@ -127,7 +127,7 @@
ViEToFileRenderer* local_file_renderer,
ViEToFileRenderer* remote_file_renderer,
FrameDropDetector* frame_drop_detector) {
- TbInterfaces interfaces = TbInterfaces("TestFullStack");
+ TbInterfaces interfaces("TestFullStack");
// Setup camera capturing from file.
ViEFakeCamera fake_camera(interfaces.capture);
diff --git a/src/video_engine/test/libvietest/include/tb_interfaces.h b/src/video_engine/test/libvietest/include/tb_interfaces.h
index 69d8b53..5060abb 100644
--- a/src/video_engine/test/libvietest/include/tb_interfaces.h
+++ b/src/video_engine/test/libvietest/include/tb_interfaces.h
@@ -13,6 +13,7 @@
#include <string>
+#include "constructor_magic.h"
#include "common_types.h"
#include "video_engine/include/vie_base.h"
#include "video_engine/include/vie_capture.h"
@@ -31,7 +32,7 @@
{
public:
// Sets up all interfaces and creates a trace file
- TbInterfaces(std::string test_name);
+ TbInterfaces(const std::string& test_name);
~TbInterfaces(void);
webrtc::VideoEngine* video_engine;
@@ -47,6 +48,9 @@
int LastError() {
return base->LastError();
}
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(TbInterfaces);
};
#endif // WEBRTC_VIDEO_ENGINE_MAIN_TEST_AUTOTEST_INTERFACE_TB_INTERFACES_H_
diff --git a/src/video_engine/test/libvietest/testbed/tb_interfaces.cc b/src/video_engine/test/libvietest/testbed/tb_interfaces.cc
index 80a161c..16d8902 100644
--- a/src/video_engine/test/libvietest/testbed/tb_interfaces.cc
+++ b/src/video_engine/test/libvietest/testbed/tb_interfaces.cc
@@ -13,7 +13,17 @@
#include "gtest/gtest.h"
#include "testsupport/fileutils.h"
-TbInterfaces::TbInterfaces(std::string test_name) {
+TbInterfaces::TbInterfaces(const std::string& test_name) :
+ video_engine(NULL),
+ base(NULL),
+ capture(NULL),
+ render(NULL),
+ rtp_rtcp(NULL),
+ codec(NULL),
+ network(NULL),
+ image_process(NULL),
+ encryption(NULL)
+{
std::string complete_path =
webrtc::test::OutputPath() + test_name + "_trace.txt";
@@ -53,15 +63,23 @@
TbInterfaces::~TbInterfaces(void)
{
EXPECT_EQ(0, encryption->Release());
+ encryption = NULL;
EXPECT_EQ(0, image_process->Release());
+ image_process = NULL;
EXPECT_EQ(0, codec->Release());
+ codec = NULL;
EXPECT_EQ(0, capture->Release());
+ capture = NULL;
EXPECT_EQ(0, render->Release());
+ render = NULL;
EXPECT_EQ(0, rtp_rtcp->Release());
+ rtp_rtcp = NULL;
EXPECT_EQ(0, network->Release());
+ network = NULL;
EXPECT_EQ(0, base->Release());
+ base = NULL;
EXPECT_TRUE(webrtc::VideoEngine::Delete(video_engine)) <<
"Since we have released all interfaces at this point, deletion "
"should be successful.";
-
+ video_engine = NULL;
}