From 6f9c48348b13021947909e594104c3c31fb270c9 Mon Sep 17 00:00:00 2001
From: "henrikg@webrtc.org"
 <henrikg@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>
Date: Fri, 21 Mar 2014 14:41:27 +0000
Subject: [PATCH] Fixing crash in video_render_tests in release mode.

This is a test bug. Fixed usage of assert.

BUG=1917
R=mflodman@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5750 4adac7df-926f-26a2-2b94-8c16560cd09d
---
 .../video_render/test/testAPI/testAPI.cc      | 65 ++++++++++++++-----
 1 file changed, 47 insertions(+), 18 deletions(-)

diff --git a/webrtc/modules/video_render/test/testAPI/testAPI.cc b/webrtc/modules/video_render/test/testAPI/testAPI.cc
index 9764ae64e..418171869 100644
--- a/webrtc/modules/video_render/test/testAPI/testAPI.cc
+++ b/webrtc/modules/video_render/test/testAPI/testAPI.cc
@@ -423,6 +423,8 @@ int TestBitmapText(VideoRender* renderModule) {
 }
 
 int TestMultipleStreams(VideoRender* renderModule) {
+    int error = 0;
+
     // Add settings for a stream to render
     printf("Add stream 0\n");
     const int streamId0 = 0;
@@ -444,10 +446,19 @@ int TestMultipleStreams(VideoRender* renderModule) {
     VideoRenderCallback* renderCallback3 =
         renderModule->AddIncomingRenderStream(streamId3, 0, 0.55f, 0.55f, 1.0f, 1.0f);
     assert(renderCallback3 != NULL);
-    assert(renderModule->StartRender(streamId0) == 0);
-    assert(renderModule->StartRender(streamId1) == 0);
-    assert(renderModule->StartRender(streamId2) == 0);
-    assert(renderModule->StartRender(streamId3) == 0);
+    error = renderModule->StartRender(streamId0);
+    if (error != 0) {
+      // TODO(phoglund): This test will not work if compiled in release mode.
+      // This rather silly construct here is to avoid compilation errors when
+      // compiling in release. Release => no asserts => unused 'error' variable.
+      assert(false);
+    }
+    error = renderModule->StartRender(streamId1);
+    assert(error == 0);
+    error = renderModule->StartRender(streamId2);
+    assert(error == 0);
+    error = renderModule->StartRender(streamId3);
+    assert(error == 0);
 
     // Loop through an I420 file and render each frame
     const int width = 352;
@@ -493,19 +504,28 @@ int TestMultipleStreams(VideoRender* renderModule) {
 
     // Shut down
     printf("Closing...\n");
-    assert(renderModule->StopRender(streamId0) == 0);
-    assert(renderModule->DeleteIncomingRenderStream(streamId0) == 0);
-    assert(renderModule->StopRender(streamId1) == 0);
-    assert(renderModule->DeleteIncomingRenderStream(streamId1) == 0);
-    assert(renderModule->StopRender(streamId2) == 0);
-    assert(renderModule->DeleteIncomingRenderStream(streamId2) == 0);
-    assert(renderModule->StopRender(streamId3) == 0);
-    assert(renderModule->DeleteIncomingRenderStream(streamId3) == 0);
+    error = renderModule->StopRender(streamId0);
+    assert(error == 0);
+    error = renderModule->DeleteIncomingRenderStream(streamId0);
+    assert(error == 0);
+    error = renderModule->StopRender(streamId1);
+    assert(error == 0);
+    error = renderModule->DeleteIncomingRenderStream(streamId1);
+    assert(error == 0);
+    error = renderModule->StopRender(streamId2);
+    assert(error == 0);
+    error = renderModule->DeleteIncomingRenderStream(streamId2);
+    assert(error == 0);
+    error = renderModule->StopRender(streamId3);
+    assert(error == 0);
+    error = renderModule->DeleteIncomingRenderStream(streamId3);
+    assert(error == 0);
 
     return 0;
 }
 
 int TestExternalRender(VideoRender* renderModule) {
+    int error = 0;
     MyRenderCallback *externalRender = new MyRenderCallback();
 
     const int streamId0 = 0;
@@ -513,10 +533,16 @@ int TestExternalRender(VideoRender* renderModule) {
         renderModule->AddIncomingRenderStream(streamId0, 0, 0.0f, 0.0f,
                                                    1.0f, 1.0f);
     assert(renderCallback0 != NULL);
-    assert(renderModule->AddExternalRenderCallback(streamId0,
-                                                   externalRender) == 0);
+    error = renderModule->AddExternalRenderCallback(streamId0, externalRender);
+    if (error != 0) {
+      // TODO(phoglund): This test will not work if compiled in release mode.
+      // This rather silly construct here is to avoid compilation errors when
+      // compiling in release. Release => no asserts => unused 'error' variable.
+      assert(false);
+    }
 
-    assert(renderModule->StartRender(streamId0) == 0);
+    error = renderModule->StartRender(streamId0);
+    assert(error == 0);
 
     const int width = 352;
     const int half_width = (width + 1) / 2;
@@ -536,8 +562,12 @@ int TestExternalRender(VideoRender* renderModule) {
     // Sleep and let all frames be rendered before closing
     SleepMs(2*renderDelayMs);
 
-    assert(renderModule->StopRender(streamId0) == 0);
-    assert(renderModule->DeleteIncomingRenderStream(streamId0) == 0);
+    // Shut down
+    printf("Closing...\n");
+    error = renderModule->StopRender(streamId0);
+    assert(error == 0);
+    error = renderModule->DeleteIncomingRenderStream(streamId0);
+    assert(error == 0);
     assert(frameCount == externalRender->_cnt);
 
     delete externalRender;
@@ -562,7 +592,6 @@ void RunVideoRenderTests(void* window, VideoRenderType windowType) {
                                                   windowType);
     assert(renderModule != NULL);
 
-
     // ##### Test single stream rendering ####
     printf("#### TestSingleStream ####\n");
     if (TestSingleStream(renderModule) != 0) {