| 48 | } |
| 49 | |
| 50 | TEST_P(TestRegistry, Basics) { |
| 51 | auto registry_factory = std::get<0>(GetParam()); |
| 52 | auto registry_ = registry_factory(); |
| 53 | auto get_num_funcs = std::get<1>(GetParam()); |
| 54 | int n_funcs = get_num_funcs(); |
| 55 | auto get_func_names = std::get<2>(GetParam()); |
| 56 | std::vector<std::string> func_names = get_func_names(); |
| 57 | ASSERT_EQ(n_funcs, registry_->num_functions()); |
| 58 | |
| 59 | std::shared_ptr<Function> func = std::make_shared<ScalarFunction>( |
| 60 | "f1", Arity::Unary(), /*doc=*/FunctionDoc::Empty()); |
| 61 | ASSERT_OK(registry_->AddFunction(func)); |
| 62 | ASSERT_EQ(n_funcs + 1, registry_->num_functions()); |
| 63 | |
| 64 | func = std::make_shared<VectorFunction>("f0", Arity::Binary(), |
| 65 | /*doc=*/FunctionDoc::Empty()); |
| 66 | ASSERT_OK(registry_->AddFunction(func)); |
| 67 | ASSERT_EQ(n_funcs + 2, registry_->num_functions()); |
| 68 | |
| 69 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<const Function> f1, registry_->GetFunction("f1")); |
| 70 | ASSERT_EQ("f1", f1->name()); |
| 71 | |
| 72 | // Nonexistent function |
| 73 | ASSERT_RAISES(KeyError, registry_->GetFunction("f2")); |
| 74 | |
| 75 | // Try adding a function with name collision |
| 76 | func = std::make_shared<ScalarAggregateFunction>("f1", Arity::Unary(), |
| 77 | /*doc=*/FunctionDoc::Empty()); |
| 78 | ASSERT_RAISES(KeyError, registry_->AddFunction(func)); |
| 79 | |
| 80 | // Allow overwriting by flag |
| 81 | ASSERT_OK(registry_->AddFunction(func, /*allow_overwrite=*/true)); |
| 82 | ASSERT_OK_AND_ASSIGN(f1, registry_->GetFunction("f1")); |
| 83 | ASSERT_EQ(Function::SCALAR_AGGREGATE, f1->kind()); |
| 84 | |
| 85 | std::vector<std::string> expected_names(func_names); |
| 86 | for (auto name : {"f0", "f1"}) { |
| 87 | expected_names.push_back(name); |
| 88 | } |
| 89 | std::sort(expected_names.begin(), expected_names.end()); |
| 90 | ASSERT_EQ(expected_names, registry_->GetFunctionNames()); |
| 91 | |
| 92 | // Aliases |
| 93 | ASSERT_RAISES(KeyError, registry_->AddAlias("f33", "f3")); |
| 94 | ASSERT_OK(registry_->AddAlias("f11", "f1")); |
| 95 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<const Function> f2, registry_->GetFunction("f11")); |
| 96 | ASSERT_EQ(func, f2); |
| 97 | } |
| 98 | |
| 99 | // Define a custom print since the default Googletest print trips Valgrind |
| 100 | void PrintTo(const TestRegistryParams& param, std::ostream* os) { |
| 101 | (*os) << "TestRegistryParams{" |
| 102 | << "get_num_funcs()=" << std::get<1>(param)() << ", get_func_names()="; |
| 103 | for (std::string func_name : std::get<2>(param)()) { |
| 104 | (*os) << func_name; |
| 105 | } |
| 106 | (*os) << ", name=" << std::get<3>(param) << "}"; |
| 107 | } |
nothing calls this directly
no test coverage detected