Skip to content

Commit

Permalink
Merge pull request #138 from keithj/operator-bugfix
Browse files Browse the repository at this point in the history
Operator bugfix for #137
  • Loading branch information
dkj committed Oct 19, 2015
2 parents 71249cb + 06e49fe commit b5fe452
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/json_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void log_json_error(log_level level, json_error_t *error) {
}

const char *ensure_valid_operator(const char *oper, baton_error_t *error) {
static size_t num_operators = 10;
static size_t num_operators = 12;
static char *operators[] = { SEARCH_OP_EQUALS, SEARCH_OP_LIKE,
SEARCH_OP_NOT_LIKE, SEARCH_OP_IN,
SEARCH_OP_STR_GT, SEARCH_OP_STR_LT,
Expand All @@ -70,7 +70,7 @@ const char *ensure_valid_operator(const char *oper, baton_error_t *error) {
if (!valid) {
set_baton_error(error, CAT_INVALID_ARGUMENT,
"Invalid operator: expected one of "
"[%s, %s, %s, %s, %s, %s, %s, %s, %s, %s]",
"[%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s]",
SEARCH_OP_EQUALS, SEARCH_OP_LIKE,
SEARCH_OP_NOT_LIKE, SEARCH_OP_IN,
SEARCH_OP_STR_GT, SEARCH_OP_STR_LT,
Expand Down
49 changes: 49 additions & 0 deletions tests/check_baton.c
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,12 @@ START_TEST(test_slurp_file) {
}
END_TEST

// Having metadata on an item of (a = x, a = y), a search for "a = x"
// gives correct results, as does a search for "a = y". However,
// searching for "a = x and a = y" does not (nothing is returned).
//
// This is caused by overzealous cropping of search terms introduced
// in commit d6d036
START_TEST(test_regression_github_issue83) {
option_flags flags = 0;
rodsEnv env;
Expand Down Expand Up @@ -1929,6 +1935,48 @@ START_TEST(test_regression_github_issue83) {
}
END_TEST

// Are all the search operators accepted? "n>=", "n<=" were not being
// accepted by user input validation.
START_TEST(test_regression_github_issue137) {
option_flags flags = SEARCH_OBJECTS;
rodsEnv env;
rcComm_t *conn = rods_login(&env);

// Not testing 'in' here
char *operators[] = { "=", "like", "not like", ">", "<",
"n>", "n<", ">=", "<=", "n>=", "n<=" };

for (size_t i = 0; i < 11; i++) {
json_t *avu = json_pack("{s:s, s:s, s:s}",
JSON_ATTRIBUTE_KEY, "numattr1",
JSON_VALUE_KEY, "10",
JSON_OPERATOR_KEY, operators[i]);
json_t *query = json_pack("{s:[o]}", JSON_AVUS_KEY, avu);

baton_error_t error;
json_t *results = search_metadata(conn, query, NULL, flags, &error);
ck_assert_msg(error.code == 0, operators[i]);

json_decref(query);
json_decref(results);
}

// Test 'in' here
json_t *avu = json_pack("{s:s, s:[s], s:s}",
JSON_ATTRIBUTE_KEY, "numattr1",
JSON_VALUE_KEY, "10",
JSON_OPERATOR_KEY, "in");
json_t *query = json_pack("{s:[o]}", JSON_AVUS_KEY, avu);

baton_error_t error;
json_t *results = search_metadata(conn, query, NULL, flags, &error);
ck_assert_msg(error.code == 0, "in");
json_decref(query);
json_decref(results);

if (conn) rcDisconnect(conn);
}
END_TEST

Suite *baton_suite(void) {
Suite *suite = suite_create("baton");
Expand Down Expand Up @@ -2003,6 +2051,7 @@ Suite *baton_suite(void) {
tcase_add_checked_fixture (regression_tests, basic_setup, basic_teardown);

tcase_add_test(regression_tests, test_regression_github_issue83);
tcase_add_test(regression_tests, test_regression_github_issue137);

suite_add_tcase(suite, utilities_tests);
suite_add_tcase(suite, basic_tests);
Expand Down
4 changes: 4 additions & 0 deletions tests/metadata/meta1.imeta
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ add -d __IRODS_TEST_ROOT__/r1.txt a y
add -d __IRODS_TEST_ROOT__/r1.txt b x
add -d __IRODS_TEST_ROOT__/r1.txt b y
add -d __IRODS_TEST_ROOT__/r1.txt b z

add -d __IRODS_TEST_ROOT__/r1.txt numattr1 1
add -d __IRODS_TEST_ROOT__/r1.txt numattr1 10
add -d __IRODS_TEST_ROOT__/r1.txt numattr1 100

0 comments on commit b5fe452

Please sign in to comment.