Beispiel #1
0
void
data_type_to_string(void)
{
#define ADD_DATUM(expected, type)                                      \
  gcut_add_datum(G_STRINGIFY(type),                                    \
                 "expected", G_TYPE_STRING, expected,                  \
                 "type", G_TYPE_UINT, type,                            \
                 NULL)

  ADD_DATUM("void", GRN_VOID);
  ADD_DATUM("bulk", GRN_BULK);
  ADD_DATUM("ptr", GRN_PTR);
  ADD_DATUM("uvector", GRN_UVECTOR);
  ADD_DATUM("pvector", GRN_PVECTOR);
  ADD_DATUM("vector", GRN_VECTOR);
  ADD_DATUM("msg", GRN_MSG);
  ADD_DATUM("query", GRN_QUERY);
  ADD_DATUM("accessor", GRN_ACCESSOR);
  ADD_DATUM("snip", GRN_SNIP);
  ADD_DATUM("patsnip", GRN_PATSNIP);
  ADD_DATUM("string", GRN_STRING);
  ADD_DATUM("cursor:table:hash_key", GRN_CURSOR_TABLE_HASH_KEY);
  ADD_DATUM("cursor:table:pat_key", GRN_CURSOR_TABLE_PAT_KEY);
  ADD_DATUM("cursor:table:dat_key", GRN_CURSOR_TABLE_DAT_KEY);
  ADD_DATUM("cursor:table:no_key", GRN_CURSOR_TABLE_NO_KEY);
  ADD_DATUM("cursor:column:index", GRN_CURSOR_COLUMN_INDEX);
  ADD_DATUM("cursor:column:geo_index", GRN_CURSOR_COLUMN_GEO_INDEX);
  ADD_DATUM("cursor:config", GRN_CURSOR_CONFIG);
  ADD_DATUM("type", GRN_TYPE);
  ADD_DATUM("proc", GRN_PROC);
  ADD_DATUM("expr", GRN_EXPR);
  ADD_DATUM("table:hash_key", GRN_TABLE_HASH_KEY);
  ADD_DATUM("table:pat_key", GRN_TABLE_PAT_KEY);
  ADD_DATUM("table:dat_key", GRN_TABLE_DAT_KEY);
  ADD_DATUM("table:no_key", GRN_TABLE_NO_KEY);
  ADD_DATUM("db", GRN_DB);
  ADD_DATUM("column:fix_size", GRN_COLUMN_FIX_SIZE);
  ADD_DATUM("column:var_size", GRN_COLUMN_VAR_SIZE);
  ADD_DATUM("column:index", GRN_COLUMN_INDEX);

#undef ADD_DATUM
}
Beispiel #2
0
void
data_text_otoj(void)
{
#define ADD_DATUM(label, expected, type, ...)                   \
  gcut_add_datum(label,                                         \
                 "expected", G_TYPE_STRING, expected,           \
                 "type", G_TYPE_INT, type,                      \
                 __VA_ARGS__);

  ADD_DATUM("Void", "", GRN_DB_VOID, NULL);
  ADD_DATUM("Bool", "true", GRN_DB_BOOL,
            "value", G_TYPE_BOOLEAN, TRUE,
            NULL);
  ADD_DATUM("Bool", "false", GRN_DB_BOOL,
            "value", G_TYPE_BOOLEAN, FALSE,
            NULL);
  ADD_DATUM("Int8 (min)", cut_take_printf("%d", INT8_MIN), GRN_DB_INT8,
            "value", G_TYPE_INT, INT8_MIN,
            NULL);
  ADD_DATUM("Int8 (max)", cut_take_printf("%d", INT8_MAX), GRN_DB_INT8,
            "value", G_TYPE_INT, INT8_MAX,
            NULL);
  ADD_DATUM("UInt8 (min)", "0", GRN_DB_UINT8,
            "value", G_TYPE_UINT, 0,
            NULL);
  ADD_DATUM("UInt8 (max)", cut_take_printf("%u", UINT8_MAX), GRN_DB_UINT8,
            "value", G_TYPE_UINT, UINT8_MAX,
            NULL);
  ADD_DATUM("Int16 (min)", cut_take_printf("%d", INT16_MIN), GRN_DB_INT16,
            "value", G_TYPE_INT, INT16_MIN,
            NULL);
  ADD_DATUM("Int16 (max)", cut_take_printf("%d", INT16_MAX), GRN_DB_INT16,
            "value", G_TYPE_INT, INT16_MAX,
            NULL);
  ADD_DATUM("UInt16 (min)", "0", GRN_DB_UINT16,
            "value", G_TYPE_UINT, 0,
            NULL);
  ADD_DATUM("UInt16 (max)", cut_take_printf("%u", UINT16_MAX), GRN_DB_UINT16,
            "value", G_TYPE_UINT, UINT16_MAX,
            NULL);
  ADD_DATUM("Int32 (min)", cut_take_printf("%d", INT32_MIN), GRN_DB_INT32,
            "value", G_TYPE_INT, INT32_MIN,
            NULL);
  ADD_DATUM("Int32 (max)", cut_take_printf("%d", INT32_MAX), GRN_DB_INT32,
            "value", G_TYPE_INT, INT32_MAX,
            NULL);
  ADD_DATUM("UInt32 (min)", "0", GRN_DB_UINT32,
            "value", G_TYPE_UINT, 0,
            NULL);
  ADD_DATUM("UInt32 (max)", cut_take_printf("%u", UINT32_MAX), GRN_DB_UINT32,
            "value", G_TYPE_UINT, UINT32_MAX,
            NULL);
  ADD_DATUM("Int64 (min)",
            cut_take_printf("%" G_GINT64_FORMAT, INT64_MIN), GRN_DB_INT64,
            "value", G_TYPE_INT64, INT64_MIN,
            NULL);
  ADD_DATUM("Int64 (max)",
            cut_take_printf("%" G_GINT64_FORMAT, INT64_MAX), GRN_DB_INT64,
            "value", G_TYPE_INT64, INT64_MAX,
            NULL);
  ADD_DATUM("UInt64 (min)", "0", GRN_DB_UINT64,
            "value", G_TYPE_UINT64, G_GUINT64_CONSTANT(0),
            NULL);
  ADD_DATUM("UInt64 (max)",
            cut_take_printf("%" G_GUINT64_FORMAT, UINT64_MAX), GRN_DB_UINT64,
            "value", G_TYPE_UINT64, UINT64_MAX,
            NULL);
  ADD_DATUM("Float", cut_take_printf("%g", 2.9), GRN_DB_FLOAT,
            "value", G_TYPE_DOUBLE, 2.9,
            NULL);
  ADD_DATUM("Time", "1271053050.21148", GRN_DB_TIME,
            "value", G_TYPE_INT64, GRN_TIME_PACK(1271053050, 211479),
            NULL);
  ADD_DATUM("ShortText",
            "\"\\\"'\\\\aAzZ09 \\n\\t\\r日本語\"", GRN_DB_SHORT_TEXT,
            "value", G_TYPE_STRING, "\"'\\aAzZ09 \n\t\r日本語",
            NULL);
  ADD_DATUM("Text",
            "\"\\\"'\\\\aAzZ09 \\n\\t\\r日本語\"", GRN_DB_TEXT,
            "value", G_TYPE_STRING, "\"'\\aAzZ09 \n\t\r日本語",
            NULL);
  ADD_DATUM("LongText",
            "\"\\\"'\\\\aAzZ09 \\n\\t\\r日本語\"", GRN_DB_LONG_TEXT,
            "value", G_TYPE_STRING, "\"'\\aAzZ09 \n\t\r日本語",
            NULL);
  ADD_DATUM("TokyoGeoPoint", "\"35681396x139766049\"", GRN_DB_TOKYO_GEO_POINT,
            "latitude", G_TYPE_INT, 35681396,
            "longitude", G_TYPE_INT, 139766049,
            NULL);
  ADD_DATUM("WGS84GeoPoint", "\"36032548x140164867\"", GRN_DB_WGS84_GEO_POINT,
            "latitude", G_TYPE_INT, 36032548,
            "longitude", G_TYPE_INT, 140164867,
            NULL);

  /* FIXME* unknown bulk */
  /* FIXME: GRN_UVECTOR */
  /* FIXME: GRN_VECTOR */
  /* FIXME: table with format */
  /* FIXME: table without format */
  /* FIXME: grn_text_atoj */

#undef ADD_DATUM
}
Beispiel #3
0
void
data_null(void)
{
#define ADD_DATUM(label, expected, load)                        \
  gcut_add_datum(label,                                         \
                 "expected", G_TYPE_STRING, expected,           \
                 "load", G_TYPE_STRING, load,                   \
                 NULL)

    ADD_DATUM("string - null",
              "[[[1],"
              "[[\"_id\",\"UInt32\"],"
              "[\"_key\",\"ShortText\"],"
              "[\"scores\",\"Int32\"],"
              "[\"nick\",\"ShortText\"]],"
              "[1,\"Daijiro MORI\",[5,5,5],\"\"]]]",
              "load --table Students --columns '_key, nick'\n"
              "[\n"
              "  [\"Daijiro MORI\", null]\n"
              "]");
    ADD_DATUM("string - empty string",
              "[[[1],"
              "[[\"_id\",\"UInt32\"],"
              "[\"_key\",\"ShortText\"],"
              "[\"scores\",\"Int32\"],"
              "[\"nick\",\"ShortText\"]],"
              "[1,\"Daijiro MORI\",[5,5,5],\"\"]]]",
              "load --table Students --columns '_key, nick'\n"
              "[\n"
              "  [\"Daijiro MORI\", \"\"]\n"
              "]");

    ADD_DATUM("vector - empty null",
              "[[[1],"
              "[[\"_id\",\"UInt32\"],"
              "[\"_key\",\"ShortText\"],"
              "[\"scores\",\"Int32\"],"
              "[\"nick\",\"ShortText\"]],"
              "[1,\"Daijiro MORI\",[],\"morita\"]]]",
              "load --table Students --columns '_key, scores'\n"
              "[\n"
              "  [\"Daijiro MORI\", null]\n"
              "]");
    ADD_DATUM("vector - empty string",
              "[[[1],"
              "[[\"_id\",\"UInt32\"],"
              "[\"_key\",\"ShortText\"],"
              "[\"scores\",\"Int32\"],"
              "[\"nick\",\"ShortText\"]],"
              "[1,\"Daijiro MORI\",[],\"morita\"]]]",
              "load --table Students --columns '_key, scores'\n"
              "[\n"
              "  [\"Daijiro MORI\", \"\"]\n"
              "]");
    ADD_DATUM("vector - empty array",
              "[[[1],"
              "[[\"_id\",\"UInt32\"],"
              "[\"_key\",\"ShortText\"],"
              "[\"scores\",\"Int32\"],"
              "[\"nick\",\"ShortText\"]],"
              "[1,\"Daijiro MORI\",[],\"morita\"]]]",
              "load --table Students --columns '_key, scores'\n"
              "[\n"
              "  [\"Daijiro MORI\", []]\n"
              "]");

#undef ADD_DATUM
}