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