chromecast: Hide some private variable from settings
[vlc.git] / src / test / picture_pool.c
blob35229cf66bd769642b4df0c46a31e610c4dd543e
1 /*****************************************************************************
2 * picture_pool.c: test cases for picture_poo_t
3 *****************************************************************************
4 * Copyright (C) 2014 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <stdbool.h>
26 #undef NDEBUG
27 #include <assert.h>
29 #include <vlc_common.h>
30 #include <vlc_es.h>
31 #include <vlc_picture_pool.h>
33 #define PICTURES 10
35 static video_format_t fmt;
36 static picture_pool_t *pool, *reserve;
38 static void test(bool zombie)
40 picture_t *pics[PICTURES];
42 pool = picture_pool_NewFromFormat(&fmt, PICTURES);
43 assert(pool != NULL);
45 for (unsigned i = 0; i < PICTURES; i++) {
46 pics[i] = picture_pool_Get(pool);
47 assert(pics[i] != NULL);
50 for (unsigned i = 0; i < PICTURES; i++)
51 assert(picture_pool_Get(pool) == NULL);
53 // Reserve currently assumes that all pictures are free (or reserved).
54 //assert(picture_pool_Reserve(pool, 1) == NULL);
56 for (unsigned i = 0; i < PICTURES / 2; i++)
57 picture_Hold(pics[i]);
59 for (unsigned i = 0; i < PICTURES / 2; i++)
60 picture_Release(pics[i]);
62 for (unsigned i = 0; i < PICTURES; i++) {
63 void *plane = pics[i]->p[0].p_pixels;
64 assert(plane != NULL);
65 picture_Release(pics[i]);
67 pics[i] = picture_pool_Get(pool);
68 assert(pics[i] != NULL);
69 assert(pics[i]->p[0].p_pixels == plane);
72 for (unsigned i = 0; i < PICTURES; i++)
73 picture_Release(pics[i]);
75 for (unsigned i = 0; i < PICTURES; i++) {
76 pics[i] = picture_pool_Wait(pool);
77 assert(pics[i] != NULL);
80 for (unsigned i = 0; i < PICTURES; i++)
81 picture_Release(pics[i]);
83 reserve = picture_pool_Reserve(pool, PICTURES / 2);
84 assert(reserve != NULL);
86 for (unsigned i = 0; i < PICTURES / 2; i++) {
87 pics[i] = picture_pool_Get(pool);
88 assert(pics[i] != NULL);
91 for (unsigned i = PICTURES / 2; i < PICTURES; i++) {
92 assert(picture_pool_Get(pool) == NULL);
93 pics[i] = picture_pool_Get(reserve);
94 assert(pics[i] != NULL);
97 if (!zombie)
98 for (unsigned i = 0; i < PICTURES; i++)
99 picture_Release(pics[i]);
101 picture_pool_Release(reserve);
102 picture_pool_Release(pool);
104 if (zombie)
105 for (unsigned i = 0; i < PICTURES; i++)
106 picture_Release(pics[i]);
109 int main(void)
111 video_format_Setup(&fmt, VLC_CODEC_I420, 320, 200, 320, 200, 1, 1);
113 pool = picture_pool_NewFromFormat(&fmt, PICTURES);
114 assert(pool != NULL);
115 assert(picture_pool_GetSize(pool) == PICTURES);
117 reserve = picture_pool_Reserve(pool, PICTURES / 2);
118 assert(reserve != NULL);
120 picture_pool_Release(reserve);
121 picture_pool_Release(pool);
123 test(false);
124 test(true);
126 return 0;