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));
57 START_TEST (mixer_path_test) {
60 pa_strlist *ship = load_makefile();
61 const char *pathsdir = get_default_paths_dir();
62 pa_log_debug("Analyzing directory: '%s'", pathsdir);
64 dir = opendir(pathsdir);
65 fail_unless(dir != NULL);
66 while ((ent = readdir(dir)) != NULL) {
68 if (pa_streq(ent->d_name, ".") || pa_streq(ent->d_name, ".."))
70 pa_log_debug("Analyzing file: '%s'", ent->d_name);
72 /* Can the file be parsed? */
73 path = pa_alsa_path_new(pathsdir, ent->d_name, PA_ALSA_DIRECTION_ANY);
74 fail_unless(path != NULL);
76 /* Is the file shipped? */
80 for (n = ship; n; n = pa_strlist_next(n))
81 found |= pa_streq(ent->d_name, pa_strlist_data(n));
86 pa_strlist_free(ship);
90 int main(int argc, char *argv[]) {
96 if (!getenv("MAKE_CHECK"))
97 pa_log_set_level(PA_LOG_DEBUG);
99 s = suite_create("Alsa-mixer-path");
100 tc = tcase_create("alsa-mixer-path");
101 tcase_add_test(tc, mixer_path_test);
102 tcase_set_timeout(tc, 30);
103 suite_add_tcase(s, tc);
105 sr = srunner_create(s);
106 srunner_run_all(sr, CK_NORMAL);
107 failed = srunner_ntests_failed(sr);
110 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;