2
0

win32_ordinal_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #if HAVE_UNISTD_H
  22. #include <unistd.h>
  23. #endif
  24. #if (HAVE_DECL_S_IRGRP == 0)
  25. #include <sf_unistd.h>
  26. #endif
  27. #include <string.h>
  28. #include <fcntl.h>
  29. #include <sys/types.h>
  30. #include "utils.h"
  31. #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
  32. #define TEST_WIN32 1
  33. #else
  34. #define TEST_WIN32 0
  35. #endif
  36. #if TEST_WIN32
  37. #include <windows.h>
  38. static const char * locations [] =
  39. { ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
  40. NULL
  41. } ; /* locations. */
  42. static int
  43. test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
  44. { char *lpmsg ;
  45. void *name, *ord ;
  46. print_test_name ("win32_ordinal_test", func_name) ;
  47. #if SIZEOF_VOIDP == 8
  48. #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
  49. #else
  50. #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
  51. #endif
  52. ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ;
  53. if ((name = GetProcAddress (hmod, func_name)) == NULL)
  54. { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
  55. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
  56. /*-puts (lpmsg) ;-*/
  57. } ;
  58. if (name != NULL && ord != NULL && name == ord)
  59. { puts ("ok") ;
  60. return 0 ;
  61. } ;
  62. puts ("fail") ;
  63. return 1 ;
  64. } /* test_ordinal */
  65. static void
  66. win32_ordinal_test (void)
  67. { static char buffer [1024] ;
  68. static char func_name [1024] ;
  69. HMODULE hmod = NULL ;
  70. FILE * file = NULL ;
  71. int k, ordinal, errors = 0 ;
  72. for (k = 0 ; locations [k] != NULL ; k++)
  73. { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ;
  74. if ((file = fopen (buffer, "r")) != NULL)
  75. break ;
  76. } ;
  77. if (file == NULL)
  78. { puts ("\n\nError : cannot open DEF file.\n") ;
  79. exit (1) ;
  80. } ;
  81. for (k = 0 ; locations [k] != NULL ; k++)
  82. { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ;
  83. if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
  84. break ;
  85. } ;
  86. if (hmod == NULL)
  87. { puts ("\n\nError : cannot load DLL.\n") ;
  88. exit (1) ;
  89. } ;
  90. while (fgets (buffer, sizeof (buffer), file) != NULL)
  91. { func_name [0] = 0 ;
  92. ordinal = 0 ;
  93. if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
  94. continue ;
  95. errors += test_ordinal (hmod, func_name, ordinal) ;
  96. } ;
  97. FreeLibrary (hmod) ;
  98. fclose (file) ;
  99. if (errors > 0)
  100. { printf ("\n\nErrors : %d\n\n", errors) ;
  101. exit (1) ;
  102. } ;
  103. return ;
  104. } /* win32_ordinal_test */
  105. #endif
  106. int
  107. main (void)
  108. {
  109. #if (TEST_WIN32 && WIN32_TARGET_DLL)
  110. win32_ordinal_test () ;
  111. #endif
  112. return 0 ;
  113. } /* main */