Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: webrtc/pc/srtpfilter_unittest.cc

Issue 2938013003: Delete SignalSrtpError. (Closed)
Patch Set: Delete left-over declaration of set_signal_silent_time. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/base/sigslotrepeater.h ('K') | « webrtc/pc/srtpfilter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 834
835 // Go back to normal sequence nubmer. 835 // Go back to normal sequence nubmer.
836 // NOTE: without the fix in libsrtp, this would fail. This is because 836 // NOTE: without the fix in libsrtp, this would fail. This is because
837 // without the fix, the loop above would keep incrementing local sequence 837 // without the fix, the loop above would keep incrementing local sequence
838 // number in libsrtp, eventually the new sequence number would go out side 838 // number in libsrtp, eventually the new sequence number would go out side
839 // of the window. 839 // of the window.
840 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_small + 1); 840 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_small + 1);
841 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), 841 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_),
842 &out_len)); 842 &out_len));
843 } 843 }
844
845 class SrtpStatTest
846 : public testing::Test,
847 public sigslot::has_slots<> {
848 public:
849 SrtpStatTest()
850 : ssrc_(0U),
851 mode_(-1),
852 error_(cricket::SrtpFilter::ERROR_NONE) {
853 srtp_stat_.SignalSrtpError.connect(this, &SrtpStatTest::OnSrtpError);
854 srtp_stat_.set_signal_silent_time(200);
855 }
856
857 protected:
858 void OnSrtpError(uint32_t ssrc,
859 cricket::SrtpFilter::Mode mode,
860 cricket::SrtpFilter::Error error) {
861 ssrc_ = ssrc;
862 mode_ = mode;
863 error_ = error;
864 }
865 void Reset() {
866 ssrc_ = 0U;
867 mode_ = -1;
868 error_ = cricket::SrtpFilter::ERROR_NONE;
869 }
870
871 cricket::SrtpStat srtp_stat_;
872 uint32_t ssrc_;
873 int mode_;
874 cricket::SrtpFilter::Error error_;
875
876 private:
877 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStatTest);
878 };
879
880 TEST_F(SrtpStatTest, TestProtectRtpError) {
881 Reset();
882 srtp_stat_.AddProtectRtpResult(1, srtp_err_status_ok);
883 EXPECT_EQ(0U, ssrc_);
884 EXPECT_EQ(-1, mode_);
885 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
886 Reset();
887 srtp_stat_.AddProtectRtpResult(1, srtp_err_status_auth_fail);
888 EXPECT_EQ(1U, ssrc_);
889 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
890 EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_);
891 Reset();
892 srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail);
893 EXPECT_EQ(1U, ssrc_);
894 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
895 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
896 // Within 200ms, the error will not be triggered.
897 Reset();
898 srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail);
899 EXPECT_EQ(0U, ssrc_);
900 EXPECT_EQ(-1, mode_);
901 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
902 // Now the error will be triggered again.
903 Reset();
904 rtc::Thread::Current()->SleepMs(210);
905 srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail);
906 EXPECT_EQ(1U, ssrc_);
907 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
908 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
909 }
910
911 TEST_F(SrtpStatTest, TestUnprotectRtpError) {
912 Reset();
913 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_ok);
914 EXPECT_EQ(0U, ssrc_);
915 EXPECT_EQ(-1, mode_);
916 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
917 Reset();
918 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_auth_fail);
919 EXPECT_EQ(1U, ssrc_);
920 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
921 EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_);
922 Reset();
923 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_replay_fail);
924 EXPECT_EQ(1U, ssrc_);
925 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
926 EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_);
927 Reset();
928 rtc::Thread::Current()->SleepMs(210);
929 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_replay_old);
930 EXPECT_EQ(1U, ssrc_);
931 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
932 EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_);
933 Reset();
934 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail);
935 EXPECT_EQ(1U, ssrc_);
936 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
937 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
938 // Within 200ms, the error will not be triggered.
939 Reset();
940 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail);
941 EXPECT_EQ(0U, ssrc_);
942 EXPECT_EQ(-1, mode_);
943 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
944 // Now the error will be triggered again.
945 Reset();
946 rtc::Thread::Current()->SleepMs(210);
947 srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail);
948 EXPECT_EQ(1U, ssrc_);
949 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
950 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
951 }
952
953 TEST_F(SrtpStatTest, TestProtectRtcpError) {
954 Reset();
955 srtp_stat_.AddProtectRtcpResult(srtp_err_status_ok);
956 EXPECT_EQ(-1, mode_);
957 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
958 Reset();
959 srtp_stat_.AddProtectRtcpResult(srtp_err_status_auth_fail);
960 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
961 EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_);
962 Reset();
963 srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail);
964 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
965 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
966 // Within 200ms, the error will not be triggered.
967 Reset();
968 srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail);
969 EXPECT_EQ(-1, mode_);
970 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
971 // Now the error will be triggered again.
972 Reset();
973 rtc::Thread::Current()->SleepMs(210);
974 srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail);
975 EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_);
976 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
977 }
978
979 TEST_F(SrtpStatTest, TestUnprotectRtcpError) {
980 Reset();
981 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_ok);
982 EXPECT_EQ(-1, mode_);
983 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
984 Reset();
985 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_auth_fail);
986 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
987 EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_);
988 Reset();
989 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_replay_fail);
990 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
991 EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_);
992 Reset();
993 rtc::Thread::Current()->SleepMs(210);
994 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_replay_fail);
995 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
996 EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_);
997 Reset();
998 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
999 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
1000 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
1001 // Within 200ms, the error will not be triggered.
1002 Reset();
1003 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1004 EXPECT_EQ(-1, mode_);
1005 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
1006 // Now the error will be triggered again.
1007 Reset();
1008 rtc::Thread::Current()->SleepMs(210);
1009 srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail);
1010 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
1011 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
1012 }
OLDNEW
« webrtc/base/sigslotrepeater.h ('K') | « webrtc/pc/srtpfilter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698