picture_pool: add test case
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 27 Oct 2014 20:30:55 +0000 (22:30 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 27 Oct 2014 20:30:55 +0000 (22:30 +0200)
src/Makefile.am
src/test/picture_pool.c [new file with mode: 0644]

index 505b69f..e200669 100644 (file)
@@ -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 (file)
index 0000000..f5d4542
--- /dev/null
@@ -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;
+}