]> code.delx.au - pulseaudio/blob - src/tests/alsa-mixer-path-test.c
Whitespace cleanup: Remove all multiple newlines
[pulseaudio] / src / tests / alsa-mixer-path-test.c
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 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/";
20 else
21 return PA_ALSA_PATHS_DIR;
22 }
23
24 static pa_strlist *load_makefile() {
25 FILE *f;
26 bool lookforfiles = false;
27 char buf[2048];
28 pa_strlist *result = NULL;
29 const char *Makefile = PA_BUILDDIR "/Makefile";
30
31 f = pa_fopen_cloexec(Makefile, "r");
32 fail_unless(f != NULL); /* Consider skipping this test instead of failing if Makefile not found? */
33 while (!feof(f)) {
34 if (!fgets(buf, sizeof(buf), f)) {
35 fail_unless(feof(f));
36 break;
37 }
38 if (strstr(buf, "dist_alsapaths_DATA = \\") != NULL) {
39 lookforfiles = true;
40 continue;
41 }
42 if (!lookforfiles)
43 continue;
44 if (!strstr(buf, "\\"))
45 lookforfiles = false;
46 else
47 strstr(buf, "\\")[0] = '\0';
48 pa_strip(buf);
49 pa_log_debug("Shipping file '%s'", pa_path_get_filename(buf));
50 result = pa_strlist_prepend(result, pa_path_get_filename(buf));
51 }
52 fclose(f);
53 return result;
54 }
55
56 START_TEST (mixer_path_test) {
57 DIR *dir;
58 struct dirent *ent;
59 pa_strlist *ship = load_makefile();
60 const char *pathsdir = get_default_paths_dir();
61 pa_log_debug("Analyzing directory: '%s'", pathsdir);
62
63 dir = opendir(pathsdir);
64 fail_unless(dir != NULL);
65 while ((ent = readdir(dir)) != NULL) {
66 pa_alsa_path *path;
67 if (pa_streq(ent->d_name, ".") || pa_streq(ent->d_name, ".."))
68 continue;
69 pa_log_debug("Analyzing file: '%s'", ent->d_name);
70
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);
74
75 /* Is the file shipped? */
76 if (ship) {
77 pa_strlist *n;
78 bool found = false;
79 for (n = ship; n; n = pa_strlist_next(n))
80 found |= pa_streq(ent->d_name, pa_strlist_data(n));
81 fail_unless(found);
82 }
83 }
84 closedir(dir);
85 pa_strlist_free(ship);
86 }
87 END_TEST
88
89 int main(int argc, char *argv[]) {
90 int failed = 0;
91 Suite *s;
92 TCase *tc;
93 SRunner *sr;
94
95 if (!getenv("MAKE_CHECK"))
96 pa_log_set_level(PA_LOG_DEBUG);
97
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);
103
104 sr = srunner_create(s);
105 srunner_run_all(sr, CK_NORMAL);
106 failed = srunner_ntests_failed(sr);
107 srunner_free(sr);
108
109 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
110 }