Skip to content

Commit

Permalink
Cleanup: Use cookie_to_mock_cookie
Browse files Browse the repository at this point in the history
Use the common method to perform all of the casts as it performs
the appropriate checks that the object is in fact the correct
type (dynamic_cast returning nullptr) and throws an exception
instead of dereferencing nullptr

Change-Id: I0f3e6d5ee48075e651de38ce0078dffb218dae93
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/159076
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
  • Loading branch information
trondn authored and daverigby committed Aug 12, 2021
1 parent c54d300 commit 4f650ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions programs/engine_testapp/engine_testapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,37 +161,34 @@ class MockTestHarness : public test_harness {

void set_ewouldblock_handling(const CookieIface* cookie,
bool enable) override {
const_cast<CookieIface*>(cookie)->setEwouldblock(enable);
cookie_to_mock_cookie(cookie)->setEwouldblock(enable);
}

void set_mutation_extras_handling(const CookieIface* cookie,
bool enable) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))
->setMutationExtrasHandling(enable);
cookie_to_mock_cookie(cookie)->setMutationExtrasHandling(enable);
}

void set_datatype_support(const CookieIface* cookie,
protocol_binary_datatype_t datatypes) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))
->setDatatypeSupport(datatypes);
cookie_to_mock_cookie(cookie)->setDatatypeSupport(datatypes);
}

void set_collections_support(const CookieIface* cookie,
bool enable) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))
->setCollectionsSupport(enable);
cookie_to_mock_cookie(cookie)->setCollectionsSupport(enable);
}

void lock_cookie(const CookieIface* cookie) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))->lock();
cookie_to_mock_cookie(cookie)->lock();
}

void unlock_cookie(const CookieIface* cookie) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))->unlock();
cookie_to_mock_cookie(cookie)->unlock();
}

void waitfor_cookie(const CookieIface* cookie) override {
dynamic_cast<MockCookie*>(const_cast<CookieIface*>(cookie))->wait();
cookie_to_mock_cookie(cookie)->wait();
}

void set_pre_link_function(PreLinkFunction function) override {
Expand Down
2 changes: 1 addition & 1 deletion programs/engine_testapp/mock_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct MockServerCookieApi : public ServerCookieIface {
}

void reserve(const CookieIface& cookie) override {
const_cast<CookieIface&>(cookie).incrementRefcount();
cookie_to_mock_cookie(cookie).incrementRefcount();
}

void release(const CookieIface& cookie) override {
Expand Down

0 comments on commit 4f650ce

Please sign in to comment.