]>
code.delx.au - pulseaudio/blob - src/tests/alsa-mixer-path-test.c
10 #include <pulse/pulseaudio.h>
11 #include <pulsecore/log.h>
12 #include <pulsecore/core-util.h>
13 #include <pulsecore/strlist.h>
14 #include <modules/alsa/alsa-mixer.h>
16 /* This function was copied from alsa-mixer.c */
17 static const char *get_default_paths_dir(void) {
18 if (pa_run_from_build_tree())
19 return PA_SRCDIR
"/modules/alsa/mixer/paths/";
21 return PA_ALSA_PATHS_DIR
;
24 static pa_strlist
*load_makefile() {
26 bool lookforfiles
= false;
28 pa_strlist
*result
= NULL
;
29 const char *Makefile
= PA_BUILDDIR
"/Makefile";
31 f
= pa_fopen_cloexec(Makefile
, "r");
32 fail_unless(f
!= NULL
); /* Consider skipping this test instead of failing if Makefile not found? */
34 if (!fgets(buf
, sizeof(buf
), f
)) {
38 if (strstr(buf
, "dist_alsapaths_DATA = \\") != NULL
) {
44 if (!strstr(buf
, "\\"))
47 strstr(buf
, "\\")[0] = '\0';
49 pa_log_debug("Shipping file '%s'", pa_path_get_filename(buf
));
50 result
= pa_strlist_prepend(result
, pa_path_get_filename(buf
));
56 START_TEST (mixer_path_test
) {
59 pa_strlist
*ship
= load_makefile();
60 const char *pathsdir
= get_default_paths_dir();
61 pa_log_debug("Analyzing directory: '%s'", pathsdir
);
63 dir
= opendir(pathsdir
);
64 fail_unless(dir
!= NULL
);
65 while ((ent
= readdir(dir
)) != NULL
) {
67 if (pa_streq(ent
->d_name
, ".") || pa_streq(ent
->d_name
, ".."))
69 pa_log_debug("Analyzing file: '%s'", ent
->d_name
);
71 /* Can the file be parsed? */
72 path
= pa_alsa_path_new(pathsdir
, ent
->d_name
, PA_ALSA_DIRECTION_ANY
);
73 fail_unless(path
!= NULL
);
75 /* Is the file shipped? */
79 for (n
= ship
; n
; n
= pa_strlist_next(n
))
80 found
|= pa_streq(ent
->d_name
, pa_strlist_data(n
));
85 pa_strlist_free(ship
);
89 int main(int argc
, char *argv
[]) {
95 if (!getenv("MAKE_CHECK"))
96 pa_log_set_level(PA_LOG_DEBUG
);
98 s
= suite_create("Alsa-mixer-path");
99 tc
= tcase_create("alsa-mixer-path");
100 tcase_add_test(tc
, mixer_path_test
);
101 tcase_set_timeout(tc
, 30);
102 suite_add_tcase(s
, tc
);
104 sr
= srunner_create(s
);
105 srunner_run_all(sr
, CK_NORMAL
);
106 failed
= srunner_ntests_failed(sr
);
109 return (failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;