Skip to content

Commit 4632e57

Browse files
committed
add unittest without specialization, make sure that the behaviour is opt-in
1 parent dc6777e commit 4632e57

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/old_tests/UnitTests/TryLookup.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ TEST_CASE("trylookup_from_abi specialization")
189189
REQUIRE_THROWS_AS(map.Lookup(123), hresult_wrong_thread);
190190
}
191191

192+
TEST_CASE("trylookup_from_abi NOT opt-in, no special tag")
193+
{
194+
// Makes sure that an existing TryLookup method is not called without the trylookup_from_abi_t tag.
195+
struct map_without_try_lookup : implements<map_without_try_lookup, IMapView<int, int>>
196+
{
197+
hresult codeToThrow{ S_OK };
198+
std::optional<int> TryLookup(int) // notice no trylookup_from_abi_t, so no opt-in
199+
{
200+
// throw an unexpectd hresult, this should not be called.
201+
throw_hresult(RPC_E_WRONG_THREAD);
202+
}
203+
int Lookup(int) { return 42; } // Behave as if the item was found
204+
205+
int32_t Size() { throw_hresult(E_UNEXPECTED); } // shouldn't be called by the test
206+
bool HasKey(int) { throw_hresult(E_UNEXPECTED); } // shouldn't be called by the test
207+
void Split(IMapView<int, int>&, IMapView<int, int>&) { throw_hresult(E_UNEXPECTED); } // shouldn't be called by the test
208+
};
209+
210+
auto self = make_self<map_without_try_lookup>();
211+
IMapView<int, int> map = *self;
212+
213+
// Make sure that we don't use the TryLookup specialization, we use the Successful Lookup
214+
REQUIRE(map.TryLookup(123).value() == 42);
215+
REQUIRE(map.Lookup(123) == 42);
216+
}
217+
192218
TEST_CASE("trylookup_from_abi specialization with IInspectable")
193219
{
194220
// A map that throws a specific error, used to verify various edge cases.

0 commit comments

Comments
 (0)