summaryrefslogtreecommitdiffstats
path: root/debian/transcode/transcode-1.1.7/testsuite/test-bufalloc.c
blob: 437429f3e6867abefe9ec599a62b17516c7fba12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * test-bufalloc.c -- testsuite for tc_*bufalloc* family (tc_functions.c)
 *                    everyone feel free to add more tests and improve
 *                    existing ones.
 * (C) 2006-2010 - Francesco Romani <fromani -at- gmail -dot- com>
 *
 * This file is part of transcode, a video stream processing tool.
 *
 * transcode is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * transcode 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <stdio.h>
#include <stdlib.h>

#include "config.h"
#include "libtc/libtc.h"

#ifndef PACKAGE
#define PACKAGE __FILE__
#endif

#define MY_PAGE_SZ  (4096)
#define HOW_MUCH    (144000)
#define BIG_SIZE    (64*1024*1024)

static int test_alloc(int size)
{
    int ret = 0;
    uint8_t *mem = tc_bufalloc(size);

    if (mem == NULL) {
        tc_error("test_alloc(%i): FAILED (mem == NULL)", size);
        ret = 1;
    } else {
        tc_info("test_alloc(%i): PASSED", size);
        ret = 1;
    }
    tc_buffree(mem);
    return ret;
}

static int test_alloc_memset(int size)
{
    int ret = 0;
    uint8_t *mem = tc_bufalloc(size);

    if (mem == NULL) {
        tc_error("test_alloc_memset(%i): FAILED (mem == NULL)", size);
        ret = 1;
    } else {
        memset(mem, 0, size);
        tc_info("test_alloc_memset(%i): PASSED", size);
        ret = 1;
    }
    tc_buffree(mem);
    return ret;
}

int main(void)
{
    test_alloc(0);
    test_alloc(1);
    test_alloc(MY_PAGE_SZ);
    test_alloc(MY_PAGE_SZ-1);
    test_alloc(MY_PAGE_SZ+1);
    test_alloc(HOW_MUCH);
    test_alloc(HOW_MUCH-1);
    test_alloc(HOW_MUCH+1);
    test_alloc(BIG_SIZE);
    test_alloc(BIG_SIZE-1);
    test_alloc(BIG_SIZE+1);
    
    test_alloc_memset(0);
    test_alloc_memset(1);
    test_alloc_memset(MY_PAGE_SZ);
    test_alloc_memset(MY_PAGE_SZ-1);
    test_alloc_memset(MY_PAGE_SZ+1);
    test_alloc_memset(HOW_MUCH);
    test_alloc_memset(HOW_MUCH-1);
    test_alloc_memset(HOW_MUCH+1);
    test_alloc_memset(BIG_SIZE);
    test_alloc_memset(BIG_SIZE-1);
    test_alloc_memset(BIG_SIZE+1);

    return 0;
}

/*************************************************************************/

/*
 * Local variables:
 *   c-file-style: "stroustrup"
 *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
 *   indent-tabs-mode: nil
 * End:
 *
 * vim: expandtab shiftwidth=4:
 */