summaryrefslogtreecommitdiff
path: root/tests/external_libs_test.c
blob: 86b029078e588a4f8e0fe5b3ed0963105f262bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software ; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation ; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program ; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "sfconfig.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <sndfile.h>

#include "utils.h"

static void major_format_test (void) ;
static void subtype_format_test (void) ;
static void simple_format_test (void) ;

int
main (void)
{
	major_format_test () ;
	subtype_format_test () ;
	simple_format_test () ;

	return 0 ;
} /* main */

static void
major_format_test (void)
{	SF_FORMAT_INFO	info ;
	int have_ogg = 0, have_flac = 0 ;
	int m, major_count ;

	print_test_name (__func__, NULL) ;

	sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;

	for (m = 0 ; m < major_count ; m++)
	{	info.format = m ;
		sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;

		have_flac = info.format == SF_FORMAT_FLAC ? 1 : have_flac ;
		have_ogg = info.format == SF_FORMAT_OGG ? 1 : have_ogg ;
		} ;

	if (HAVE_EXTERNAL_LIBS)
	{	exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
		exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
		}
	else
	{	exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
		exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
		} ;

	puts ("ok") ;
} /* major_format_test */

static void
subtype_format_test (void)
{	SF_FORMAT_INFO	info ;
	int have_vorbis = 0 ;
	int s, subtype_count ;

	print_test_name (__func__, NULL) ;

	sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;

	for (s = 0 ; s < subtype_count ; s++)
	{	info.format = s ;
		sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ;

		have_vorbis = info.format == SF_FORMAT_VORBIS ? 1 : have_vorbis ;
		} ;

	if (HAVE_EXTERNAL_LIBS)
		exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
	else
		exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;

	puts ("ok") ;
} /* subtype_format_test */

static void
simple_format_test (void)
{	SF_FORMAT_INFO	info ;
	int have_flac = 0, have_ogg = 0, have_vorbis = 0 ;
	int s, simple_count ;

	print_test_name (__func__, NULL) ;

	sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &simple_count, sizeof (int)) ;

	for (s = 0 ; s < simple_count ; s++)
	{	info.format = s ;
		sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &info, sizeof (info)) ;

		switch (info.format & SF_FORMAT_TYPEMASK)
		{	case SF_FORMAT_FLAC :
				have_flac = 1 ;
				break ;

			case SF_FORMAT_OGG :
				have_ogg = 1 ;
				break ;

			default :
				break ;
			} ;

		switch (info.format & SF_FORMAT_SUBMASK)
		{	case SF_FORMAT_VORBIS :
				have_vorbis = 1 ;
				break ;

			default :
				break ;
			} ;

		} ;

	if (HAVE_EXTERNAL_LIBS)
	{	exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
		exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
		exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
		}
	else
	{	exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
		exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
		exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
		} ;

	puts ("ok") ;
} /* simple_format_test */