diff options
author | mostynb@opera.com <mostynb@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 21:52:19 +0000 |
---|---|---|
committer | mostynb@opera.com <mostynb@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 21:52:19 +0000 |
commit | 6bdd375080bd308abd3827209fa78d1ee70a69b8 (patch) | |
tree | 8cc5963f75fde7f1364ee1231afa4b8d64f92004 /net/dns | |
parent | c50199a5a71577f053b43e40dac73539c8f1843a (diff) | |
download | chromium_src-6bdd375080bd308abd3827209fa78d1ee70a69b8.zip chromium_src-6bdd375080bd308abd3827209fa78d1ee70a69b8.tar.gz chromium_src-6bdd375080bd308abd3827209fa78d1ee70a69b8.tar.bz2 |
avoid char+'\xHH' as it's too easy to use values > 127
TEST=net_unittests
Review URL: https://chromiumcodereview.appspot.com/21534003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215124 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns')
-rw-r--r-- | net/dns/mdns_client_unittest.cc | 496 | ||||
-rw-r--r-- | net/dns/mock_mdns_socket_factory.cc | 2 | ||||
-rw-r--r-- | net/dns/mock_mdns_socket_factory.h | 2 | ||||
-rw-r--r-- | net/dns/record_parsed_unittest.cc | 30 | ||||
-rw-r--r-- | net/dns/record_rdata_unittest.cc | 102 |
5 files changed, 321 insertions, 311 deletions
diff --git a/net/dns/mdns_client_unittest.cc b/net/dns/mdns_client_unittest.cc index cbe464a..324b4df 100644 --- a/net/dns/mdns_client_unittest.cc +++ b/net/dns/mdns_client_unittest.cc @@ -28,311 +28,315 @@ namespace net { namespace { -const char kSamplePacket1[] = { +const uint8 kSamplePacket1[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x00', // TTL (4 bytes) is 1 second; - '\x00', '\x01', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x00, // TTL (4 bytes) is 1 second; + 0x00, 0x01, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x0c, // Answer 2 - '\x08', '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', - '\xc0', '\x14', // Pointer to "._tcp.local" - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. - '\x24', '\x75', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x32' + 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', + 0xc0, 0x14, // Pointer to "._tcp.local" + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. + 0x24, 0x75, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x32 }; -const char kCorruptedPacketBadQuestion[] = { +const uint8 kCorruptedPacketBadQuestion[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x01', // One question - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x01, // One question + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Question is corrupted and cannot be read. - '\x99', 'h', 'e', 'l', 'l', 'o', - '\x00', - '\x00', '\x00', - '\x00', '\x00', + 0x99, 'h', 'e', 'l', 'l', 'o', + 0x00, + 0x00, 0x00, + 0x00, 0x00, // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x99', // RDLENGTH is impossible - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x99, // RDLENGTH is impossible + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x0c, // Answer 2 - '\x08', '_', 'p', 'r', // Useless trailing data. + 0x08, '_', 'p', 'r', // Useless trailing data. }; -const char kCorruptedPacketUnsalvagable[] = { +const uint8 kCorruptedPacketUnsalvagable[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x99', // RDLENGTH is impossible - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x99, // RDLENGTH is impossible + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x0c, // Answer 2 - '\x08', '_', 'p', 'r', // Useless trailing data. + 0x08, '_', 'p', 'r', // Useless trailing data. }; -const char kCorruptedPacketDoubleRecord[] = { +const uint8 kCorruptedPacketDoubleRecord[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x06', 'p', 'r', 'i', 'v', 'e', 't', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x01', // TYPE is A. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x04', // RDLENGTH is 4 - '\x05', '\x03', - '\xc0', '\x0c', + 0x06, 'p', 'r', 'i', 'v', 'e', 't', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x01, // TYPE is A. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x04, // RDLENGTH is 4 + 0x05, 0x03, + 0xc0, 0x0c, // Answer 2 -- Same key - '\x06', 'p', 'r', 'i', 'v', 'e', 't', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x01', // TYPE is A. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x04', // RDLENGTH is 4 - '\x02', '\x03', - '\x04', '\x05', + 0x06, 'p', 'r', 'i', 'v', 'e', 't', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x01, // TYPE is A. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x04, // RDLENGTH is 4 + 0x02, 0x03, + 0x04, 0x05, }; -const char kCorruptedPacketSalvagable[] = { +const uint8 kCorruptedPacketSalvagable[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x99', 'h', 'e', 'l', 'l', 'o', // Bad RDATA format. - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x99, 'h', 'e', 'l', 'l', 'o', // Bad RDATA format. + 0xc0, 0x0c, // Answer 2 - '\x08', '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', - '\xc0', '\x14', // Pointer to "._tcp.local" - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. - '\x24', '\x75', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x32' + 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', + 0xc0, 0x14, // Pointer to "._tcp.local" + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 49 seconds. + 0x24, 0x75, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x32 }; -const char kSamplePacket2[] = { +const uint8 kSamplePacket2[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x02', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x02, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'z', 'z', 'z', 'z', 'z', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'z', 'z', 'z', 'z', 'z', + 0xc0, 0x0c, // Answer 2 - '\x08', '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', - '\xc0', '\x14', // Pointer to "._tcp.local" - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'z', 'z', 'z', 'z', 'z', - '\xc0', '\x32' + 0x08, '_', 'p', 'r', 'i', 'n', 't', 'e', 'r', + 0xc0, 0x14, // Pointer to "._tcp.local" + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'z', 'z', 'z', 'z', 'z', + 0xc0, 0x32 }; -const char kQueryPacketPrivet[] = { +const uint8 kQueryPacketPrivet[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x00', '\x00', // No flags. - '\x00', '\x01', // One question. - '\x00', '\x00', // 0 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x00, 0x00, // No flags. + 0x00, 0x01, // One question. + 0x00, 0x00, // 0 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Question // This part is echoed back from the respective query. - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. }; -const char kSamplePacketAdditionalOnly[] = { +const uint8 kSamplePacketAdditionalOnly[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x00', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x01', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x00, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x01, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'h', 'e', 'l', 'l', 'o', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'h', 'e', 'l', 'l', 'o', + 0xc0, 0x0c, }; -const char kSamplePacketNsec[] = { +const uint8 kSamplePacketNsec[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x01', // 1 RR (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x01, // 1 RR (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x2f', // TYPE is NSEC. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x06', // RDLENGTH is 6 bytes. - '\xc0', '\x0c', - '\x00', '\x02', '\x00', '\x08' // Only A record present + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x2f, // TYPE is NSEC. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x06, // RDLENGTH is 6 bytes. + 0xc0, 0x0c, + 0x00, 0x02, 0x00, 0x08 // Only A record present }; -const char kSamplePacketAPrivet[] = { +const uint8 kSamplePacketAPrivet[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x01', // 1 RR (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x01, // 1 RR (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x01', // TYPE is A. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x04', // RDLENGTH is 4 bytes. - '\xc0', '\x0c', - '\x00', '\x02', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x01, // TYPE is A. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x04, // RDLENGTH is 4 bytes. + 0xc0, 0x0c, + 0x00, 0x02, }; -const char kSamplePacketGoodbye[] = { +const uint8 kSamplePacketGoodbye[] = { // Header - '\x00', '\x00', // ID is zeroed out - '\x81', '\x80', // Standard query response, RA, no error - '\x00', '\x00', // No questions (for simplicity) - '\x00', '\x01', // 2 RRs (answers) - '\x00', '\x00', // 0 authority RRs - '\x00', '\x00', // 0 additional RRs + 0x00, 0x00, // ID is zeroed out + 0x81, 0x80, // Standard query response, RA, no error + 0x00, 0x00, // No questions (for simplicity) + 0x00, 0x01, // 2 RRs (answers) + 0x00, 0x00, // 0 authority RRs + 0x00, 0x00, // 0 additional RRs // Answer 1 - '\x07', '_', 'p', 'r', 'i', 'v', 'e', 't', - '\x04', '_', 't', 'c', 'p', - '\x05', 'l', 'o', 'c', 'a', 'l', - '\x00', - '\x00', '\x0c', // TYPE is PTR. - '\x00', '\x01', // CLASS is IN. - '\x00', '\x00', // TTL (4 bytes) is zero; - '\x00', '\x00', - '\x00', '\x08', // RDLENGTH is 8 bytes. - '\x05', 'z', 'z', 'z', 'z', 'z', - '\xc0', '\x0c', + 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', + 0x04, '_', 't', 'c', 'p', + 0x05, 'l', 'o', 'c', 'a', 'l', + 0x00, + 0x00, 0x0c, // TYPE is PTR. + 0x00, 0x01, // CLASS is IN. + 0x00, 0x00, // TTL (4 bytes) is zero; + 0x00, 0x00, + 0x00, 0x08, // RDLENGTH is 8 bytes. + 0x05, 'z', 'z', 'z', 'z', 'z', + 0xc0, 0x0c, }; +std::string MakeString(const uint8* data, unsigned size) { + return std::string(reinterpret_cast<const char*>(data), size); +} + class PtrRecordCopyContainer { public: PtrRecordCopyContainer() {} @@ -385,8 +389,8 @@ class MDnsTest : public ::testing::Test { protected: - void ExpectPacket(const char* packet, unsigned size); - void SimulatePacketReceive(const char* packet, unsigned size); + void ExpectPacket(const uint8* packet, unsigned size); + void SimulatePacketReceive(const uint8* packet, unsigned size); scoped_ptr<MDnsClientImpl> test_client_; IPEndPoint mdns_ipv4_endpoint_; @@ -424,12 +428,12 @@ void MDnsTest::SetUp() { void MDnsTest::TearDown() { } -void MDnsTest::SimulatePacketReceive(const char* packet, unsigned size) { +void MDnsTest::SimulatePacketReceive(const uint8* packet, unsigned size) { socket_factory_->SimulateReceive(packet, size); } -void MDnsTest::ExpectPacket(const char* packet, unsigned size) { - EXPECT_CALL(*socket_factory_, OnSendTo(std::string(packet, size))) +void MDnsTest::ExpectPacket(const uint8* packet, unsigned size) { + EXPECT_CALL(*socket_factory_, OnSendTo(MakeString(packet, size))) .Times(2); } @@ -1096,8 +1100,8 @@ class MDnsConnectionTest : public ::testing::Test { }; TEST_F(MDnsConnectionTest, ReceiveSynchronous) { - std::string sample_packet = - std::string(kSamplePacket1, sizeof(kSamplePacket1)); + std::string sample_packet = MakeString(kSamplePacket1, + sizeof(kSamplePacket1)); socket_ipv6_->SetResponsePacket(sample_packet); EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _)) @@ -1113,8 +1117,8 @@ TEST_F(MDnsConnectionTest, ReceiveSynchronous) { } TEST_F(MDnsConnectionTest, ReceiveAsynchronous) { - std::string sample_packet = - std::string(kSamplePacket1, sizeof(kSamplePacket1)); + std::string sample_packet = MakeString(kSamplePacket1, + sizeof(kSamplePacket1)); socket_ipv6_->SetResponsePacket(sample_packet); EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _)) .WillOnce(Return(ERR_IO_PENDING)); @@ -1131,8 +1135,8 @@ TEST_F(MDnsConnectionTest, ReceiveAsynchronous) { } TEST_F(MDnsConnectionTest, Send) { - std::string sample_packet = - std::string(kSamplePacket1, sizeof(kSamplePacket1)); + std::string sample_packet = MakeString(kSamplePacket1, + sizeof(kSamplePacket1)); scoped_refptr<IOBufferWithSize> buf( new IOBufferWithSize(sizeof kSamplePacket1)); diff --git a/net/dns/mock_mdns_socket_factory.cc b/net/dns/mock_mdns_socket_factory.cc index 720f6a0d..8c08c15 100644 --- a/net/dns/mock_mdns_socket_factory.cc +++ b/net/dns/mock_mdns_socket_factory.cc @@ -84,7 +84,7 @@ scoped_ptr<DatagramServerSocket> MockMDnsSocketFactory::CreateSocket() { return new_socket.PassAs<DatagramServerSocket>(); } -void MockMDnsSocketFactory::SimulateReceive(const char* packet, int size) { +void MockMDnsSocketFactory::SimulateReceive(const uint8* packet, int size) { DCHECK(recv_buffer_size_ >= size); DCHECK(recv_buffer_.get()); DCHECK(!recv_callback_.is_null()); diff --git a/net/dns/mock_mdns_socket_factory.h b/net/dns/mock_mdns_socket_factory.h index 62f6b7e..f60b08c5 100644 --- a/net/dns/mock_mdns_socket_factory.h +++ b/net/dns/mock_mdns_socket_factory.h @@ -77,7 +77,7 @@ class MockMDnsSocketFactory : public MDnsConnection::SocketFactory { virtual scoped_ptr<DatagramServerSocket> CreateSocket() OVERRIDE; - void SimulateReceive(const char* packet, int size); + void SimulateReceive(const uint8* packet, int size); MOCK_METHOD1(OnSendTo, void(const std::string&)); diff --git a/net/dns/record_parsed_unittest.cc b/net/dns/record_parsed_unittest.cc index bf99c26..2864dcb 100644 --- a/net/dns/record_parsed_unittest.cc +++ b/net/dns/record_parsed_unittest.cc @@ -12,22 +12,22 @@ namespace net { -static const char kT1ResponseWithCacheFlushBit[] = { - '\x0a', 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', - '\x08', 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', - '\x03', 'o', 'r', 'g', - '\x00', - '\x00', '\x05', // TYPE is CNAME. - '\x80', '\x01', // CLASS is IN with cache flush bit set. - '\x00', '\x01', // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. - '\x24', '\x74', - '\x00', '\x12', // RDLENGTH is 18 bytes. +static const uint8 kT1ResponseWithCacheFlushBit[] = { + 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', + 0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', + 0x03, 'o', 'r', 'g', + 0x00, + 0x00, 0x05, // TYPE is CNAME. + 0x80, 0x01, // CLASS is IN with cache flush bit set. + 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. + 0x24, 0x74, + 0x00, 0x12, // RDLENGTH is 18 bytes. // ghs.l.google.com in DNS format. - '\x03', 'g', 'h', 's', - '\x01', 'l', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm', - '\x00' + 0x03, 'g', 'h', 's', + 0x01, 'l', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00 }; TEST(RecordParsedTest, ParseSingleRecord) { diff --git a/net/dns/record_rdata_unittest.cc b/net/dns/record_rdata_unittest.cc index 30ce8be..90bac44 100644 --- a/net/dns/record_rdata_unittest.cc +++ b/net/dns/record_rdata_unittest.cc @@ -10,6 +10,11 @@ namespace net { +base::StringPiece MakeStringPiece(const uint8* data, unsigned size) { + const char* data_cc = reinterpret_cast<const char*>(data); + return base::StringPiece(data_cc, size); +} + TEST(RecordRdataTest, ParseSrvRecord) { scoped_ptr<SrvRecordRdata> record1_obj; scoped_ptr<SrvRecordRdata> record2_obj; @@ -17,25 +22,26 @@ TEST(RecordRdataTest, ParseSrvRecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x00', '\x01', - '\x00', '\x02', - '\x00', '\x50', - '\x03', 'w', 'w', 'w', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm', - '\x00', - '\x01', '\x01', - '\x01', '\x02', - '\x01', '\x03', - '\x04', 'w', 'w', 'w', '2', - '\xc0', '\x0a', // Pointer to "google.com" + const uint8 record[] = { + 0x00, 0x01, + 0x00, 0x02, + 0x00, 0x50, + 0x03, 'w', 'w', 'w', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00, + 0x01, 0x01, + 0x01, 0x02, + 0x01, 0x03, + 0x04, 'w', 'w', 'w', '2', + 0xc0, 0x0a, // Pointer to "google.com" }; DnsRecordParser parser(record, sizeof(record), 0); const unsigned first_record_len = 22; - base::StringPiece record1_strpiece(record, first_record_len); - base::StringPiece record2_strpiece( + base::StringPiece record1_strpiece = MakeStringPiece( + record, first_record_len); + base::StringPiece record2_strpiece = MakeStringPiece( record + first_record_len, sizeof(record) - first_record_len); record1_obj = SrvRecordRdata::Create(record1_strpiece, parser); @@ -64,12 +70,12 @@ TEST(RecordRdataTest, ParseARecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x7F', '\x00', '\x00', '\x01' // 127.0.0.1 + const uint8 record[] = { + 0x7F, 0x00, 0x00, 0x01 // 127.0.0.1 }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = ARecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); @@ -85,15 +91,15 @@ TEST(RecordRdataTest, ParseAAAARecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x12', '\x34', '\x56', '\x78', - '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x09' // 1234:5678::9A + const uint8 record[] = { + 0x12, 0x34, 0x56, 0x78, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09 // 1234:5678::9A }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = AAAARecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); @@ -110,15 +116,15 @@ TEST(RecordRdataTest, ParseCnameRecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x03', 'w', 'w', 'w', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm', - '\x00' + const uint8 record[] = { + 0x03, 'w', 'w', 'w', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00 }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = CnameRecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); @@ -134,15 +140,15 @@ TEST(RecordRdataTest, ParsePtrRecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x03', 'w', 'w', 'w', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm', - '\x00' + const uint8 record[] = { + 0x03, 'w', 'w', 'w', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00 }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = PtrRecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); @@ -158,14 +164,14 @@ TEST(RecordRdataTest, ParseTxtRecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x03', 'w', 'w', 'w', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm' + const uint8 record[] = { + 0x03, 'w', 'w', 'w', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm' }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = TxtRecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); @@ -186,16 +192,16 @@ TEST(RecordRdataTest, ParseNsecRecord) { // These are just the rdata portions of the DNS records, rather than complete // records, but it works well enough for this test. - const char record[] = { - '\x03', 'w', 'w', 'w', - '\x06', 'g', 'o', 'o', 'g', 'l', 'e', - '\x03', 'c', 'o', 'm', - '\x00', - '\x00', '\x02', '\x40', '\x01' + const uint8 record[] = { + 0x03, 'w', 'w', 'w', + 0x06, 'g', 'o', 'o', 'g', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00, + 0x00, 0x02, 0x40, 0x01 }; DnsRecordParser parser(record, sizeof(record), 0); - base::StringPiece record_strpiece(record, sizeof(record)); + base::StringPiece record_strpiece = MakeStringPiece(record, sizeof(record)); record_obj = NsecRecordRdata::Create(record_strpiece, parser); ASSERT_TRUE(record_obj != NULL); |