1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <check.h>
6 #include <dirent.h>
7 #include <stdbool.h>
8 #include <stdio.h>
9
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>
15
16 /* This test inspects the Makefile, so this is not applicable when using
17 * Meson. */
18 #ifndef MESON_BUILD
19
20 /* This function was copied from alsa-mixer.c */
get_default_paths_dir(void)21 static const char *get_default_paths_dir(void) {
22 if (pa_run_from_build_tree())
23 return PA_SRCDIR "/modules/alsa/mixer/paths/";
24 else
25 return PA_ALSA_PATHS_DIR;
26 }
27
load_makefile()28 static pa_strlist *load_makefile() {
29 FILE *f;
30 bool lookforfiles = false;
31 char buf[2048];
32 pa_strlist *result = NULL;
33 const char *Makefile = PA_BUILDDIR "/Makefile";
34
35 f = pa_fopen_cloexec(Makefile, "r");
36 fail_unless(f != NULL); /* Consider skipping this test instead of failing if Makefile not found? */
37 while (!feof(f)) {
38 if (!fgets(buf, sizeof(buf), f)) {
39 fail_unless(feof(f));
40 break;
41 }
42 if (strstr(buf, "dist_alsapaths_DATA = \\") != NULL) {
43 lookforfiles = true;
44 continue;
45 }
46 if (!lookforfiles)
47 continue;
48 if (!strstr(buf, "\\"))
49 lookforfiles = false;
50 else
51 strstr(buf, "\\")[0] = '\0';
52 pa_strip(buf);
53 pa_log_debug("Shipping file '%s'", pa_path_get_filename(buf));
54 result = pa_strlist_prepend(result, pa_path_get_filename(buf));
55 }
56 fclose(f);
57 return result;
58 }
59 #endif /* end of #ifndef MESON_BUILD */
60
START_TEST(mixer_path_test)61 START_TEST (mixer_path_test) {
62 #ifdef MESON_BUILD
63 pa_log_info("Test disabled for meson build");
64 return;
65 #else
66 DIR *dir;
67 struct dirent *ent;
68 pa_strlist *ship = load_makefile();
69 const char *pathsdir = get_default_paths_dir();
70 pa_log_debug("Analyzing directory: '%s'", pathsdir);
71
72 dir = opendir(pathsdir);
73 fail_unless(dir != NULL);
74 while ((ent = readdir(dir)) != NULL) {
75 pa_alsa_path *path;
76 if (pa_streq(ent->d_name, ".") || pa_streq(ent->d_name, ".."))
77 continue;
78 pa_log_debug("Analyzing file: '%s'", ent->d_name);
79
80 /* Can the file be parsed? */
81 path = pa_alsa_path_new(pathsdir, ent->d_name, PA_ALSA_DIRECTION_ANY);
82 fail_unless(path != NULL);
83
84 /* Is the file shipped? */
85 if (ship) {
86 pa_strlist *n;
87 bool found = false;
88 for (n = ship; n; n = pa_strlist_next(n))
89 found |= pa_streq(ent->d_name, pa_strlist_data(n));
90 fail_unless(found);
91 }
92 }
93 closedir(dir);
94 pa_strlist_free(ship);
95 #endif
96 }
97 END_TEST
98
main(int argc,char * argv[])99 int main(int argc, char *argv[]) {
100 int failed = 0;
101 Suite *s;
102 TCase *tc;
103 SRunner *sr;
104
105 if (!getenv("MAKE_CHECK"))
106 pa_log_set_level(PA_LOG_DEBUG);
107
108 s = suite_create("Alsa-mixer-path");
109 tc = tcase_create("alsa-mixer-path");
110 tcase_add_test(tc, mixer_path_test);
111 tcase_set_timeout(tc, 30);
112 suite_add_tcase(s, tc);
113
114 sr = srunner_create(s);
115 srunner_run_all(sr, CK_NORMAL);
116 failed = srunner_ntests_failed(sr);
117 srunner_free(sr);
118
119 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
120 }
121