OLD | NEW |
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 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "webrtc/p2p/base/stun.h" | 13 #include "webrtc/p2p/base/stun.h" |
| 14 #include "webrtc/base/arraysize.h" |
14 #include "webrtc/base/bytebuffer.h" | 15 #include "webrtc/base/bytebuffer.h" |
15 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/messagedigest.h" | 18 #include "webrtc/base/messagedigest.h" |
18 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
19 #include "webrtc/base/socketaddress.h" | 20 #include "webrtc/base/socketaddress.h" |
20 | 21 |
21 namespace cricket { | 22 namespace cricket { |
22 | 23 |
23 class StunTest : public ::testing::Test { | 24 class StunTest : public ::testing::Test { |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 EXPECT_EQ(-1, GetStunSuccessResponseType(STUN_BINDING_RESPONSE)); | 509 EXPECT_EQ(-1, GetStunSuccessResponseType(STUN_BINDING_RESPONSE)); |
509 EXPECT_EQ(-1, GetStunSuccessResponseType(STUN_BINDING_ERROR_RESPONSE)); | 510 EXPECT_EQ(-1, GetStunSuccessResponseType(STUN_BINDING_ERROR_RESPONSE)); |
510 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_INDICATION)); | 511 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_INDICATION)); |
511 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_RESPONSE)); | 512 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_RESPONSE)); |
512 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_ERROR_RESPONSE)); | 513 EXPECT_EQ(-1, GetStunErrorResponseType(STUN_BINDING_ERROR_RESPONSE)); |
513 | 514 |
514 int types[] = { | 515 int types[] = { |
515 STUN_BINDING_REQUEST, STUN_BINDING_INDICATION, | 516 STUN_BINDING_REQUEST, STUN_BINDING_INDICATION, |
516 STUN_BINDING_RESPONSE, STUN_BINDING_ERROR_RESPONSE | 517 STUN_BINDING_RESPONSE, STUN_BINDING_ERROR_RESPONSE |
517 }; | 518 }; |
518 for (int i = 0; i < ARRAY_SIZE(types); ++i) { | 519 for (size_t i = 0; i < arraysize(types); ++i) { |
519 EXPECT_EQ(i == 0, IsStunRequestType(types[i])); | 520 EXPECT_EQ(i == 0U, IsStunRequestType(types[i])); |
520 EXPECT_EQ(i == 1, IsStunIndicationType(types[i])); | 521 EXPECT_EQ(i == 1U, IsStunIndicationType(types[i])); |
521 EXPECT_EQ(i == 2, IsStunSuccessResponseType(types[i])); | 522 EXPECT_EQ(i == 2U, IsStunSuccessResponseType(types[i])); |
522 EXPECT_EQ(i == 3, IsStunErrorResponseType(types[i])); | 523 EXPECT_EQ(i == 3U, IsStunErrorResponseType(types[i])); |
523 EXPECT_EQ(1, types[i] & 0xFEEF); | 524 EXPECT_EQ(1, types[i] & 0xFEEF); |
524 } | 525 } |
525 } | 526 } |
526 | 527 |
527 TEST_F(StunTest, ReadMessageWithIPv4AddressAttribute) { | 528 TEST_F(StunTest, ReadMessageWithIPv4AddressAttribute) { |
528 StunMessage msg; | 529 StunMessage msg; |
529 size_t size = ReadStunMessage(&msg, kStunMessageWithIPv4MappedAddress); | 530 size_t size = ReadStunMessage(&msg, kStunMessageWithIPv4MappedAddress); |
530 CheckStunHeader(msg, STUN_BINDING_RESPONSE, size); | 531 CheckStunHeader(msg, STUN_BINDING_RESPONSE, size); |
531 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); | 532 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); |
532 | 533 |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 rtc::ByteBuffer out2; | 1438 rtc::ByteBuffer out2; |
1438 EXPECT_TRUE(msg2.Write(&out2)); | 1439 EXPECT_TRUE(msg2.Write(&out2)); |
1439 EXPECT_EQ(size, out2.Length()); | 1440 EXPECT_EQ(size, out2.Length()); |
1440 size_t len2 = out2.Length(); | 1441 size_t len2 = out2.Length(); |
1441 std::string outstring2; | 1442 std::string outstring2; |
1442 out2.ReadString(&outstring2, len2); | 1443 out2.ReadString(&outstring2, len2); |
1443 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2)); | 1444 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2)); |
1444 } | 1445 } |
1445 | 1446 |
1446 } // namespace cricket | 1447 } // namespace cricket |
OLD | NEW |