Merge branch 'libsndfile'
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / tests / win32_ordinal_test.c
1 /*
2 ** Copyright (C) 2006-2011 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 <sys/types.h>
36
37 #include "utils.h"
38
39 #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
40 #define TEST_WIN32 1
41 #else
42 #define TEST_WIN32 0
43 #endif
44
45 #if TEST_WIN32
46 #include <windows.h>
47
48
49 static const char * locations [] =
50 { ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
51 NULL
52 } ; /* locations. */
53
54 static int
55 test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
56 { char *lpmsg ;
57 void *name, *ord ;
58
59 print_test_name ("win32_ordinal_test", func_name) ;
60
61 #if SIZEOF_VOIDP == 8
62 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
63 #else
64 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
65 #endif
66
67 ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (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/libsndfile-1.def", locations [k]) ;
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/libsndfile-1.dll", locations [k]) ;
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 && WIN32_TARGET_DLL)
141 win32_ordinal_test () ;
142 #endif
143
144 return 0 ;
145 } /* main */
146