]> git.sesse.net Git - vlc/blob - src/test/block_test.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / test / block_test.c
1 /*****************************************************************************
2  * block.c: Test for block_t stuff
3  *****************************************************************************
4  * Copyright (C) 2008 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <stdio.h>
26 #include <string.h>
27 #undef NDEBUG
28 #include <assert.h>
29
30 #include <vlc_common.h>
31 #include <vlc_block.h>
32
33 static const char text[] =
34     "This is a test!\n"
35     "This file can be deleted safely!\n";
36
37 static void test_block_File (void)
38 {
39     FILE *stream;
40     int res;
41
42     stream = fopen ("testfile.txt", "wb+");
43     assert (stream != NULL);
44
45     res = fputs (text, stream);
46     assert (res != EOF);
47     res = fflush (stream);
48     assert (res != EOF);
49
50     block_t *block = block_File (fileno (stream));
51     fclose (stream);
52
53     assert (block != NULL);
54     assert (block->i_buffer == strlen (text));
55     assert (!memcmp (block->p_buffer, text, block->i_buffer));
56     block_Release (block);
57
58     remove ("testfile.txt");
59 }
60
61 static void test_block (void)
62 {
63     block_t *block = block_Alloc (sizeof (text));
64     assert (block != NULL);
65
66     memcpy (block->p_buffer, text, sizeof (text));
67     block = block_Realloc (block, 0, sizeof (text));
68     assert (block != NULL);
69     assert (block->i_buffer == sizeof (text));
70     assert (!memcmp (block->p_buffer, text, sizeof (text)));
71
72     block = block_Realloc (block, 200, sizeof (text) + 200);
73     assert (block != NULL);
74     assert (block->i_buffer == 200 + sizeof (text) + 200);
75     assert (!memcmp (block->p_buffer + 200, text, sizeof (text)));
76
77     block = block_Realloc (block, -200, sizeof (text) + 200);
78     assert (block != NULL);
79     assert (block->i_buffer == sizeof (text));
80     assert (!memcmp (block->p_buffer, text, sizeof (text)));
81     block_Release (block);
82
83     //block = block_Alloc (SIZE_MAX);
84     //assert (block == NULL);
85 }
86
87 int main (void)
88 {
89     test_block_File ();
90     test_block ();
91     return 0;
92 }
93