Exemple #1
0
void decode_suite(char ext, gpr_timespec (*answer)(long x)) {
    long test_vals[] = {1,       12,       123,       1234,     12345,   123456,
                        1234567, 12345678, 123456789, 98765432, 9876543, 987654,
                        98765,   9876,     987,       98,       9
                       };
    unsigned i;
    char *input;
    for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) {
        gpr_asprintf(&input, "%ld%c", test_vals[i], ext);
        assert_decodes_as(input, answer(test_vals[i]));
        gpr_free(input);

        gpr_asprintf(&input, "   %ld%c", test_vals[i], ext);
        assert_decodes_as(input, answer(test_vals[i]));
        gpr_free(input);

        gpr_asprintf(&input, "%ld %c", test_vals[i], ext);
        assert_decodes_as(input, answer(test_vals[i]));
        gpr_free(input);

        gpr_asprintf(&input, "%ld %c  ", test_vals[i], ext);
        assert_decodes_as(input, answer(test_vals[i]));
        gpr_free(input);
    }
}
void test_decoding(void) {
  LOG_TEST("test_decoding");
  decode_suite('n', gpr_time_from_nanos);
  decode_suite('u', gpr_time_from_micros);
  decode_suite('m', gpr_time_from_millis);
  decode_suite('S', gpr_time_from_seconds);
  decode_suite('M', gpr_time_from_minutes);
  decode_suite('H', gpr_time_from_hours);
  assert_decodes_as("1000000000S",
                    gpr_time_from_seconds(1000 * 1000 * 1000, GPR_TIMESPAN));
  assert_decodes_as("1000000000000000000000u", gpr_inf_future(GPR_TIMESPAN));
  assert_decodes_as("1000000001S", gpr_inf_future(GPR_TIMESPAN));
  assert_decodes_as("2000000001S", gpr_inf_future(GPR_TIMESPAN));
  assert_decodes_as("9999999999S", gpr_inf_future(GPR_TIMESPAN));
}
Exemple #3
0
void test_decoding(void) {
    LOG_TEST();
    decode_suite('n', gpr_time_from_nanos);
    decode_suite('u', gpr_time_from_micros);
    decode_suite('m', gpr_time_from_millis);
    decode_suite('S', gpr_time_from_seconds);
    decode_suite('M', gpr_time_from_minutes);
    decode_suite('H', gpr_time_from_hours);
    assert_decodes_as("1000000000000000000000u", gpr_inf_future);
}