END_TEST static bool check_adjusted_tstamp(Streader* sr, int32_t index, void* userdata) { fail_if(sr == NULL, "Callback did not get a Streader"); fail_if(Streader_is_error_set(sr), "Callback was called with Streader error set: %s", Streader_get_error_desc(sr)); fail_if(index < 0, "Callback got a negative item index (%" PRId32 ")", index); fail_if(index >= item_count, "Callback got too large an index (%" PRId32 ")", index); fail_if(userdata != NULL, "Callback got unexpected userdata"); Tstamp* ts = TSTAMP_AUTO; fail_if(!Streader_read_tstamp(sr, ts), "Could not read timestamp from list index %" PRId32 ": %s", index, Streader_get_error_desc(sr)); fail_if((Tstamp_get_beats(ts) != index + 10) || (Tstamp_get_rem(ts) != index + 100), "Unexpected list item " PRIts " (expected (%d, %d))", PRIVALts(*ts), (int)index + 10, (int)index + 100); return true; }
int serialise_Tstamp(char* dest, int size, const Tstamp* value) { assert(dest != NULL); assert(size > 0); assert(value != NULL); char beats_buf[INT_BUF_SIZE] = ""; char rem_buf[INT_BUF_SIZE] = ""; serialise_int(beats_buf, INT_BUF_SIZE, Tstamp_get_beats(value)); serialise_int(rem_buf, INT_BUF_SIZE, Tstamp_get_rem(value)); int printed = snprintf(dest, size, "[%s, %s]", beats_buf, rem_buf); return min(printed, size - 1); }