~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/libsndfile/tests/error_test.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3
 
**
4
 
** This program is free software; you can redistribute it and/or modify
5
 
** it under the terms of the GNU General Public License as published by
6
 
** the Free Software Foundation; either version 2 of the License, or
7
 
** (at your option) any later version.
8
 
**
9
 
** This program is distributed in the hope that it will be useful,
10
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
** GNU General Public License for more details.
13
 
**
14
 
** You should have received a copy of the GNU General Public License
15
 
** along with this program; if not, write to the Free Software
16
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
*/
18
 
 
19
 
#include "sfconfig.h"
20
 
 
21
 
#include <stdio.h>
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
 
25
 
#if HAVE_UNISTD_H
26
 
#include <unistd.h>
27
 
#endif
28
 
 
29
 
#include <sndfile.h>
30
 
 
31
 
#include "utils.h"
32
 
 
33
 
#define BUFFER_SIZE             (1<<15)
34
 
#define SHORT_BUFFER    (256)
35
 
 
36
 
static void error_number_test (void) ;
37
 
static void error_value_test (void) ;
38
 
 
39
 
int
40
 
main (void)
41
 
{       error_number_test () ;
42
 
        error_value_test () ;
43
 
 
44
 
        return 0 ;
45
 
} /* main */
46
 
 
47
 
static void
48
 
error_number_test (void)
49
 
{       const char      *noerror, *errstr ;
50
 
        int                     k ;
51
 
 
52
 
        print_test_name ("error_number_test", "") ;
53
 
 
54
 
        noerror = sf_error_number (0) ;
55
 
 
56
 
        for (k = 1 ; k < 300 ; k++)
57
 
        {       errstr = sf_error_number (k) ;
58
 
 
59
 
                /* Test for termination condition. */
60
 
                if (errstr == noerror)
61
 
                        break ;
62
 
 
63
 
                /* Test for error. */
64
 
                if (strstr (errstr, "This is a bug in libsndfile."))
65
 
                        exit (1) ;
66
 
                } ;
67
 
 
68
 
 
69
 
        puts ("ok") ;
70
 
        return ;
71
 
} /* error_number_test */
72
 
 
73
 
static void
74
 
error_value_test (void)
75
 
{       static unsigned char aiff_data [0x1b0] =
76
 
        {       'F' , 'O' , 'R' , 'M' ,
77
 
                0x00, 0x00, 0x01, 0xA8, /* FORM length */
78
 
 
79
 
                'A' , 'I' , 'F' , 'C' ,
80
 
                } ;
81
 
 
82
 
        const char *filename = "error.aiff" ;
83
 
        SNDFILE *file ;
84
 
        SF_INFO sfinfo ;
85
 
        int error_num ;
86
 
 
87
 
        print_test_name ("error_value_test", filename) ;
88
 
 
89
 
        dump_data_to_file (filename, aiff_data, sizeof (aiff_data)) ;
90
 
 
91
 
        file = sf_open (filename, SFM_READ, &sfinfo) ;
92
 
        if (file != NULL)
93
 
        {       printf ("\n\nLine %d : Should not have been able to open this file.\n\n", __LINE__) ;
94
 
                exit (1) ;
95
 
                } ;
96
 
 
97
 
        if ((error_num = sf_error (NULL)) <= 1 || error_num > 300)
98
 
        {       printf ("\n\nLine %d : Should not have had an error number of %d.\n\n", __LINE__, error_num) ;
99
 
                exit (1) ;
100
 
                } ;
101
 
 
102
 
        remove (filename) ;
103
 
        puts ("ok") ;
104
 
        return ;
105
 
} /* error_value_test */
106
 
 
107
 
/*
108
 
** Do not edit or modify anything in this comment block.
109
 
** The arch-tag line is a file identity tag for the GNU Arch 
110
 
** revision control system.
111
 
**
112
 
** arch-tag: 799eba74-b505-49d9-89a6-22a7f51a31b4
113
 
*/