"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/common_tests.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

common_tests.c  (vnstat-2.7):common_tests.c  (vnstat-2.8)
skipping to change at line 98 skipping to change at line 98
ck_assert_int_eq(isleapyear(2018), 0); ck_assert_int_eq(isleapyear(2018), 0);
ck_assert_int_eq(isleapyear(2019), 0); ck_assert_int_eq(isleapyear(2019), 0);
ck_assert_int_eq(isleapyear(2020), 1); ck_assert_int_eq(isleapyear(2020), 1);
ck_assert_int_eq(isleapyear(2021), 0); ck_assert_int_eq(isleapyear(2021), 0);
} }
END_TEST END_TEST
START_TEST(mosecs_return_values) START_TEST(mosecs_return_values)
{ {
time_t a, b; time_t a, b;
defaultcfg();
cfg.monthrotate = 1; cfg.monthrotate = 1;
ck_assert_int_eq(mosecs(0, 0), 1); ck_assert_int_eq(mosecs(0, 0), 1);
a = mosecs(172800, 173000); a = mosecs(172800, 173000);
ck_assert_int_gt(a, 1); ck_assert_int_gt(a, 1);
cfg.monthrotate = 2; cfg.monthrotate = 2;
b = mosecs(172800, 173000); b = mosecs(172800, 173000);
ck_assert_int_gt(b, 1); ck_assert_int_gt(b, 1);
skipping to change at line 125 skipping to change at line 124
#if defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || defined(__APPLE__) || def ined(__linux__) #if defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || defined(__APPLE__) || def ined(__linux__)
extern long timezone; extern long timezone;
#else #else
long timezone = 0; long timezone = 0;
#endif #endif
long timezone_before_call; long timezone_before_call;
tzset(); tzset();
timezone_before_call = timezone; timezone_before_call = timezone;
defaultcfg();
ck_assert_int_eq(cfg.monthrotate, 1); ck_assert_int_eq(cfg.monthrotate, 1);
ck_assert_int_ne(mosecs(1, 2), 0); ck_assert_int_ne(mosecs(1, 2), 0);
ck_assert_int_ne(mosecs(1, 2), 1); ck_assert_int_ne(mosecs(1, 2), 1);
ck_assert_int_eq(timezone_before_call, timezone); ck_assert_int_eq(timezone_before_call, timezone);
} }
END_TEST END_TEST
START_TEST(mosecs_does_not_change_struct_tm_pointer_content) START_TEST(mosecs_does_not_change_struct_tm_pointer_content)
{ {
struct tm *stm; struct tm *stm;
time_t current; time_t current;
current = time(NULL); current = time(NULL);
stm = localtime(&current); stm = localtime(&current);
defaultcfg();
ck_assert_int_eq(cfg.monthrotate, 1); ck_assert_int_eq(cfg.monthrotate, 1);
ck_assert_int_eq(current, mktime(stm)); ck_assert_int_eq(current, mktime(stm));
ck_assert_int_ne(mosecs(1, 2), 0); ck_assert_int_ne(mosecs(1, 2), 0);
ck_assert_int_ne(mosecs(1, 2), 1); ck_assert_int_ne(mosecs(1, 2), 1);
ck_assert_int_eq(current, mktime(stm)); ck_assert_int_eq(current, mktime(stm));
} }
END_TEST END_TEST
START_TEST(countercalc_no_change_32bit) START_TEST(countercalc_no_change_32bit)
{ {
skipping to change at line 351 skipping to change at line 348
ck_assert(strchr(getversion(), '.') != NULL); ck_assert(strchr(getversion(), '.') != NULL);
} }
END_TEST END_TEST
START_TEST(timeused_debug_outputs_something_expected_when_debug_is_enabled) START_TEST(timeused_debug_outputs_something_expected_when_debug_is_enabled)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
debug = 1; debug = 1;
pipe = pipe_output(); pipe = pipe_output();
/* the assumption here is that the next two steps /* the assumption here is that the next two steps
can always execute in less than one second resulting can always execute in less than one second resulting
in a duration that starts with a zero */ in a duration that starts with a zero */
timeused_debug("that_func", 1); timeused_debug("that_func", 1);
timeused_debug("that_func", 0); timeused_debug("that_func", 0);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
skipping to change at line 373 skipping to change at line 369
ck_assert_ptr_ne(strstr(buffer, "that_func() in 0"), NULL); ck_assert_ptr_ne(strstr(buffer, "that_func() in 0"), NULL);
} }
END_TEST END_TEST
START_TEST(timeused_debug_does_not_output_anything_when_debug_is_disabled) START_TEST(timeused_debug_does_not_output_anything_when_debug_is_disabled)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
debug = 0; debug = 0;
pipe = pipe_output(); pipe = pipe_output();
/* the assumption here is that the next two steps /* the assumption here is that the next two steps
can always execute in less than one second resulting can always execute in less than one second resulting
in a duration that starts with a zero */ in a duration that starts with a zero */
timeused_debug("other_func", 1); timeused_debug("other_func", 1);
timeused_debug("other_func", 0); timeused_debug("other_func", 0);
printf("-"); // stdout needs to contain something so that read doesn't bl ock printf("-"); // stdout needs to contain something so that read doesn't bl ock
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_int_eq(len, 1); ck_assert_int_eq(len, 1);
} }
END_TEST END_TEST
START_TEST(timeused_tracks_used_time) START_TEST(timeused_tracks_used_time)
{ {
double used; double used;
struct timespec ts; struct timespec ts;
defaultcfg();
used = timeused("quick_func", 1); used = timeused("quick_func", 1);
ck_assert(used == 0.0); ck_assert(used == 0.0);
ts.tv_sec = 0; ts.tv_sec = 0;
ts.tv_nsec = 100000000; // 0.1 s ts.tv_nsec = 100000000; // 0.1 s
nanosleep(&ts, NULL); nanosleep(&ts, NULL);
used = timeused("quick_func", 0); used = timeused("quick_func", 0);
ck_assert(used > 0.0); ck_assert(used > 0.0);
} }
 End of changes. 6 change blocks. 
7 lines changed or deleted 0 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)