"Fossies" - the Fresh Open Source Software Archive

Member "vnstat-2.9/tests/fs_tests.c" (26 Jul 2021, 4108 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:


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 last Fossies "Diffs" side-by-side code changes report for "fs_tests.c": 2.7_vs_2.8.

    1 #include "common.h"
    2 #include "vnstat_tests.h"
    3 #include "fs_tests.h"
    4 #include "cfg.h"
    5 #include "fs.h"
    6 
    7 START_TEST(fileexists_with_no_file)
    8 {
    9     char testfile[512];
   10 
   11     snprintf(testfile, 512, "%s/no_file", TESTDIR);
   12     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   13     ck_assert_int_eq(fileexists(""), 0);
   14     ck_assert_int_eq(fileexists(testfile), 0);
   15 }
   16 END_TEST
   17 
   18 START_TEST(fileexists_with_file)
   19 {
   20     char testfile[512];
   21 
   22     snprintf(testfile, 512, "%s/dummy_file", TESTDBDIR);
   23     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   24     ck_assert_int_eq(clean_testdbdir(), 1);
   25     ck_assert_int_eq(create_zerosize_dbfile("dummy_file"), 1);
   26     ck_assert_int_eq(fileexists(testfile), 1);
   27 }
   28 END_TEST
   29 
   30 START_TEST(direxists_with_no_dir)
   31 {
   32     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   33     ck_assert_int_eq(direxists(""), 0);
   34     ck_assert_int_eq(direxists(TESTDIR), 0);
   35 }
   36 END_TEST
   37 
   38 START_TEST(direxists_with_dir)
   39 {
   40     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   41     ck_assert_int_eq(clean_testdbdir(), 1);
   42     ck_assert_int_eq(direxists(TESTDIR), 1);
   43     ck_assert_int_eq(direxists(TESTDBDIR), 1);
   44 }
   45 END_TEST
   46 
   47 START_TEST(mkpath_with_no_dir)
   48 {
   49     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   50     ck_assert_int_eq(mkpath("", 0775), 0);
   51 }
   52 END_TEST
   53 
   54 START_TEST(mkpath_with_dir)
   55 {
   56     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   57     ck_assert_int_eq(direxists(TESTDIR), 0);
   58     ck_assert_int_eq(direxists(TESTDBDIR), 0);
   59     ck_assert_int_eq(mkpath(TESTDIR, 0775), 1);
   60     ck_assert_int_eq(direxists(TESTDIR), 1);
   61     ck_assert_int_eq(direxists(TESTDBDIR), 0);
   62     ck_assert_int_eq(mkpath(TESTDBDIR, 0775), 1);
   63     ck_assert_int_eq(direxists(TESTDBDIR), 1);
   64     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   65     ck_assert_int_eq(direxists(TESTDBDIR), 0);
   66     ck_assert_int_eq(mkpath(TESTDBDIR, 0775), 1);
   67     ck_assert_int_eq(direxists(TESTDBDIR), 1);
   68 }
   69 END_TEST
   70 
   71 START_TEST(preparevnstatdir_with_no_vnstat)
   72 {
   73     char testdir[512], testpath[530];
   74     cfg.updatefileowner = 0;
   75 
   76     ck_assert_int_eq(remove_directory(TESTDIR), 1);
   77     ck_assert_int_eq(direxists(TESTDIR), 0);
   78     snprintf(testdir, 512, "%s/here/be/dragons", TESTDIR);
   79     snprintf(testpath, 530, "%s/or_something.txt", testdir);
   80     preparevnstatdir(testpath, "user", "group");
   81     ck_assert_int_eq(direxists(TESTDIR), 0);
   82     ck_assert_int_eq(direxists(testdir), 0);
   83 
   84     snprintf(testdir, 512, "%s/here/be/vnstat/dragons", TESTDIR);
   85     snprintf(testpath, 530, "%s/or_something.txt", testdir);
   86     preparevnstatdir(testpath, "user", "group");
   87     ck_assert_int_eq(direxists(TESTDIR), 0);
   88     ck_assert_int_eq(direxists(testdir), 0);
   89 
   90     snprintf(testdir, 512, "%s/here/be/vnstati", TESTDIR);
   91     snprintf(testpath, 530, "%s/or_something.txt", testdir);
   92     preparevnstatdir(testpath, "user", "group");
   93     ck_assert_int_eq(direxists(TESTDIR), 0);
   94     ck_assert_int_eq(direxists(testdir), 0);
   95 }
   96 END_TEST
   97 
   98 START_TEST(preparevnstatdir_with_vnstat)
   99 {
  100     char testdir[512], testpath[530];
  101     cfg.updatefileowner = 0;
  102 
  103     ck_assert_int_eq(remove_directory(TESTDIR), 1);
  104     ck_assert_int_eq(direxists(TESTDIR), 0);
  105     snprintf(testdir, 512, "%s/here/be/vnstat", TESTDIR);
  106     snprintf(testpath, 530, "%s/or_something.txt", testdir);
  107     preparevnstatdir(testpath, "user", "group");
  108     ck_assert_int_eq(direxists(TESTDIR), 1);
  109     ck_assert_int_eq(direxists(testdir), 1);
  110 
  111     ck_assert_int_eq(remove_directory(TESTDIR), 1);
  112     ck_assert_int_eq(direxists(TESTDIR), 0);
  113     snprintf(testdir, 512, "%s/here/be/vnstatd", TESTDIR);
  114     snprintf(testpath, 530, "%s/or_something.txt", testdir);
  115     preparevnstatdir(testpath, "user", "group");
  116     ck_assert_int_eq(direxists(TESTDIR), 1);
  117     ck_assert_int_eq(direxists(testdir), 1);
  118 }
  119 END_TEST
  120 
  121 void add_fs_tests(Suite *s)
  122 {
  123     TCase *tc_fs = tcase_create("FS");
  124     tcase_add_checked_fixture(tc_fs, setup, teardown);
  125     tcase_add_unchecked_fixture(tc_fs, setup, teardown);
  126     tcase_add_test(tc_fs, fileexists_with_no_file);
  127     tcase_add_test(tc_fs, fileexists_with_file);
  128     tcase_add_test(tc_fs, direxists_with_no_dir);
  129     tcase_add_test(tc_fs, direxists_with_dir);
  130     tcase_add_test(tc_fs, mkpath_with_no_dir);
  131     tcase_add_test(tc_fs, mkpath_with_dir);
  132     tcase_add_test(tc_fs, preparevnstatdir_with_no_vnstat);
  133     tcase_add_test(tc_fs, preparevnstatdir_with_vnstat);
  134     suite_add_tcase(s, tc_fs);
  135 }