From: Teemu Toivola Date: Mon, 5 Mar 2018 20:05:44 +0000 (+0200) Subject: fix clang warnings from tests X-Git-Tag: v2.0~88 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65fc3a2f1679644cec5e8e6cf556c05e36aa3bc4;p=vnstat fix clang warnings from tests --- diff --git a/tests/common_tests.c b/tests/common_tests.c index e94d8c6..d47884c 100644 --- a/tests/common_tests.c +++ b/tests/common_tests.c @@ -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(); diff --git a/tests/daemon_tests.c b/tests/daemon_tests.c index 197bede..89fafaa 100644 --- a/tests/daemon_tests.c +++ b/tests/daemon_tests.c @@ -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); diff --git a/tests/database_tests.c b/tests/database_tests.c index 75694aa..6b496e9 100644 --- a/tests/database_tests.c +++ b/tests/database_tests.c @@ -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; diff --git a/tests/datacache_tests.c b/tests/datacache_tests.c index f638888..fb10bf8 100644 --- a/tests/datacache_tests.c +++ b/tests/datacache_tests.c @@ -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); diff --git a/tests/dbsql_tests.c b/tests/dbsql_tests.c index 22a19e5..efa169c 100644 --- a/tests/dbsql_tests.c +++ b/tests/dbsql_tests.c @@ -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(); diff --git a/tests/misc_tests.c b/tests/misc_tests.c index a94662b..bb16ce6 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -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) {