~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjlib/src/pjlib-test/fifobuf.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: fifobuf.c 3553 2011-05-05 06:14:19Z nanang $ */
2
 
/*
3
 
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
 
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 */
20
 
#include "test.h"
21
 
 
22
 
/* To prevent warning about "translation unit is empty"
23
 
 * when this test is disabled.
24
 
 */
25
 
int dummy_fifobuf_test;
26
 
 
27
 
#if INCLUDE_FIFOBUF_TEST
28
 
 
29
 
#include <pjlib.h>
30
 
 
31
 
int fifobuf_test()
32
 
{
33
 
    enum { SIZE = 1024, MAX_ENTRIES = 128,
34
 
           MIN_SIZE = 4, MAX_SIZE = 64,
35
 
           LOOP=10000 };
36
 
    pj_pool_t *pool;
37
 
    pj_fifobuf_t fifo;
38
 
    unsigned available = SIZE;
39
 
    void *entries[MAX_ENTRIES];
40
 
    void *buffer;
41
 
    int i;
42
 
 
43
 
    pool = pj_pool_create(mem, NULL, SIZE+256, 0, NULL);
44
 
    if (!pool)
45
 
        return -10;
46
 
 
47
 
    buffer = pj_pool_alloc(pool, SIZE);
48
 
    if (!buffer)
49
 
        return -20;
50
 
 
51
 
    pj_fifobuf_init (&fifo, buffer, SIZE);
52
 
 
53
 
    // Test 1
54
 
    for (i=0; i<LOOP*MAX_ENTRIES; ++i) {
55
 
        int size;
56
 
        int c, f;
57
 
        c = i%2;
58
 
        f = (i+1)%2;
59
 
        do {
60
 
            size = MIN_SIZE+(pj_rand() % MAX_SIZE);
61
 
            entries[c] = pj_fifobuf_alloc (&fifo, size);
62
 
        } while (entries[c] == 0);
63
 
        if ( i!=0) {
64
 
            pj_fifobuf_free(&fifo, entries[f]);
65
 
        }
66
 
    }
67
 
    if (entries[(i+1)%2])
68
 
        pj_fifobuf_free(&fifo, entries[(i+1)%2]);
69
 
 
70
 
    if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
71
 
        pj_assert(0);
72
 
        return -1;
73
 
    }
74
 
 
75
 
    // Test 2
76
 
    entries[0] = pj_fifobuf_alloc (&fifo, MIN_SIZE);
77
 
    if (!entries[0]) return -1;
78
 
    for (i=0; i<LOOP*MAX_ENTRIES; ++i) {
79
 
        int size = MIN_SIZE+(pj_rand() % MAX_SIZE);
80
 
        entries[1] = pj_fifobuf_alloc (&fifo, size);
81
 
        if (entries[1])
82
 
            pj_fifobuf_unalloc(&fifo, entries[1]);
83
 
    }
84
 
    pj_fifobuf_unalloc(&fifo, entries[0]);
85
 
    if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
86
 
        pj_assert(0);
87
 
        return -2;
88
 
    }
89
 
 
90
 
    // Test 3
91
 
    for (i=0; i<LOOP; ++i) {
92
 
        int count, j;
93
 
        for (count=0; available>=MIN_SIZE+4 && count < MAX_ENTRIES;) {
94
 
            int size = MIN_SIZE+(pj_rand() % MAX_SIZE);
95
 
            entries[count] = pj_fifobuf_alloc (&fifo, size);
96
 
            if (entries[count]) {
97
 
                available -= (size+4);
98
 
                ++count;
99
 
            }
100
 
        }
101
 
        for (j=0; j<count; ++j) {
102
 
            pj_fifobuf_free (&fifo, entries[j]);
103
 
        }
104
 
        available = SIZE;
105
 
    }
106
 
 
107
 
    if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
108
 
        pj_assert(0);
109
 
        return -3;
110
 
    }
111
 
    pj_pool_release(pool);
112
 
    return 0;
113
 
}
114
 
 
115
 
#endif  /* INCLUDE_FIFOBUF_TEST */