[vlc-commits] test: slaves: fix false positive when calling test_expected_slaves with 0

Thomas Guillem git at videolan.org
Mon Nov 6 15:54:44 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Nov  6 15:36:56 2017 +0100| [674c416d2d6ea7ca94bcdad25dbeec5d246ee3ae] | committer: Thomas Guillem

test: slaves: fix false positive when calling test_expected_slaves with 0

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=674c416d2d6ea7ca94bcdad25dbeec5d246ee3ae
---

 test/libvlc/slaves.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/test/libvlc/slaves.c b/test/libvlc/slaves.c
index 330532d391..e36e301d6c 100644
--- a/test/libvlc/slaves.c
+++ b/test/libvlc/slaves.c
@@ -73,33 +73,33 @@ test_expected_slaves(libvlc_media_t *p_m,
     unsigned int i_slave_count = libvlc_media_slaves_get(p_m, &pp_slaves);
     assert(i_expected_slaves == i_slave_count);
 
-    if (i_expected_slaves > 0)
+    unsigned i_found_slaves = 0;
+    bool *p_found_list = calloc(i_expected_slaves, sizeof(bool));
+    assert(p_found_list != NULL);
+    for (unsigned int i = 0; i < i_slave_count; ++i)
     {
-        bool *p_found_list = calloc(i_expected_slaves, sizeof(bool));
-        assert(p_found_list != NULL);
-        for (unsigned int i = 0; i < i_slave_count; ++i)
+        libvlc_media_slave_t *p_slave1 = pp_slaves[i];
+        for (unsigned int j = 0; j < i_expected_slaves; ++j)
         {
-            libvlc_media_slave_t *p_slave1 = pp_slaves[i];
-            for (unsigned int j = 0; i < i_expected_slaves; ++j)
+            libvlc_media_slave_t *p_slave2 = &p_expected_slaves[j];
+            if (strcmp(p_slave1->psz_uri, p_slave2->psz_uri) == 0)
             {
-                libvlc_media_slave_t *p_slave2 = &p_expected_slaves[j];
-                if (strcmp(p_slave1->psz_uri, p_slave2->psz_uri) == 0)
-                {
-                    assert(p_found_list[j] == false);
-                    assert(p_slave1->i_type == p_slave2->i_type);
-                    assert(p_slave1->i_priority == p_slave2->i_priority);
-                    p_found_list[j] = true;
-                    break;
-                }
+                assert(p_found_list[j] == false);
+                assert(p_slave1->i_type == p_slave2->i_type);
+                assert(p_slave1->i_priority == p_slave2->i_priority);
+                p_found_list[j] = true;
+                i_found_slaves++;
+                break;
             }
         }
-        for (unsigned int i = 0; i < i_expected_slaves; ++i)
-        {
-            printf("Check if slaves[%d] is found\n", i);
-            assert(p_found_list[i]);
-        }
-        free(p_found_list);
     }
+    assert(i_expected_slaves == i_found_slaves);
+    for (unsigned int i = 0; i < i_expected_slaves; ++i)
+    {
+        printf("Check if slaves[%d] is found\n", i);
+        assert(p_found_list[i]);
+    }
+    free(p_found_list);
 
     libvlc_media_slaves_release(pp_slaves, i_slave_count);
 }



More information about the vlc-commits mailing list