void test_atoull(gconstpointer data) { const gchar *input, *input_end, *rest; uint64_t value; input = gcut_data_get_string(data, "input"); input_end = strchr(input, '\0'); value = grn_atoull(input, input_end, &rest); cut_assert_equal_string(input_end, rest); gcut_assert_equal_uint64(gcut_data_get_uint64(data, "expected"), value); }
void test_aton(gconstpointer data) { const gchar *input, *input_end, *rest; grn_builtin_type type; grn_rc rc; type = gcut_data_get_int(data, "type"); input = gcut_data_get_string(data, "input"); input_end = strchr(input, '\0'); rc = grn_aton(&context, input, input_end, &rest, &buffer); grn_test_assert(rc); cut_assert_equal_string(input_end, rest); cut_assert_equal_int(type, buffer.header.domain); switch (type) { case GRN_DB_INT32 : cut_assert_equal_int(gcut_data_get_int(data, "expected"), GRN_INT32_VALUE(&buffer)); break; case GRN_DB_UINT32 : cut_assert_equal_uint(gcut_data_get_uint(data, "expected"), GRN_UINT32_VALUE(&buffer)); break; case GRN_DB_INT64 : gcut_assert_equal_int64(gcut_data_get_int64(data, "expected"), GRN_INT64_VALUE(&buffer)); break; case GRN_DB_UINT64 : gcut_assert_equal_uint64(gcut_data_get_uint64(data, "expected"), GRN_UINT64_VALUE(&buffer)); break; case GRN_DB_FLOAT : cut_assert_equal_double(gcut_data_get_double(data, "expected"), 0.000001, GRN_FLOAT_VALUE(&buffer)); break; default : cut_error("unknown type: %d", type); break; } }
static void construct_object(gconstpointer data, grn_builtin_type type, grn_obj *object) { switch (type) { case GRN_DB_VOID: GRN_VOID_INIT(object); break; case GRN_DB_BOOL: GRN_BOOL_INIT(object, 0); GRN_BOOL_SET(&context, object, gcut_data_get_boolean(data, "value")); break; case GRN_DB_INT8: GRN_INT8_INIT(object, 0); GRN_INT8_SET(&context, object, gcut_data_get_int(data, "value")); break; case GRN_DB_UINT8: GRN_UINT8_INIT(object, 0); GRN_UINT8_SET(&context, object, gcut_data_get_uint(data, "value")); break; case GRN_DB_INT16: GRN_INT16_INIT(object, 0); GRN_INT16_SET(&context, object, gcut_data_get_int(data, "value")); break; case GRN_DB_UINT16: GRN_UINT16_INIT(object, 0); GRN_UINT16_SET(&context, object, gcut_data_get_uint(data, "value")); break; case GRN_DB_INT32: GRN_INT32_INIT(object, 0); GRN_INT32_SET(&context, object, gcut_data_get_int(data, "value")); break; case GRN_DB_UINT32: GRN_UINT32_INIT(object, 0); GRN_UINT32_SET(&context, object, gcut_data_get_uint(data, "value")); break; case GRN_DB_INT64: GRN_INT64_INIT(object, 0); GRN_INT64_SET(&context, object, gcut_data_get_int64(data, "value")); break; case GRN_DB_UINT64: GRN_UINT64_INIT(object, 0); GRN_UINT64_SET(&context, object, gcut_data_get_uint64(data, "value")); break; case GRN_DB_FLOAT: GRN_FLOAT_INIT(object, 0); GRN_FLOAT_SET(&context, object, gcut_data_get_double(data, "value")); break; case GRN_DB_TIME: GRN_TIME_INIT(object, 0); GRN_TIME_SET(&context, object, gcut_data_get_int64(data, "value")); break; case GRN_DB_SHORT_TEXT: GRN_SHORT_TEXT_INIT(object, 0); GRN_TEXT_SETS(&context, object, gcut_data_get_string(data, "value")); break; case GRN_DB_TEXT: GRN_TEXT_INIT(object, 0); GRN_TEXT_SETS(&context, object, gcut_data_get_string(data, "value")); break; case GRN_DB_LONG_TEXT: GRN_LONG_TEXT_INIT(object, 0); GRN_TEXT_SETS(&context, object, gcut_data_get_string(data, "value")); break; case GRN_DB_TOKYO_GEO_POINT: GRN_TOKYO_GEO_POINT_INIT(object, 0); GRN_GEO_POINT_SET(&context, object, gcut_data_get_int(data, "latitude"), gcut_data_get_int(data, "longitude")); break; case GRN_DB_WGS84_GEO_POINT: GRN_WGS84_GEO_POINT_INIT(object, 0); GRN_GEO_POINT_SET(&context, object, gcut_data_get_int(data, "latitude"), gcut_data_get_int(data, "longitude")); break; default: cut_fail("unknown type: %d", type); break; } }