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

« back to all changes in this revision

Viewing changes to lib-src/libsndfile/tests/win32_ordinal_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) 2006 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
 
#include "sndfile.h"
21
 
 
22
 
#include <stdio.h>
23
 
#include <stdlib.h>
24
 
 
25
 
#if HAVE_UNISTD_H
26
 
#include <unistd.h>
27
 
#endif
28
 
 
29
 
#if (HAVE_DECL_S_IRGRP == 0)
30
 
#include <sf_unistd.h>
31
 
#endif
32
 
 
33
 
#include <string.h>
34
 
#include <fcntl.h>
35
 
#include <errno.h>
36
 
#include <sys/types.h>
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
41
 
#define TEST_WIN32              1
42
 
#else
43
 
#define TEST_WIN32              0
44
 
#endif
45
 
 
46
 
#if TEST_WIN32
47
 
#include <windows.h>
48
 
 
49
 
#ifdef __CYGWIN__
50
 
#define DLL_NAME        "cygsndfile"
51
 
#else
52
 
#define DLL_NAME        "libsndfile"
53
 
#endif
54
 
 
55
 
static const char * locations [] =
56
 
{       "../src/", "src/", "../src/.libs/", "src/.libs/",
57
 
        NULL
58
 
} ; /* locations. */
59
 
 
60
 
static int
61
 
test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
62
 
{       char *lpmsg ;
63
 
        void *name, *ord ;
64
 
 
65
 
        print_test_name ("win32_ordinal_test", func_name) ;
66
 
 
67
 
        ord = GetProcAddress (hmod, (LPSTR) ordinal) ;
68
 
        if ((name = GetProcAddress (hmod, func_name)) == NULL)
69
 
        {       FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
70
 
                                        MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
71
 
                /*-puts (lpmsg) ;-*/
72
 
                } ;
73
 
 
74
 
        if (name != NULL && ord != NULL && name == ord)
75
 
        {       puts ("ok") ;
76
 
                return 0 ;
77
 
                } ;
78
 
 
79
 
        puts ("fail") ;
80
 
        return 1 ;
81
 
} /* test_ordinal */
82
 
 
83
 
static void
84
 
win32_ordinal_test (void)
85
 
{       static char buffer [1024] ;
86
 
        static char func_name [1024] ;
87
 
        HMODULE hmod = NULL ;
88
 
        FILE * file = NULL ;
89
 
        int k, ordinal, errors = 0 ;
90
 
 
91
 
        for (k = 0 ; locations [k] != NULL ; k++)
92
 
        {       snprintf (buffer, sizeof (buffer), "%s/%s.def", locations [k], DLL_NAME) ;
93
 
                if ((file = fopen (buffer, "r")) != NULL)
94
 
                        break ;
95
 
                } ;
96
 
 
97
 
        if (file == NULL)
98
 
        {       puts ("\n\nError : cannot open DEF file.\n") ;
99
 
                exit (1) ;
100
 
                } ;
101
 
 
102
 
        for (k = 0 ; locations [k] != NULL ; k++)
103
 
        {       snprintf (buffer, sizeof (buffer), "%s/%s-1.dll", locations [k], DLL_NAME) ;
104
 
                if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
105
 
                        break ;
106
 
                } ;
107
 
 
108
 
        if (hmod == NULL)
109
 
        {       puts ("\n\nError : cannot load DLL.\n") ;
110
 
                exit (1) ;
111
 
                } ;
112
 
 
113
 
        while (fgets (buffer, sizeof (buffer), file) != NULL)
114
 
        {       func_name [0] = 0 ;
115
 
                ordinal = 0 ;
116
 
 
117
 
                if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
118
 
                        continue ;
119
 
 
120
 
                errors += test_ordinal (hmod, func_name, ordinal) ;
121
 
                } ;
122
 
 
123
 
        FreeLibrary (hmod) ;
124
 
 
125
 
        fclose (file) ;
126
 
 
127
 
        if (errors > 0)
128
 
        {       printf ("\n\nErrors : %d\n\n", errors) ;
129
 
                exit (1) ;
130
 
                } ;
131
 
 
132
 
        return ;
133
 
} /* win32_ordinal_test */
134
 
 
135
 
#endif
136
 
 
137
 
int
138
 
main (void)
139
 
{
140
 
#if TEST_WIN32
141
 
        win32_ordinal_test () ;
142
 
#endif
143
 
 
144
 
        return 0 ;
145
 
} /* main */
146
 
 
147
 
 
148
 
/*
149
 
** Do not edit or modify anything in this comment block.
150
 
** The arch-tag line is a file identity tag for the GNU Arch
151
 
** revision control system.
152
 
**
153
 
** arch-tag: 708f6815-e787-4143-bb99-f32c1bb5564e
154
 
*/