add WebRTC tests
This commit is contained in:
74
tests/integration/test_webrtc_smoke.zig
Normal file
74
tests/integration/test_webrtc_smoke.zig
Normal file
@@ -0,0 +1,74 @@
|
||||
//! WebRTC Smoke Test — verify libdatachannel lifecycle works.
|
||||
//!
|
||||
//! Tests: rtcPreload → createPeerConnection → createDataChannel → close → delete → rtcCleanup
|
||||
//! Requires: libdatachannel.dylib available (via WEBRTC_LIB_PATH or next to binary)
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const webrtc = @import("webrtc");
|
||||
const rtc = webrtc.rtc;
|
||||
|
||||
test "webrtc smoke: lifecycle does not crash" {
|
||||
// Load the WebRTC library at runtime
|
||||
if (!rtc.load()) return error.SkipZigTest;
|
||||
|
||||
rtc.rtcInitLogger(.warning, null);
|
||||
rtc.rtcPreload();
|
||||
defer rtc.rtcCleanup();
|
||||
|
||||
// Create PeerConnection with no ICE servers (loopback)
|
||||
var config = rtc.Configuration{};
|
||||
_ = &config;
|
||||
|
||||
const pc_id = rtc.rtcCreatePeerConnection(&config);
|
||||
try testing.expect(pc_id >= 0);
|
||||
|
||||
// Create DataChannel
|
||||
const dc_id = rtc.rtcCreateDataChannel(pc_id, "test");
|
||||
try testing.expect(dc_id >= 0);
|
||||
|
||||
// Close and delete
|
||||
_ = rtc.rtcClose(dc_id);
|
||||
_ = rtc.rtcDelete(dc_id);
|
||||
_ = rtc.rtcClosePeerConnection(pc_id);
|
||||
_ = rtc.rtcDeletePeerConnection(pc_id);
|
||||
}
|
||||
|
||||
test "webrtc smoke: ChannelState init and deinit" {
|
||||
const allocator = testing.allocator;
|
||||
|
||||
var cs = webrtc.ChannelState.init(allocator, 42);
|
||||
defer cs.deinit();
|
||||
|
||||
// Verify initial state
|
||||
try testing.expectEqual(rtc.State.new, cs.state.load(.acquire));
|
||||
try testing.expect(!cs.dc_open.load(.acquire));
|
||||
try testing.expect(cs.getLocalSdp() == null);
|
||||
}
|
||||
|
||||
test "webrtc smoke: NativeWebRTCManager createOffer generates SDP" {
|
||||
var mgr = webrtc.NativeWebRTCManager.init(testing.allocator) catch |err| switch (err) {
|
||||
error.WebRTCUnavailable => return error.SkipZigTest,
|
||||
};
|
||||
defer mgr.deinit();
|
||||
|
||||
rtc.rtcInitLogger(.warning, null);
|
||||
|
||||
const cs = try mgr.createOffer(null);
|
||||
defer mgr.destroyChannel(cs);
|
||||
|
||||
// Wait for SDP to be generated (up to 2 seconds)
|
||||
var waited: usize = 0;
|
||||
while (cs.getLocalSdp() == null and waited < 200) : (waited += 1) {
|
||||
std.Thread.sleep(10 * std.time.ns_per_ms);
|
||||
}
|
||||
|
||||
// Should have an SDP
|
||||
const sdp = cs.getLocalSdp();
|
||||
try testing.expect(sdp != null);
|
||||
|
||||
// SDP should contain "v=0" (SDP version line)
|
||||
if (sdp) |s| {
|
||||
try testing.expect(std.mem.indexOf(u8, s, "v=0") != null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user