diff --git a/unit_tests/src/test_rc_genquery2.cpp b/unit_tests/src/test_rc_genquery2.cpp index c2365837a8..313fe20646 100644 --- a/unit_tests/src/test_rc_genquery2.cpp +++ b/unit_tests/src/test_rc_genquery2.cpp @@ -14,15 +14,15 @@ // NOLINTNEXTLINE(readability-function-cognitive-complexity) TEST_CASE("rc_genquery2") { - SECTION("execute a simple query") - { - load_client_api_plugins(); + load_client_api_plugins(); - rodsEnv env; - _getRodsEnv(env); + rodsEnv env; + _getRodsEnv(env); - irods::experimental::client_connection conn; + irods::experimental::client_connection conn; + SECTION("execute a simple query") + { auto query_string = fmt::format("select COLL_NAME where COLL_NAME = '{}'", env.rodsHome); Genquery2Input input{}; @@ -56,4 +56,60 @@ TEST_CASE("rc_genquery2") CHECK(rc_genquery2(&comm, &input, nullptr) == SYS_INVALID_INPUT_PARAM); CHECK_FALSE(output); } + + SECTION("supports nested, multi-argument functions in projection list") + { + auto query_string = fmt::format("select concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) where COLL_NAME = '{}'", env.rodsHome); + + Genquery2Input input{}; + input.query_string = query_string.data(); + + char* output{}; + REQUIRE(rc_genquery2(static_cast(conn), &input, &output) == 0); + REQUIRE_FALSE(output == nullptr); + + REQUIRE_NOTHROW([&env, &output] { + const auto result = nlohmann::json::parse(output); + CHECK_FALSE(result.empty()); + const auto expected = fmt::format("{}--{}", env.rodsHome, env.rodsUserName); + CHECK(result.at(0).at(0).get_ref() == expected); + }()); + } + + SECTION("supports nested, multi-argument functions in where clause") + { + auto query_string = fmt::format("select COLL_NAME where concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) = '{}--{}'", env.rodsHome, env.rodsUserName); + + Genquery2Input input{}; + input.query_string = query_string.data(); + + char* output{}; + REQUIRE(rc_genquery2(static_cast(conn), &input, &output) == 0); + REQUIRE_FALSE(output == nullptr); + + REQUIRE_NOTHROW([&env, &output] { + const auto result = nlohmann::json::parse(output); + CHECK_FALSE(result.empty()); + CHECK(result.at(0).at(0).get_ref() == env.rodsHome); + }()); + } + + SECTION("supports nested, multi-argument functions in order-by clause") + { + auto query_string = fmt::format("select concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) where COLL_NAME = '{}' order by concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME))", env.rodsHome); + + Genquery2Input input{}; + input.query_string = query_string.data(); + + char* output{}; + REQUIRE(rc_genquery2(static_cast(conn), &input, &output) == 0); + REQUIRE_FALSE(output == nullptr); + + REQUIRE_NOTHROW([&env, &output] { + const auto result = nlohmann::json::parse(output); + CHECK_FALSE(result.empty()); + const auto expected = fmt::format("{}--{}", env.rodsHome, env.rodsUserName); + CHECK(result.at(0).at(0).get_ref() == expected); + }()); + } }