@@ -110,21 +110,37 @@ TEST_CASE("TryRemove")
110110
111111TEST_CASE (" TryLookup TryRemove error" )
112112{
113- // Simulate a non-agile map that is being accessed from the wrong thread.
114- // "Try" operations should throw rather than erroneously report "not found".
115- // Because they didn't even try. The operation never got off the ground.
116- struct incorrectly_used_non_agile_map : implements<incorrectly_used_non_agile_map, IMap<int , int >>
113+ // A map that throws a specific error, used to verify various edge cases.
114+ struct error_map : implements<error_map, IMap<int , int >>
117115 {
118- int Lookup (int ) { throw hresult_wrong_thread (); }
119- int32_t Size () { throw hresult_wrong_thread (); }
120- bool HasKey (int ) { throw hresult_wrong_thread (); }
121- IMapView<int , int > GetView () { throw hresult_wrong_thread (); }
122- bool Insert (int , int ) { throw hresult_wrong_thread (); }
123- void Remove (int ) { throw hresult_wrong_thread (); }
124- void Clear () { throw hresult_wrong_thread (); }
116+ hresult code;
117+ int Lookup (int ) { throw_hresult (code); }
118+ int32_t Size () { throw_hresult (E_UNEXPECTED); } // shouldn't be called by the test
119+ bool HasKey (int ) { throw_hresult (E_UNEXPECTED); } // shouldn't be called by the test
120+ IMapView<int , int > GetView () { throw_hresult (E_UNEXPECTED); } // shouldn't be called by the test
121+ bool Insert (int , int ) { throw_hresult (E_UNEXPECTED); } // shouldn't be called by the test
122+ void Remove (int ) { throw_hresult (code); }
123+ void Clear () { throw_hresult (E_UNEXPECTED); } // shouldn't be called by the test
125124 };
126125
127- auto map = make<incorrectly_used_non_agile_map>();
126+ auto self = make_self<error_map>();
127+ IMap<int , int > map = *self;
128+
129+ // Simulate a non-agile map that is being accessed from the wrong thread.
130+ // "Try" operations should throw rather than erroneously report "not found".
131+ // Because they didn't even try. The operation never got off the ground.
132+ self->code = RPC_E_WRONG_THREAD;
128133 REQUIRE_THROWS_AS (map.TryLookup (123 ), hresult_wrong_thread);
129134 REQUIRE_THROWS_AS (map.TryRemove (123 ), hresult_wrong_thread);
135+
136+ // Some implementations return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
137+ // or E_FAIL when the key is not present.
138+ self->code = HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND);
139+ REQUIRE (!map.TryLookup (123 ));
140+ REQUIRE (!map.TryRemove (123 ));
141+
142+ self->code = E_FAIL;
143+ REQUIRE (!map.TryLookup (123 ));
144+ REQUIRE (!map.TryRemove (123 ));
145+
130146}
0 commit comments