1717#include < gtest/gtest.h>
1818#include < livekit/livekit.h>
1919
20+ #include < chrono>
21+ #include < string>
22+
23+ #include " ffi.pb.h"
24+ #include " room_proto_converter.h"
25+
2026namespace livekit ::test {
2127
2228class RoomTest : public ::testing::Test {
@@ -31,6 +37,8 @@ TEST_F(RoomTest, ConnectWithoutInitialize) {
3137 livekit::shutdown ();
3238
3339 Room room;
40+
41+ // Default room options okay here, will return before FFI layer since not initialized
3442 bool result = room.connect (" wss://localhost:7880" , " test" , livekit::RoomOptions ());
3543 EXPECT_FALSE (result) << " Connecting without initializing should return false" ;
3644 EXPECT_TRUE (room.localParticipant ().expired ()) << " Local participant should be empty after failed connect" ;
@@ -47,9 +55,104 @@ TEST_F(RoomTest, RoomOptionsDefaults) {
4755 RoomOptions options;
4856
4957 EXPECT_TRUE (options.auto_subscribe ) << " auto_subscribe should default to true" ;
58+ EXPECT_FALSE (options.adaptive_stream .has_value ()) << " adaptive_stream should defer to Rust default" ;
5059 EXPECT_FALSE (options.dynacast ) << " dynacast should default to false" ;
51- EXPECT_FALSE (options.rtc_config .has_value ()) << " rtc_config should not have a value by default" ;
5260 EXPECT_FALSE (options.encryption .has_value ()) << " encryption should not have a value by default" ;
61+ EXPECT_FALSE (options.rtc_config .has_value ()) << " rtc_config should not have a value by default" ;
62+ EXPECT_FALSE (options.join_retries .has_value ()) << " join_retries should defer to Rust default" ;
63+ EXPECT_TRUE (options.single_peer_connection ) << " single_peer_connection should default to true" ;
64+ EXPECT_FALSE (options.connect_timeout .has_value ()) << " connect_timeout should defer to Rust default" ;
65+ }
66+
67+ TEST_F (RoomTest, RoomOptionsToProtoSerializesDefaults) {
68+ const proto::RoomOptions proto_options = toProto (RoomOptions{});
69+
70+ EXPECT_TRUE (proto_options.has_auto_subscribe ());
71+ EXPECT_TRUE (proto_options.auto_subscribe ());
72+ EXPECT_FALSE (proto_options.has_adaptive_stream ());
73+ EXPECT_TRUE (proto_options.has_dynacast ());
74+ EXPECT_FALSE (proto_options.dynacast ());
75+ EXPECT_FALSE (proto_options.has_encryption ());
76+ EXPECT_FALSE (proto_options.has_rtc_config ());
77+ EXPECT_FALSE (proto_options.has_join_retries ());
78+ EXPECT_TRUE (proto_options.has_single_peer_connection ());
79+ EXPECT_TRUE (proto_options.single_peer_connection ());
80+ EXPECT_FALSE (proto_options.has_connect_timeout_ms ());
81+ }
82+
83+ TEST_F (RoomTest, RoomOptionsProtoConverter) {
84+ RoomOptions options;
85+ options.auto_subscribe = false ;
86+ options.adaptive_stream = true ;
87+ options.dynacast = true ;
88+ E2EEOptions encryption;
89+ encryption.key_provider_options .shared_key = std::vector<std::uint8_t >{' s' , ' e' , ' c' , ' r' , ' e' , ' t' };
90+ options.encryption = encryption;
91+ RtcConfig rtc_config;
92+ rtc_config.ice_transport_type = proto::TRANSPORT_ALL ;
93+ rtc_config.continual_gathering_policy = proto::GATHER_CONTINUALLY ;
94+ rtc_config.ice_servers .push_back ({" stun:stun.l.google.com:19302" , " " , " " });
95+ rtc_config.ice_servers .push_back ({" turn:turn.example.com:3478" , " user" , " pass" });
96+ options.rtc_config = rtc_config;
97+ options.join_retries = 8 ;
98+ options.single_peer_connection = false ;
99+ options.connect_timeout = std::chrono::milliseconds (750 );
100+
101+ const proto::RoomOptions proto_options = toProto (options);
102+
103+ EXPECT_TRUE (proto_options.has_auto_subscribe ());
104+ EXPECT_FALSE (proto_options.auto_subscribe ());
105+ EXPECT_TRUE (proto_options.has_adaptive_stream ());
106+ EXPECT_TRUE (proto_options.adaptive_stream ());
107+ EXPECT_TRUE (proto_options.has_dynacast ());
108+ EXPECT_TRUE (proto_options.dynacast ());
109+ ASSERT_TRUE (proto_options.has_encryption ());
110+ EXPECT_EQ (proto_options.encryption ().encryption_type (),
111+ static_cast <proto::EncryptionType>(encryption.encryption_type ));
112+ ASSERT_TRUE (proto_options.encryption ().has_key_provider_options ());
113+ EXPECT_EQ (proto_options.encryption ().key_provider_options ().shared_key (), " secret" );
114+ ASSERT_TRUE (proto_options.has_rtc_config ());
115+ EXPECT_EQ (proto_options.rtc_config ().ice_transport_type (), proto::TRANSPORT_ALL );
116+ EXPECT_EQ (proto_options.rtc_config ().continual_gathering_policy (), proto::GATHER_CONTINUALLY );
117+ ASSERT_EQ (proto_options.rtc_config ().ice_servers_size (), 2 );
118+ EXPECT_EQ (proto_options.rtc_config ().ice_servers (0 ).urls (0 ), " stun:stun.l.google.com:19302" );
119+ EXPECT_EQ (proto_options.rtc_config ().ice_servers (1 ).urls (0 ), " turn:turn.example.com:3478" );
120+ EXPECT_EQ (proto_options.rtc_config ().ice_servers (1 ).username (), " user" );
121+ EXPECT_EQ (proto_options.rtc_config ().ice_servers (1 ).password (), " pass" );
122+ EXPECT_TRUE (proto_options.has_join_retries ());
123+ EXPECT_EQ (proto_options.join_retries (), 8U );
124+ EXPECT_TRUE (proto_options.has_single_peer_connection ());
125+ EXPECT_FALSE (proto_options.single_peer_connection ());
126+ EXPECT_TRUE (proto_options.has_connect_timeout_ms ());
127+ EXPECT_EQ (proto_options.connect_timeout_ms (), 750U );
128+ }
129+
130+ TEST (RoomOptionsProtoTest, ConnectRequestSerializesRetryOptions) {
131+ RoomOptions options;
132+ options.join_retries = 8 ;
133+ options.connect_timeout = std::chrono::milliseconds (750 );
134+
135+ proto::FfiRequest request;
136+ auto * connect = request.mutable_connect ();
137+ connect->set_url (" ws://localhost:7880" );
138+ connect->set_token (" test-token" );
139+ connect->mutable_options ()->CopyFrom (toProto (options));
140+
141+ ASSERT_TRUE (connect->options ().has_join_retries ());
142+ EXPECT_EQ (connect->options ().join_retries (), 8U );
143+ ASSERT_TRUE (connect->options ().has_connect_timeout_ms ());
144+ EXPECT_EQ (connect->options ().connect_timeout_ms (), 750U );
145+
146+ ASSERT_TRUE (request.IsInitialized ()) << request.InitializationErrorString ();
147+
148+ std::string serialized;
149+ ASSERT_TRUE (request.SerializeToString (&serialized));
150+ EXPECT_FALSE (serialized.empty ());
151+
152+ proto::FfiRequest decoded;
153+ ASSERT_TRUE (decoded.ParseFromString (serialized));
154+ EXPECT_EQ (decoded.connect ().options ().join_retries (), 8U );
155+ EXPECT_EQ (decoded.connect ().options ().connect_timeout_ms (), 750U );
53156}
54157
55158TEST_F (RoomTest, RtcConfigDefaults) {
0 commit comments