[vlc-commits] picture_pool: add test case

Rémi Denis-Courmont git at videolan.org
Mon Oct 27 21:31:13 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Oct 27 22:30:55 2014 +0200| [fbd0ccb714b4cf830c77fe11cf36524856903efd] | committer: Rémi Denis-Courmont

picture_pool: add test case

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

 src/Makefile.am         |    2 +
 src/test/picture_pool.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+)

diff --git a/src/Makefile.am b/src/Makefile.am
index 505b69f..e200669 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -520,6 +520,7 @@ check_PROGRAMS = \
 	test_dictionary \
 	test_i18n_atof \
 	test_md5 \
+	test_picture_pool \
 	test_timer \
 	test_url \
 	test_utf8 \
@@ -535,6 +536,7 @@ test_block_DEPENDENCIES =
 test_dictionary_SOURCES = test/dictionary.c
 test_i18n_atof_SOURCES = test/i18n_atof.c
 test_md5_SOURCES = test/md5.c
+test_picture_pool_SOURCES = test/picture_pool.c
 test_timer_SOURCES = test/timer.c
 test_url_SOURCES = test/url.c
 test_utf8_SOURCES = test/utf8.c
diff --git a/src/test/picture_pool.c b/src/test/picture_pool.c
new file mode 100644
index 0000000..f5d4542
--- /dev/null
+++ b/src/test/picture_pool.c
@@ -0,0 +1,114 @@
+/*****************************************************************************
+ * picture_pool.c: test cases for picture_poo_t
+ *****************************************************************************
+ * Copyright (C) 2014 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdbool.h>
+#undef NDEBUG
+#include <assert.h>
+
+#include <vlc_common.h>
+#include <vlc_es.h>
+#include <vlc_picture_pool.h>
+
+#define PICTURES 10
+
+static video_format_t fmt;
+static picture_pool_t *pool, *reserve;
+
+static void test(bool zombie)
+{
+    picture_t *pics[PICTURES];
+
+    pool = picture_pool_NewFromFormat(&fmt, PICTURES);
+    assert(pool != NULL);
+
+    for (unsigned i = 0; i < PICTURES; i++) {
+        pics[i] = picture_pool_Get(pool);
+        assert(pics[i] != NULL);
+    }
+
+    for (unsigned i = 0; i < PICTURES; i++)
+        assert(picture_pool_Get(pool) == NULL);
+
+    // Reserve currently assumes that all pictures are free (or reserved).
+    //assert(picture_pool_Reserve(pool, 1) == NULL);
+
+    for (unsigned i = 0; i < PICTURES / 2; i++)
+        picture_Hold(pics[i]);
+
+    for (unsigned i = 0; i < PICTURES / 2; i++)
+        picture_Release(pics[i]);
+
+    for (unsigned i = 0; i < PICTURES; i++) {
+        picture_Release(pics[i]);
+        assert(picture_pool_Get(pool) == pics[i]);
+    }
+
+    for (unsigned i = 0; i < PICTURES; i++)
+        picture_Release(pics[i]);
+
+    reserve = picture_pool_Reserve(pool, PICTURES / 2);
+    assert(reserve != NULL);
+
+    for (unsigned i = 0; i < PICTURES / 2; i++) {
+        pics[i] = picture_pool_Get(pool);
+        assert(pics[i] != NULL);
+    }
+
+    for (unsigned i = PICTURES / 2; i < PICTURES; i++) {
+        assert(picture_pool_Get(pool) == NULL);
+        pics[i] = picture_pool_Get(reserve);
+        assert(pics[i] != NULL);
+    }
+
+    if (!zombie)
+        for (unsigned i = 0; i < PICTURES; i++)
+            picture_Release(pics[i]);
+
+    picture_pool_Delete(reserve);
+    picture_pool_Delete(pool);
+
+    if (zombie)
+        for (unsigned i = 0; i < PICTURES; i++)
+            picture_Release(pics[i]);
+}
+
+int main(void)
+{
+    video_format_Setup(&fmt, VLC_CODEC_I420, 320, 200, 320, 200, 1, 1);
+
+    pool = picture_pool_NewFromFormat(&fmt, PICTURES);
+    assert(pool != NULL);
+    assert(picture_pool_GetSize(pool) == PICTURES);
+
+    reserve = picture_pool_Reserve(pool, PICTURES / 2);
+    assert(reserve != NULL);
+
+    picture_pool_Delete(reserve);
+    picture_pool_Delete(pool);
+
+    test(false);
+    test(true);
+
+    return 0;
+}



More information about the vlc-commits mailing list