Kouhei Sutou
null+****@clear*****
Mon Jan 27 22:21:28 JST 2014
Kouhei Sutou 2014-01-27 22:21:28 +0900 (Mon, 27 Jan 2014) New Revision: 59c644c32f37922499f97025e0519fb42c830f8a https://github.com/groonga/groonga-gobject/commit/59c644c32f37922499f97025e0519fb42c830f8a Message: Add more tests for ggrn_command_to_path Modified files: test/test-command.c Modified: test/test-command.c (+59 -3) =================================================================== --- test/test-command.c 2014-01-22 00:23:22 +0900 (9a5f878) +++ test/test-command.c 2014-01-27 22:21:28 +0900 (0c34de5) @@ -24,7 +24,8 @@ #include <gcutter.h> -CUT_EXPORT void test_to_path(void); +CUT_EXPORT void data_to_path(void); +CUT_EXPORT void test_to_path(gconstpointer data); CUT_EXPORT void test_to_command_line(void); static GGrnContext *context; @@ -44,10 +45,65 @@ cut_teardown(void) g_object_unref(context); } +static void +add_argument(gpointer key, gpointer value, gpointer user_data) +{ + ggrn_command_add_argument(command, key, value); +} + +static void +add_arguments(GHashTable *arguments) +{ + if (!arguments) { + return; + } + + g_hash_table_foreach(arguments, add_argument, NULL); +} + +void +data_to_path(void) +{ +#define ADD_DATA(label, expected, arguments) \ + gcut_add_datum(label, \ + "expected", G_TYPE_STRING, expected, \ + "arguments", G_TYPE_HASH_TABLE, arguments, \ + NULL); + +#define ARGUMENTS(argument, ...) \ + gcut_hash_table_string_string_new(argument, __VA_ARGS__) + + ADD_DATA("no arguments", + "/d/select", + NULL); + ADD_DATA("one argument", + "/d/select?table=Users", + ARGUMENTS("table", "Users", + NULL)); + ADD_DATA("two or more arguments", + "/d/select?table=Users&output_columns=_key&limit=10", + ARGUMENTS("table", "Users", + "output_columns", "_key", + "limit", "10", + NULL)); + ADD_DATA("escape", + "/d/select?filter=%281%20%2B%202%20%26%26%20%22string%22%29", + ARGUMENTS("filter", "(1 + 2 && \"string\")", + NULL)); + +#undef ARGUMENTS + +#undef ADD_DATA +} + void -test_to_path(void) +test_to_path(gconstpointer data) { - cut_assert_equal_string_with_free("/d/select", + const gchar *expected; + + expected = gcut_data_get_string(data, "expected"); + add_arguments((GHashTable *)(gcut_data_get_pointer(data, "arguments"))); + cut_assert_equal_string_with_free(expected, ggrn_command_to_path(command)); } -------------- next part -------------- HTML����������������������������... Download