Add _DEBUG/NDEBUG defines when DEBUG/NODEBUG options are used, respectively
[openal-soft.git] / RouterTest / main.cpp
blob961c3ecbc87813f5b3dc3e9b9d7bb1414959ab84
1 #include <al.h>
2 #include <alc.h>
3 #include <stdio.h>
4 #include <conio.h>
5 #include <string.h>
6 #include <windows.h>
7 #include <mmsystem.h>
9 int main(int argc, char* argv[])
11 const ALchar *szNames = NULL;
12 long lErrorCount = 0;
14 ///////////////////////////////////////////////////////////////////
15 // TEST : Enumerate the playback devices
17 printf("--------------------------------------\n");
18 printf("TESTING ALC_ENUMERATION_EXT EXTENSION\n\n");
19 if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE)
21 printf("ALC_ENUMERATION_EXT Device List:-\n\n");
23 szNames = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
24 if (strlen(szNames) == 0)
25 printf("NO DEVICES FOUND\n");
26 else
28 while (szNames && *szNames)
30 printf("%s ", szNames);
31 // Try opening each device
32 ALCdevice *pDevice = alcOpenDevice(szNames);
33 if (pDevice)
35 printf("- Opened Successfully\n");
36 alcCloseDevice(pDevice);
38 else
40 printf("- FAILED to open\n");
41 lErrorCount++;
43 szNames += (strlen(szNames) + 1);
47 else
49 printf("!!!ERROR!!! : ALC_ENUMERATION_EXT NOT FOUND!\n");
50 lErrorCount++;
52 printf("--------------------------------------\n\n");
53 ///////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////
57 // TEST : Get Default Playback Device
59 printf("--------------------------------------\n");
60 printf("TESTING GET DEFAULT PLAYBACK DEVICE\n\n");
61 szNames = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
62 if (szNames && strlen(szNames))
64 printf("\nDEFAULT DEVICE is %s\n", szNames);
66 else
68 if (waveOutGetNumDevs())
70 printf("\n!!!ERROR!!! DEFAULT DEVICE NOT FOUND!\n");
71 lErrorCount++;
73 else
75 printf("\nDEFAULT DEVICE NOT FOUND!\n");
78 printf("--------------------------------------\n\n");
79 ///////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////
83 // TEST : Enumerate all the capture devices
85 printf("--------------------------------------\n");
86 printf("TESTING CAPTURE ENUMERATION EXTENSION\n\n");
87 if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE)
89 printf("ALC_ENUMERATION_EXT Capture Device List:-\n\n");
91 szNames = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
92 if (strlen(szNames) == 0)
93 printf("NO DEVICES FOUND\n");
94 else
96 while (szNames && *szNames)
98 printf("%s ", szNames);
99 // Try opening each device
100 ALCdevice *pDevice = alcCaptureOpenDevice(szNames, 11025, AL_FORMAT_STEREO16, 8192);
101 if (pDevice)
103 printf("- Opened Successfully\n");
104 alcCaptureCloseDevice(pDevice);
106 else
108 printf("- FAILED to open\n");
109 lErrorCount++;
111 szNames += (strlen(szNames) + 1);
115 else
117 printf("!!!ERROR!!! : ALC_ENUMERATION_EXT NOT FOUND!\n");
118 lErrorCount++;
120 printf("--------------------------------------\n\n");
121 ///////////////////////////////////////////////////////////////////
124 ///////////////////////////////////////////////////////////////////
125 // TEST : Get Default Capture Device
127 printf("--------------------------------------\n");
128 printf("TESTING DEFAULT CAPTURE DEVICE\n\n");
129 szNames = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
130 if (szNames && strlen(szNames))
132 printf("\nDEFAULT CAPTURE DEVICE IS %s\n", szNames);
134 else
136 if (waveInGetNumDevs())
138 printf("\n!!!ERROR!!! DEFAULT CAPTURE DEVICE NOT FOUND!\n");
139 lErrorCount++;
141 else
143 printf("\nDEFAULT CAPTURE DEVICE NOT FOUND!\n");
146 printf("--------------------------------------\n\n");
147 ///////////////////////////////////////////////////////////////////
150 ///////////////////////////////////////////////////////////////////
151 // TEST : Enumerate *all* the playback devices
153 printf("--------------------------------------\n");
154 printf("TESTING PLAYBACK ENUMERATE ALL EXTENSION\n\n");
155 if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE)
157 printf("ALC_ENUMERATE_ALL_EXT DEVICE LIST:-\n\n");
159 szNames = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
160 if (strlen(szNames) == 0)
161 printf("NO DEVICES FOUND\n");
162 else
164 while (szNames && *szNames)
166 printf("%s ", szNames);
168 // Try opening each device
169 ALCdevice *pDevice = alcOpenDevice(szNames);
170 if (pDevice)
172 printf("- Opened Successfully\n");
173 alcCloseDevice(pDevice);
175 else
177 printf("- FAILED to open\n");
178 lErrorCount++;
181 szNames += (strlen(szNames) + 1);
185 else
187 printf("!!!ERROR!!! : ALC_ENUMERATE_ALL_EXT NOT FOUND!\n");
188 lErrorCount++;
190 printf("--------------------------------------\n\n");
191 ///////////////////////////////////////////////////////////////////
194 ///////////////////////////////////////////////////////////////////
195 // TEST : Get Default *All* Playback Device
197 printf("--------------------------------------\n");
198 printf("TESTING DEFAULT ALL PLAYBACK DEVICE\n\n");
199 szNames = alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
200 if (szNames && strlen(szNames))
202 printf("\nDEFAULT ALL DEVICES IS %s\n", szNames);
204 else
206 if (waveOutGetNumDevs())
208 printf("\n!!!ERROR!!! DEFAULT ALL DEVICE NOT FOUND!\n");
209 lErrorCount++;
211 else
213 printf("\nDEFAULT ALL DEVICES NOT FOUND!\n");
216 printf("--------------------------------------\n\n");
217 ///////////////////////////////////////////////////////////////////
220 ///////////////////////////////////////////////////////////////////
221 // TEST : Open 'Generic Hardware' device
223 printf("--------------------------------------\n");
224 printf("TESTING 'Generic Hardware' DEVICE\n\n");
225 ALCdevice *pDevice = alcOpenDevice("Generic Hardware");
226 if (pDevice)
228 printf("OPENED 'Generic Hardware' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
229 alcCloseDevice(pDevice);
231 else
233 if (waveOutGetNumDevs())
235 printf("!!!ERROR!!! : FAILED TO OPEN 'Generic Hardware' DEVICE\n");
236 lErrorCount++;
238 else
240 printf("FAILED TO OPEN 'Generic Hardware' DEVICE\n");
243 printf("--------------------------------------\n\n");
244 ///////////////////////////////////////////////////////////////////
247 ///////////////////////////////////////////////////////////////////
248 // TEST : Open 'Generic Software' device
250 printf("--------------------------------------\n");
251 printf("TESTING 'Generic Software' DEVICE\n\n");
252 pDevice = alcOpenDevice("Generic Software");
253 if (pDevice)
255 printf("OPENED 'Generic Software' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
256 alcCloseDevice(pDevice);
258 else
260 if (waveOutGetNumDevs())
262 printf("!!!ERROR!!! : FAILED TO OPEN 'Generic Software' DEVICE\n");
263 lErrorCount++;
265 else
267 printf("FAILED TO OPEN 'Generic Software' DEVICE\n");
270 printf("--------------------------------------\n\n");
271 ///////////////////////////////////////////////////////////////////
273 ///////////////////////////////////////////////////////////////////
274 // TEST : Open legacy 'DirectSound3D' device
276 printf("--------------------------------------\n");
277 printf("TESTING LEGACY 'DirectSound3D' DEVICE\n\n");
278 pDevice = alcOpenDevice("DirectSound3D");
279 if (pDevice)
281 printf("OPENED 'DirectSound3D' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
282 alcCloseDevice(pDevice);
284 else
286 if (waveOutGetNumDevs())
288 printf("!!!ERROR!!! : FAILED TO OPEN 'DirectSound3D' DEVICE\n");
289 lErrorCount++;
291 else
293 printf("FAILED TO OPEN 'DirectSound3D' DEVICE\n");
296 printf("--------------------------------------\n\n");
297 ///////////////////////////////////////////////////////////////////
300 ///////////////////////////////////////////////////////////////////
301 // TEST : Open legacy 'DirectSound' device
303 printf("--------------------------------------\n");
304 printf("TESTING LEGACY 'DirectSound' DEVICE\n\n");
305 pDevice = alcOpenDevice("DirectSound");
306 if (pDevice)
308 printf("OPENED 'DirectSound' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
309 alcCloseDevice(pDevice);
311 else
313 if (waveOutGetNumDevs())
315 printf("!!!ERROR!!! : FAILED TO OPEN 'DirectSound' DEVICE\n");
316 lErrorCount++;
318 else
320 printf("FAILED TO OPEN 'DirectSound' DEVICE\n");
323 printf("--------------------------------------\n\n");
324 ///////////////////////////////////////////////////////////////////
327 ///////////////////////////////////////////////////////////////////
328 // TEST : Open legacy 'MMSYSTEM' device
330 printf("--------------------------------------\n");
331 printf("TESTING LEGACY 'MMSYSTEM' DEVICE\n\n");
332 pDevice = alcOpenDevice("MMSYSTEM");
333 if (pDevice)
335 printf("OPENED 'MMSYSTEM' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
336 alcCloseDevice(pDevice);
338 else
340 if (waveOutGetNumDevs())
342 printf("!!!ERROR!!! : FAILED TO OPEN 'MMSYSTEM' DEVICE\n");
343 lErrorCount++;
345 else
347 printf("FAILED TO OPEN 'MMSYSTEM' DEVICE\n");
350 printf("--------------------------------------\n\n");
351 ///////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////
355 // TEST : Open NULL device
357 printf("--------------------------------------\n");
358 printf("TESTING NULL DEVICE\n\n");
359 pDevice = alcOpenDevice(NULL);
360 if (pDevice)
362 printf("OPENED NULL DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
363 alcCloseDevice(pDevice);
365 else
367 if (waveOutGetNumDevs())
369 printf("!!!ERROR!!! : FAILED TO OPEN NULL DEVICE\n");
370 lErrorCount++;
372 else
374 printf("FAILED TO OPEN NULL DEVICE\n");
377 printf("--------------------------------------\n\n");
378 ///////////////////////////////////////////////////////////////////
381 ///////////////////////////////////////////////////////////////////
382 // TEST : Open "" device
384 printf("--------------------------------------\n");
385 printf("TESTING EMPTY DEVICE\n\n");
386 pDevice = alcOpenDevice("");
387 if (pDevice)
389 printf("OPENED \"\" DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
390 alcCloseDevice(pDevice);
392 else
394 if (waveOutGetNumDevs())
396 printf("!!!ERROR!!! : FAILED TO OPEN EMPTY DEVICE\n");
397 lErrorCount++;
399 else
401 printf("FAILED TO OPEN EMPTY DEVICE\n");
404 printf("--------------------------------------\n\n");
405 ///////////////////////////////////////////////////////////////////
408 ///////////////////////////////////////////////////////////////////
409 // TEST : Open "A Random Name" device
411 printf("--------------------------------------\n");
412 printf("TESTING 'A Random Name' DEVICE\n\n");
413 pDevice = alcOpenDevice("A Random Name");
414 if (pDevice)
416 printf("!!!ERROR!!! : OPENED 'A Random Name' DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
417 lErrorCount++;
418 alcCloseDevice(pDevice);
420 else
422 printf("FAILED TO OPEN 'A Random Name' DEVICE\n");
424 printf("--------------------------------------\n\n");
425 ///////////////////////////////////////////////////////////////////
428 ///////////////////////////////////////////////////////////////////
429 // TEST : Open NULL Capture device
431 printf("--------------------------------------\n");
432 printf("TESTING NULL CAPTURE DEVICE\n\n");
433 pDevice = alcCaptureOpenDevice(NULL, 22500, AL_FORMAT_MONO16, 4096);
434 if (pDevice)
436 printf("OPENED NULL CAPTURE DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_CAPTURE_DEVICE_SPECIFIER));
437 alcCaptureCloseDevice(pDevice);
439 else
441 if (waveInGetNumDevs())
443 printf("!!!ERROR!!! : FAILED TO OPEN NULL CAPTURE DEVICE\n");
444 lErrorCount++;
446 else
448 printf("FAILED TO OPEN NULL CAPTURE DEVICE\n");
451 printf("--------------------------------------\n\n");
452 ///////////////////////////////////////////////////////////////////
455 ///////////////////////////////////////////////////////////////////
456 // TEST : Open "" capture device
458 printf("--------------------------------------\n");
459 printf("TESTING EMPTY CAPTURE DEVICE\n\n");
460 pDevice = alcCaptureOpenDevice("", 22500, AL_FORMAT_MONO16, 4096);
461 if (pDevice)
463 printf("OPENED \"\" CAPTURE DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_CAPTURE_DEVICE_SPECIFIER));
464 alcCaptureCloseDevice(pDevice);
466 else
468 if (waveInGetNumDevs())
470 printf("!!!ERROR!!! : FAILED TO OPEN EMPTY CAPTURE DEVICE\n");
471 lErrorCount++;
473 else
475 printf("FAILED TO OPEN EMPTY CAPTURE DEVICE\n");
478 printf("--------------------------------------\n\n");
479 ///////////////////////////////////////////////////////////////////
482 ///////////////////////////////////////////////////////////////////
483 // TEST : Open "A Random Name" capture device
485 printf("--------------------------------------\n");
486 printf("TESTING 'A Random Name' CAPTURE DEVICE\n\n");
487 pDevice = alcCaptureOpenDevice("A Random Name", 22500, AL_FORMAT_MONO16, 4096);
488 if (pDevice)
490 printf("!!!ERROR!!! : OPENED 'A Random Name' CAPTURE DEVICE ... GOT %s\n", alcGetString(pDevice, ALC_CAPTURE_DEVICE_SPECIFIER));
491 lErrorCount++;
492 alcCaptureCloseDevice(pDevice);
494 else
496 printf("FAILED TO OPEN 'A Random Name' CAPTURE DEVICE\n");
498 printf("--------------------------------------\n\n");
499 ///////////////////////////////////////////////////////////////////
501 printf("\nFOUND %d ERRORS\n", lErrorCount);
503 printf("\nPress a key to quit\n");
504 char ch = _getch();
506 return 0;
511 ALboolean InitOpenAL(ALCdevice **ppDevice, ALCcontext **ppContext)
513 ALchar szDeviceNames[10][1024];
514 ALchar *szNames;
515 ALint lNumDevices;
516 ALint lLoop;
517 ALint lLength;
518 ALbyte ch;
519 ALboolean bInit;
521 bInit = AL_FALSE;
522 memset(szDeviceNames, 0, sizeof(ALchar) * 10 * 1024);
523 lNumDevices = 0;
527 if (!szNames)
529 szNames = (char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
530 if (szNames && *szNames && (strlen(szNames) < 1024))
531 strcpy(szDeviceNames[lNumDevices++], szNames);
534 for (lLoop = 0; lLoop < lNumDevices; lLoop++)
535 printf("Press %d for '%s' Device\n", lLoop+1, szDeviceNames[lLoop]);
536 printf("Press Q to quit\n");
540 ch = _getch();
541 if (ch == 'q' || ch == 'Q')
542 exit(0);
543 else if ((ch >= '1') && (ch < ('1' + lNumDevices)))
544 break;
545 } while (1);
547 *ppDevice = alcOpenDevice(szDeviceNames[ch - '1']);
548 if (*ppDevice)
550 *ppContext = alcCreateContext(*ppDevice,NULL);
551 if (*ppContext)
553 alcGetError(*ppDevice);
554 alcMakeContextCurrent(*ppContext);
555 if (alcGetError(*ppDevice) == ALC_NO_ERROR)
556 bInit = AL_TRUE;
558 else
560 alcCloseDevice(*ppDevice);
564 return bInit;
568 ALboolean InitOpenALEx(ALCdevice **ppDevice, ALCcontext **ppContext)
570 ALchar szDeviceNames[32][1024];
571 const ALchar *szNames;
572 const ALchar *szDefaultName = NULL;
573 const ALchar *szDefaultAllName = NULL;
574 ALint lNumDevices = 0;
575 ALint lLoop;
576 ALint lLength;
577 ALbyte ch;
578 ALboolean bInit;
580 bInit = AL_FALSE;
581 memset(szDeviceNames, 0, sizeof(ALchar) * 32 * 1024);
583 // Get legacy enumeration list and Default Device
584 if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE)
586 szNames = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
588 while (szNames && *szNames)
590 if ((lLength = strlen(szNames)) < 1024)
591 strcpy(szDeviceNames[lNumDevices++], szNames);
592 szNames += lLength + 1;
595 szDefaultName = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
598 // Get new uber enumeration list and Default Device
599 if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE)
601 szNames = alcGetString(NULL, alcGetEnumValue(NULL, "ALC_ALL_DEVICES_SPECIFIER"));
603 while (szNames && *szNames)
605 if ((lLength = strlen(szNames)) < 1024)
606 strcpy(szDeviceNames[lNumDevices++], szNames);
607 szNames += lLength + 1;
610 szDefaultAllName = alcGetString(NULL, alcGetEnumValue(NULL, "ALC_DEFAULT_ALL_DEVICES_SPECIFIER"));
614 for (lLoop = 0; lLoop < lNumDevices; lLoop++)
615 printf("Press %d for '%s' Device %s\n", lLoop+1, szDeviceNames[lLoop],
616 (strcmp(szDeviceNames[lLoop], szDefaultName?szDefaultName:"") == 0) ? "*" : (strcmp(szDeviceNames[lLoop], szDefaultAllName?szDefaultAllName:"") == 0) ? "**" : "");
617 printf("Press Q to quit\n");
621 ch = _getch();
622 if (ch == 'q' || ch == 'Q')
623 exit(0);
624 else if ((ch >= '1') && (ch < ('1' + lNumDevices)))
625 break;
626 } while (1);
628 *ppDevice = alcOpenDevice(szDeviceNames[ch - '1']);
629 if (*ppDevice)
631 *ppContext = alcCreateContext(*ppDevice,NULL);
632 if (*ppContext)
634 alcGetError(*ppDevice);
635 alcMakeContextCurrent(*ppContext);
636 if (alcGetError(*ppDevice) == ALC_NO_ERROR)
637 bInit = AL_TRUE;
639 else
641 alcCloseDevice(*ppDevice);
645 return bInit;