20 #include <glib/gstdio.h>
22 #include "../lib/grn-assertions.h"
30 static gchar *tmp_directory, *plugins_dir, *plugins_dir_env;
46 g_free(tmp_directory);
50 remove_tmp_directory(
void)
52 cut_remove_path(tmp_directory, NULL);
56 setup_plugins_dir(
void)
63 plugins_dir_env = g_strdup(g_getenv(
"GRN_PLUGINS_DIR"));
64 g_setenv(
"GRN_PLUGINS_DIR", plugins_dir,
TRUE);
70 const gchar *database_path;
72 remove_tmp_directory();
73 g_mkdir_with_parents(tmp_directory, 0700);
78 database_path = cut_build_path(tmp_directory,
"database.groonga", NULL);
85 teardown_plugins_dir(
void)
87 if (plugins_dir_env) {
88 g_setenv(
"GRN_PLUGINS_DIR", plugins_dir_env,
TRUE);
90 g_unsetenv(
"GRN_PLUGINS_DIR");
92 g_free(plugins_dir_env);
99 teardown_plugins_dir();
105 remove_tmp_directory();
114 cut_assert_equal_string(
"[[[1],[[\"_score\",\"Int32\"]],[11]]]",
116 "--output_columns _score "
118 "--scorer '_score=str_len(_key)'"));
125 const gchar *full_path;
126 const gchar *error_message_without_path;
127 const gchar *error_message_without_name;
128 gint
i, max_name_length;
130 long_name = gcut_take_new_string(NULL);
131 max_name_length = (
PATH_MAX - strlen(plugins_dir) - 1) - 1;
132 for (i = 0; i < max_name_length; i++) {
133 g_string_append_c(long_name,
'x');
135 full_path = cut_take_string(g_build_filename(plugins_dir,
138 error_message_without_path =
"too long plugin path: <";
142 cut_take_printf(
"%s%.*s",
143 error_message_without_path,
145 strlen(error_message_without_path) -
148 cut_take_printf(
"register %s", long_name->str));
150 g_string_append_c(long_name,
'x');
151 full_path = cut_take_string(g_build_filename(plugins_dir,
154 error_message_without_name =
155 cut_take_printf(
"plugin name is too long: %d (max: %d) <",
156 (
int)(long_name->len),
161 cut_take_printf(
"%s%.*s",
162 error_message_without_name,
164 strlen(error_message_without_name) -
167 cut_take_printf(
"register %s", long_name->str));
176 cut_assert_equal_string(
"[[[1],[[\"_score\",\"Int32\"]],[11]]]",
178 "--output_columns _score "
180 "--scorer '_score=str_len(_key)'"));