Skip to content

Commit 585bc4c

Browse files
cleaner tests
1 parent 028ea3b commit 585bc4c

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎src/tests/common/test_common.h‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ inline bool waitForParticipant(Room* room, const std::string& identity, std::chr
145145
/// lock() blindly is undefined behavior, so tests must go through this helper,
146146
/// which throws instead of crashing when the handle is expired.
147147
inline std::shared_ptr<LocalParticipant> lockLocalParticipant(const Room& room) {
148-
auto participant = room.localParticipant().lock();
149-
if (!participant) {
150-
throw std::runtime_error("Local participant handle is expired");
148+
if (auto participant = room.localParticipant().lock()) {
149+
return participant;
151150
}
152-
return participant;
151+
throw std::runtime_error("Local participant handle is expired");
153152
}
154153

155154
/// Pointer overload of lockLocalParticipant(); throws if @p room is null.
@@ -166,11 +165,10 @@ inline std::shared_ptr<LocalParticipant> lockLocalParticipant(const Room* room)
166165
/// std::weak_ptr that lock()s to nullptr once the participant disconnects, so
167166
/// this helper throws rather than letting callers dereference a null pointer.
168167
inline std::shared_ptr<RemoteParticipant> lockRemoteParticipant(const Room& room, const std::string& identity) {
169-
auto participant = room.remoteParticipant(identity).lock();
170-
if (!participant) {
171-
throw std::runtime_error("Remote participant '" + identity + "' handle is expired");
168+
if (auto participant = room.remoteParticipant(identity).lock()) {
169+
return participant;
172170
}
173-
return participant;
171+
throw std::runtime_error("Remote participant '" + identity + "' handle is expired");
174172
}
175173

176174
/// Pointer overload of lockRemoteParticipant(); throws if @p room is null.

0 commit comments

Comments
 (0)