-
Notifications
You must be signed in to change notification settings - Fork 548
v1: uri (CXX-3237, CXX-3238) #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kevinAlbs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor comments.
| uri const opts; | ||
| auto const identity = uri::internal::as_mongoc(opts); | ||
|
|
||
| char const str = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: also test C function returning NULL causes C++ member function to return unset optional:
template <typename MemFn, typename Mock>
void test_string_opt(MemFn mem_fn, Mock& mock) {
uri const opts;
auto const identity = uri::internal::as_mongoc(opts);
auto const v = GENERATE(bsoncxx::v1::stdx::optional<char const>{}, bsoncxx::v1::stdx::optional<char const>{'\0'});
auto fn = mock.create_instance();
fn->interpose([&](mongoc_uri_t const* ptr) -> char const* {
CHECK(ptr == identity);
if (v.has_value()) {
return &(*v);
}
return nullptr;
});
auto const opt = (opts.*mem_fn)();
if (v.has_value()) {
REQUIRE(opt.has_value());
CHECK(opt->data() == static_cast<void const*>(&(*v)));
} else {
CHECK(!opt.has_value());
}
}| } | ||
|
|
||
| template <typename MemFn, typename Mock> | ||
| void test_doc_opt(MemFn mem_fn, Mock& mock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: also test C function returning NULL causes C++ member function to return unset optional:
template <typename MemFn, typename Mock>
void test_doc_opt(MemFn mem_fn, Mock& mock) {
uri const opts;
auto const identity = uri::internal::as_mongoc(opts);
auto const v =
GENERATE(bsoncxx::v1::stdx::optional<scoped_bson>{}, bsoncxx::v1::stdx::optional<scoped_bson>{R"({"x": 1})"});
auto fn = mock.create_instance();
fn->interpose([&](mongoc_uri_t const* ptr) -> bson_t const* {
CHECK(ptr == identity);
if (v.has_value()) {
return v->bson();
}
return nullptr;
});
auto const opt = (opts.*mem_fn)();
if (v.has_value()) {
REQUIRE(opt.has_value());
CHECK(opt->data() == v->view().data());
} else {
CHECK(!opt.has_value());
}
}| } | ||
| } | ||
|
|
||
| TEST_CASE("exceptions", "[bsoncxx][v1][uri]") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| TEST_CASE("exceptions", "[bsoncxx][v1][uri]") { | |
| TEST_CASE("exceptions", "[mongocxx][v1][uri]") { |
| CHECK_FALSE(opts.retry_reads().has_value()); | ||
| CHECK_FALSE(opts.retry_writes().has_value()); | ||
| CHECK_FALSE(opts.server_selection_timeout_ms().has_value()); | ||
| CHECK_FALSE(opts.server_selection_try_once().has_value()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate check.
| CHECK_FALSE(opts.server_selection_try_once().has_value()); |
| /// @par Postconditions: | ||
| /// - `other` is in an assign-or-destroy-only state. | ||
| /// | ||
| /// @warning Invalidates all associated iterators and views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove non-applicable docs.
| /// @par Postconditions: | |
| /// - `other` is in an assign-or-destroy-only state. | |
| /// | |
| /// @warning Invalidates all associated iterators and views. |
| template <typename T> | ||
| bsoncxx::v1::stdx::optional<T> get_credentials_field(mongoc_uri_t const* uri, char const* field); | ||
|
|
||
| template <> | ||
| bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view> get_credentials_field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary template? I expect it is not needed since there is only one specialization.
| template <typename T> | |
| bsoncxx::v1::stdx::optional<T> get_credentials_field(mongoc_uri_t const* uri, char const* field); | |
| template <> | |
| bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view> get_credentials_field( | |
| bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view> get_credentials_field( |
Resolves CXX-3237 and CXX-3238 for the
v1::uricomponent.To continue to support implicit conversion from e.g.
char const* -> string::view_or_valuewithout ambiguity with the v1 ctor (becausev1::urialso has a non-explicitstring_viewctor), a constrained non-explicit constructor template is added to have higher priority for convertible-to-string::view_or_valuearguments than the non-explicit v1 ctor.This PR also adds
/Zc:strictStrings(part of/permissive-, which we do not yet enable) to avoid non-conforming behavior with MSVC which interacts poorly with ourvoid*ctor (even when private or explicit). This flag is applied to mongocxx library (and test) builds only and is not inherited by users. We can consider adding achar const*ctor instead, but I'd prefer depending on and encouraging standard conformance instead.Additional notes:
v1bsoncxx API instead of bson when able; however, cannot use bsoncxx for URI field lookup due to backward compatibility with case (in)sensitivity lookups. Not all options may support canonicalization into lowercase form.v_noabi::uriremains non-copyable for backward compatibility despitev1::uribeing copyable.