"Fossies" - the Fresh Open Source Software Archive

Member "pulseaudio-13.0/src/tests/alsa-mixer-path-test.c" (13 Sep 2019, 3115 Bytes) of package /linux/misc/pulseaudio-13.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "alsa-mixer-path-test.c": 12.2_vs_13.0.

    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 #ifdef MESON_BUILD
   58     pa_log_info("Test disabled for meson build");
   59     return;
   60 #else
   61     DIR *dir;
   62     struct dirent *ent;
   63     pa_strlist *ship = load_makefile();
   64     const char *pathsdir = get_default_paths_dir();
   65     pa_log_debug("Analyzing directory: '%s'", pathsdir);
   66 
   67     dir = opendir(pathsdir);
   68     fail_unless(dir != NULL);
   69     while ((ent = readdir(dir)) != NULL) {
   70         pa_alsa_path *path;
   71         if (pa_streq(ent->d_name, ".") || pa_streq(ent->d_name, ".."))
   72             continue;
   73         pa_log_debug("Analyzing file: '%s'", ent->d_name);
   74 
   75         /* Can the file be parsed? */
   76         path = pa_alsa_path_new(pathsdir, ent->d_name, PA_ALSA_DIRECTION_ANY);
   77         fail_unless(path != NULL);
   78 
   79         /* Is the file shipped? */
   80         if (ship) {
   81             pa_strlist *n;
   82             bool found = false;
   83             for (n = ship; n; n = pa_strlist_next(n))
   84                 found |= pa_streq(ent->d_name, pa_strlist_data(n));
   85             fail_unless(found);
   86         }
   87     }
   88     closedir(dir);
   89     pa_strlist_free(ship);
   90 #endif
   91 }
   92 END_TEST
   93 
   94 int main(int argc, char *argv[]) {
   95     int failed = 0;
   96     Suite *s;
   97     TCase *tc;
   98     SRunner *sr;
   99 
  100     if (!getenv("MAKE_CHECK"))
  101         pa_log_set_level(PA_LOG_DEBUG);
  102 
  103     s = suite_create("Alsa-mixer-path");
  104     tc = tcase_create("alsa-mixer-path");
  105     tcase_add_test(tc, mixer_path_test);
  106     tcase_set_timeout(tc, 30);
  107     suite_add_tcase(s, tc);
  108 
  109     sr = srunner_create(s);
  110     srunner_run_all(sr, CK_NORMAL);
  111     failed = srunner_ntests_failed(sr);
  112     srunner_free(sr);
  113 
  114     return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  115 }