END_TEST START_TEST(showbar_with_half_and_half) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); defaultcfg(); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(0, 1, 0, 1, 2, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rrrrrttttt"); }
END_TEST START_TEST(showbar_can_also_do_mb_calculations) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); defaultcfg(); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(0, 1024, 0, 1024, 2048, 2); ck_assert_int_eq(len, 2); fflush(stdout); len = read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rt"); }
END_TEST START_TEST(timeused_debug_does_not_output_anything_when_debug_is_disabled) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); defaultcfg(); debug = 0; pipe = pipe_output(); /* the assumption here is that the next two steps can always execute in less than one second resulting in a duration that starts with a zero */ timeused_debug("other_func", 1); timeused_debug("other_func", 0); printf("-"); // stdout needs to contain something so that read doesn't block fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_int_eq(len, 1); }
END_TEST START_TEST(timeused_debug_outputs_something_expected_when_debug_is_enabled) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); defaultcfg(); debug = 1; pipe = pipe_output(); /* the assumption here is that the next two steps can always execute in less than one second resulting in a duration that starts with a zero */ timeused_debug("that_func", 1); timeused_debug("that_func", 0); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_int_gt(len, 1); ck_assert_ptr_ne(strstr(buffer, "that_func() in 0"), NULL); }