]> granicus.if.org Git - vnstat/commitdiff
fix clang warnings from tests
authorTeemu Toivola <git@humdi.net>
Mon, 5 Mar 2018 20:05:44 +0000 (22:05 +0200)
committerTeemu Toivola <git@humdi.net>
Mon, 5 Mar 2018 20:05:44 +0000 (22:05 +0200)
tests/common_tests.c
tests/daemon_tests.c
tests/database_tests.c
tests/datacache_tests.c
tests/dbsql_tests.c
tests/misc_tests.c

index e94d8c67969b62b330f28eb484f878e2dcac0aac..d47884ca5dca0c2e89ed9cc6bf58acb2934ddc33 100644 (file)
@@ -42,6 +42,8 @@ START_TEST(logprint_options)
 }
 END_TEST
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
 START_TEST(dmonth_return_within_range)
 {
        int m;
@@ -50,6 +52,7 @@ START_TEST(dmonth_return_within_range)
        ck_assert_int_le(m, 31);
 }
 END_TEST
+#pragma clang diagnostic pop
 
 START_TEST(leapyears_are_known)
 {
@@ -267,12 +270,13 @@ START_TEST(timeused_outputs_something_expected)
        timeused("something", 0);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_int_gt(len, 0);
        ck_assert_ptr_ne(strstr(buffer, "something() in 0"), NULL);
 }
 END_TEST
 
+__attribute__((noreturn))
 START_TEST(can_panic)
 {
        suppress_output();
index 197bede91c6b655a8aaa4ea7041a9502b365a24f..89fafaa8e01dbb88bb2b7d1bd2454dbfb79463c4 100644 (file)
@@ -49,7 +49,7 @@ START_TEST(addinterfaces_adds_interfaces)
        ret = db_open_rw(1);
        ck_assert_int_eq(ret, 1);
 
-       ret = addinterfaces(&s);
+       ret = (int)addinterfaces(&s);
        ck_assert_int_eq(ret, 2);
 
        ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1);
@@ -83,7 +83,7 @@ START_TEST(addinterfaces_adds_only_new_interfaces)
        ret = db_open_rw(1);
        ck_assert_int_eq(ret, 1);
 
-       ret = addinterfaces(&s);
+       ret = (int)addinterfaces(&s);
        ck_assert_int_eq(ret, 2);
 
        ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1);
@@ -102,7 +102,7 @@ START_TEST(addinterfaces_adds_only_new_interfaces)
 
        fake_proc_net_dev("a", "eththree", 9, 10, 11, 12);
 
-       ret = addinterfaces(&s);
+       ret = (int)addinterfaces(&s);
        ck_assert_int_eq(ret, 1);
 
        ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1);
@@ -144,7 +144,7 @@ START_TEST(addinterfaces_adds_to_cache_when_running)
        ck_assert_int_eq(datacache_count(&s.dcache), 0);
 
        s.running = 1;
-       ret = addinterfaces(&s);
+       ret = (int)addinterfaces(&s);
        ck_assert_int_eq(ret, 2);
        ck_assert_int_eq(datacache_count(&s.dcache), 2);
 
@@ -163,7 +163,7 @@ START_TEST(addinterfaces_adds_to_cache_when_running)
 
        fake_proc_net_dev("a", "eththree", 9, 10, 11, 12);
 
-       ret = addinterfaces(&s);
+       ret = (int)addinterfaces(&s);
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(datacache_count(&s.dcache), 3);
 
index 75694aa3c9cebbab31c108942f57d3d771984a21..6b496e97edc605456eab456bd94fdc787c4e1fff 100644 (file)
@@ -215,7 +215,7 @@ START_TEST(database_outputs_do_not_crash)
        ck_assert_int_eq(ret, 1);
 
        for (i=1; i<100; i++) {
-               ret = db_addtraffic_dated("something", i*1234, i*2345, i*85000);
+               ret = db_addtraffic_dated("something", (uint64_t)i*1234, (uint64_t)i*2345, (uint64_t)i*85000);
                ck_assert_int_eq(ret, 1);
        }
 
@@ -327,7 +327,7 @@ START_TEST(showbar_with_all_rx)
        ck_assert_int_eq(len, 10);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_str_eq(buffer, "  rrrrrrrrrr");
 }
 END_TEST
@@ -346,7 +346,7 @@ START_TEST(showbar_with_all_tx)
        ck_assert_int_eq(len, 10);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_str_eq(buffer, "  tttttttttt");
 }
 END_TEST
@@ -365,7 +365,7 @@ START_TEST(showbar_with_half_and_half)
        ck_assert_int_eq(len, 10);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_str_eq(buffer, "  rrrrrttttt");
 }
 END_TEST
@@ -384,7 +384,7 @@ START_TEST(showbar_with_one_tenth)
        ck_assert_int_eq(len, 10);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_str_eq(buffer, "  rttttttttt");
 }
 END_TEST
@@ -403,7 +403,7 @@ START_TEST(showbar_with_small_rx_shows_all_tx)
        ck_assert_int_eq(len, 10);
        fflush(stdout);
 
-       len = read(pipe, buffer, 512);
+       len = (int)read(pipe, buffer, 512);
        ck_assert_str_eq(buffer, "  tttttttttt");
 }
 END_TEST
@@ -448,7 +448,7 @@ void add_database_tests(Suite *s)
 
 int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
 {
-       FILE *db;
+       FILE *testdb;
        char file[512], backup[512];
 
        snprintf(file, 512, "%s/%s", dirname, iface);
@@ -464,15 +464,15 @@ int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
        /* make sure version stays correct */
        data->version=LEGACYDBVERSION;
 
-       if ((db=fopen(file,"w"))==NULL) {
+       if ((testdb=fopen(file,"w"))==NULL) {
                snprintf(errorstring, 1024, "Unable to open database \"%s\" for writing: %s", file, strerror(errno));
                printe(PT_Error);
                return 0;
        }
 
        /* lock file */
-       if (!lockdb(fileno(db), 1)) {
-               fclose(db);
+       if (!lockdb(fileno(testdb), 1)) {
+               fclose(testdb);
                return 0;
        }
 
@@ -481,16 +481,16 @@ int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
                data->lastupdated=time(NULL);
        }
 
-       if (fwrite(data,sizeof(DATA),1,db)==0) {
+       if (fwrite(data,sizeof(DATA),1,testdb)==0) {
                snprintf(errorstring, 1024, "Unable to write database \"%s\": %s", file, strerror(errno));
                printe(PT_Error);
-               fclose(db);
+               fclose(testdb);
                return 0;
        } else {
                if (debug) {
                        printf("db: Database \"%s\" saved.\n", file);
                }
-               fclose(db);
+               fclose(testdb);
                if ((newdb) && (noexit==0)) {
                        snprintf(errorstring, 1024, "-> A new database has been created.");
                        printe(PT_Info);
@@ -521,7 +521,7 @@ int backupdb(const char *current, const char *backup)
 
        /* copy data */
        while((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) {
-               if (write(b, buffer, bytes) < 0) {
+               if (write(b, buffer, (size_t)bytes) < 0) {
                        close(c);
                        fclose(bf);
                        return 0;
index f6388884fe022ef0132bcdff6e9738595a2c2f48..fb10bf8f1834c9410bbe181055f44dba87926e25 100644 (file)
@@ -277,7 +277,7 @@ START_TEST(datacache_can_do_stuff)
        iter = dc;
        ret = datacache_seek(&iter, "eth3");
        for (i=1; i<=10; i++) {
-               ret = xferlog_add(&iter->log, i, i*10, i*20);
+               ret = xferlog_add(&iter->log, (time_t)i, (uint64_t)i*10, (uint64_t)i*20);
                ck_assert_int_eq(ret, 1);
        }
        ck_assert_int_eq(iter->log->timestamp, 10);
index 22a19e5c2853571b56bc4e6ddd5c930b3554a5bb..efa169c24b6eb646ff9618b0e2544dbf3b5871ca 100644 (file)
@@ -489,7 +489,7 @@ END_TEST
 
 START_TEST(db_getinterfacecount_counts_interfaces)
 {
-       uint64_t ret;
+       int ret;
 
        defaultcfg();
        suppress_output();
@@ -497,25 +497,25 @@ START_TEST(db_getinterfacecount_counts_interfaces)
        ret = db_open_rw(1);
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecount();
+       ret = (int)db_getinterfacecount();
        ck_assert_int_eq(ret, 0);
 
        ret = db_addinterface("eth0");
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecount();
+       ret = (int)db_getinterfacecount();
        ck_assert_int_eq(ret, 1);
 
        ret = db_addinterface("eth0");
        ck_assert_int_eq(ret, 0);
 
-       ret = db_getinterfacecount();
+       ret = (int)db_getinterfacecount();
        ck_assert_int_eq(ret, 1);
 
        ret = db_addinterface("eth1");
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecount();
+       ret = (int)db_getinterfacecount();
        ck_assert_int_eq(ret, 2);
 
        ret = db_close();
@@ -525,7 +525,7 @@ END_TEST
 
 START_TEST(db_getinterfacecountbyname_counts_interfaces)
 {
-       uint64_t ret;
+       int ret;
 
        defaultcfg();
 
@@ -538,19 +538,19 @@ START_TEST(db_getinterfacecountbyname_counts_interfaces)
        ret = db_addinterface("eth1");
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecountbyname("foo");
+       ret = (int)db_getinterfacecountbyname("foo");
        ck_assert_int_eq(ret, 0);
 
-       ret = db_getinterfacecountbyname("eth0");
+       ret = (int)db_getinterfacecountbyname("eth0");
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecountbyname("eth1");
+       ret = (int)db_getinterfacecountbyname("eth1");
        ck_assert_int_eq(ret, 1);
 
-       ret = db_getinterfacecountbyname("eth2");
+       ret = (int)db_getinterfacecountbyname("eth2");
        ck_assert_int_eq(ret, 0);
 
-       ret = db_getinterfacecountbyname("");
+       ret = (int)db_getinterfacecountbyname("");
        ck_assert_int_eq(ret, 2);
 
        ret = db_close();
index a94662b61f79734d9865a0ac2446f75b8d828330..bb16ce6503bd3bebf11b7529dfb4be4cad4001a2 100644 (file)
@@ -9,6 +9,8 @@ START_TEST(getbtime_does_not_return_zero)
 }
 END_TEST
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
 START_TEST(getunitprefix_returns_something_with_all_cfg_combinations)
 {
        const char *string;
@@ -49,6 +51,7 @@ START_TEST(getunitdivisor_returns_something_with_all_cfg_combinations)
        }
 }
 END_TEST
+#pragma clang diagnostic pop
 
 START_TEST(spacecheck_does_not_check_when_not_configured)
 {