diff options
Diffstat (limited to 'test/test_srtp.cc')
-rw-r--r-- | test/test_srtp.cc | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/test/test_srtp.cc b/test/test_srtp.cc index 962c18f..c7b82e5 100644 --- a/test/test_srtp.cc +++ b/test/test_srtp.cc @@ -25,6 +25,8 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <cppunit/extensions/HelperMacros.h> + #include <stdio.h> #include "../src/rtp.h" @@ -33,55 +35,56 @@ #define KEY "123456789012345678901234567890123456789012345678901234567890" #define SSRC 1234567890 -void dump(const char *title, const char *buf, size_t size) -{ - printf("%12s: ", title); - for(int i = 0; i < size; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", (unsigned char)*buf++); - } - printf("\n"); -} - -int main() +class test_srtp_class : public CppUnit::TestFixture { - RTP rtp; - rtp.setSSrc(SSRC); + CPPUNIT_TEST_SUITE(test_srtp_class); + CPPUNIT_TEST(test_srtp); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_srtp() { + RTP rtp; + rtp.setSSrc(SSRC); + + char payload[] = { 0xde, 0xad, 0xbe, 0xef }; + rtp.setPayload(payload, sizeof(payload)); - char payload[] = { 0xde, 0xad, 0xbe, 0xef }; - rtp.setPayload(payload, sizeof(payload)); + char buf[MAX_RTP_PACKET_SIZE]; + size_t sz = rtp.packet(buf, sizeof(buf)); - char buf[MAX_RTP_PACKET_SIZE]; - size_t sz = rtp.packet(buf, sizeof(buf)); + //dump("Vanilla", buf, sz); - dump("Vanilla", buf, sz); + { + SRTP srtp(KEY, rtp.SSrc()); + sz = srtp.encrypt(buf, sz); + } - { - SRTP srtp(KEY, rtp.SSrc()); - sz = srtp.encrypt(buf, sz); - } + //dump("Encrypted", buf, sz); - dump("Encrypted", buf, sz); + { + SRTP srtp(KEY, rtp.SSrc()); + sz = srtp.decrypt(buf, sz); + } - { - SRTP srtp(KEY, rtp.SSrc()); - sz = srtp.decrypt(buf, sz); - } + //dump("Decrypted", buf, sz); + //printf("Compare:\n"); + char buf0[MAX_RTP_PACKET_SIZE]; + size_t sz0 = rtp.packet(buf0, sizeof(buf0)); - dump("Decrypted", buf, sz); + CPPUNIT_ASSERT_EQUAL(sz, sz0); - printf("Compare:\n"); - char buf0[MAX_RTP_PACKET_SIZE]; - size_t sz0 = rtp.packet(buf0, sizeof(buf0)); - if(sz0 != sz) printf("Sizes differ (%d %d)...\n", sz0, sz); - unsigned int sum = 0; - for(int i = 0; i < sz0; i++) { - sum += abs(buf0[i] - buf[i]); - } - if(sum) printf("NOT EQUAL! diff = %d\n", sum); - else printf("Vanilla == Decrypted\n"); + int err = 0; + for(int i = 0; i < sz0; i++) { + err += abs(buf0[i] - buf[i]); + } - return 0; -} + CPPUNIT_ASSERT_EQUAL(0, err); + } +}; +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_srtp_class); |