|
| 1 | +/* |
| 2 | + * Copyright 2026 LiveKit |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +#include <memory> |
| 20 | +#include <string> |
| 21 | + |
| 22 | +#include "../common/audio_utils.h" |
| 23 | +#include "../common/test_common.h" |
| 24 | + |
| 25 | +namespace livekit::test { |
| 26 | +namespace { |
| 27 | + |
| 28 | +void expectTrackSidAssigned(const Track& track, const LocalTrackPublication& publication) { |
| 29 | + const std::string& track_sid = track.sid(); |
| 30 | + const std::string& publication_sid = publication.sid(); |
| 31 | + EXPECT_NE(track_sid, "TR_unknown"); |
| 32 | + EXPECT_FALSE(track_sid.empty()); |
| 33 | + EXPECT_EQ(track_sid, publication_sid); |
| 34 | +} |
| 35 | + |
| 36 | +} // namespace |
| 37 | + |
| 38 | +class LocalTrackPublishSidTest : public LiveKitTestBase {}; |
| 39 | + |
| 40 | +TEST_F(LocalTrackPublishSidTest, PublishVideoTrackAssignsSid) { |
| 41 | + failIfNotConfigured(); |
| 42 | + |
| 43 | + Room room; |
| 44 | + const RoomOptions room_options; |
| 45 | + ASSERT_TRUE(room.connect(config_.url, config_.token_a, room_options)); |
| 46 | + |
| 47 | + auto source = std::make_shared<EncodedVideoSource>(VideoCodec::H264, 16, 16); |
| 48 | + std::shared_ptr<LocalVideoTrack> track; |
| 49 | + ASSERT_NO_THROW( |
| 50 | + track = lockLocalParticipant(room)->publishVideoTrack("video-sid-check", source, TrackSource::SOURCE_CAMERA)); |
| 51 | + ASSERT_NE(track, nullptr); |
| 52 | + ASSERT_NE(track->publication(), nullptr); |
| 53 | + |
| 54 | + expectTrackSidAssigned(*track, *track->publication()); |
| 55 | + lockLocalParticipant(room)->unpublishTrack(track->publication()->sid()); |
| 56 | +} |
| 57 | + |
| 58 | +TEST_F(LocalTrackPublishSidTest, PublishAudioTrackAssignsSid) { |
| 59 | + failIfNotConfigured(); |
| 60 | + |
| 61 | + Room room; |
| 62 | + const RoomOptions room_options; |
| 63 | + ASSERT_TRUE(room.connect(config_.url, config_.token_a, room_options)); |
| 64 | + |
| 65 | + auto source = std::make_shared<AudioSource>(kDefaultAudioSampleRate, kDefaultAudioChannels, 0); |
| 66 | + std::shared_ptr<LocalAudioTrack> track; |
| 67 | + ASSERT_NO_THROW( |
| 68 | + track = lockLocalParticipant(room)->publishAudioTrack("audio-sid-check", source, TrackSource::SOURCE_MICROPHONE)); |
| 69 | + ASSERT_NE(track, nullptr); |
| 70 | + ASSERT_NE(track->publication(), nullptr); |
| 71 | + |
| 72 | + expectTrackSidAssigned(*track, *track->publication()); |
| 73 | + lockLocalParticipant(room)->unpublishTrack(track->publication()->sid()); |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace livekit::test |
0 commit comments