1 /*****************************************************************************
2 * block_test.c: Test for block_t stuff
3 *****************************************************************************
4 * Copyright (C) 2008 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 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_block.h>
33 static const char text
[] =
35 "This file can be deleted safely!\n";
37 static void test_block_File(bool write
)
42 stream
= fopen ("testfile.txt", "wb+e");
43 assert (stream
!= NULL
);
45 res
= fputs (text
, stream
);
47 res
= fflush (stream
);
50 block_t
*block
= block_File(fileno(stream
), write
);
53 assert (block
!= NULL
);
54 assert (block
->i_buffer
== strlen (text
));
55 assert (!memcmp (block
->p_buffer
, text
, block
->i_buffer
));
57 memset(block
->p_buffer
, 'A', block
->i_buffer
);
58 block_Release (block
);
60 remove ("testfile.txt");
63 static void test_block (void)
65 block_t
*block
= block_Alloc (sizeof (text
));
66 assert (block
!= NULL
);
68 memcpy (block
->p_buffer
, text
, sizeof (text
));
69 block
= block_Realloc (block
, 0, sizeof (text
));
70 assert (block
!= NULL
);
71 assert (block
->i_buffer
== sizeof (text
));
72 assert (!memcmp (block
->p_buffer
, text
, sizeof (text
)));
74 block
= block_Realloc (block
, 200, sizeof (text
) + 200);
75 assert (block
!= NULL
);
76 assert (block
->i_buffer
== 200 + sizeof (text
) + 200);
77 assert (!memcmp (block
->p_buffer
+ 200, text
, sizeof (text
)));
79 block
= block_Realloc (block
, -200, sizeof (text
) + 200);
80 assert (block
!= NULL
);
81 assert (block
->i_buffer
== sizeof (text
));
82 assert (!memcmp (block
->p_buffer
, text
, sizeof (text
)));
83 block_Release (block
);
85 //block = block_Alloc (SIZE_MAX);
86 //assert (block == NULL);
91 test_block_File(false);
92 test_block_File(true);