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

Side by Side Diff: net/websockets/websocket_frame_test.cc

Issue 826973002: replace COMPILE_ASSERT with static_assert in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: apply fixups Created 5 years, 11 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
« no previous file with comments | « net/websockets/websocket_frame_perftest.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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_frame.h" 5 #include "net/websockets/websocket_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 std::vector<char> output(expected_output.size()); 44 std::vector<char> output(expected_output.size());
45 EXPECT_EQ(static_cast<int>(expected_output.size()), 45 EXPECT_EQ(static_cast<int>(expected_output.size()),
46 WriteWebSocketFrameHeader( 46 WriteWebSocketFrameHeader(
47 header, NULL, &output.front(), output.size())); 47 header, NULL, &output.front(), output.size()));
48 EXPECT_EQ(expected_output, output); 48 EXPECT_EQ(expected_output, output);
49 } 49 }
50 } 50 }
51 51
52 TEST(WebSocketFrameHeaderTest, FrameLengthsWithMasking) { 52 TEST(WebSocketFrameHeaderTest, FrameLengthsWithMasking) {
53 static const char kMaskingKey[] = "\xDE\xAD\xBE\xEF"; 53 static const char kMaskingKey[] = "\xDE\xAD\xBE\xEF";
54 COMPILE_ASSERT(arraysize(kMaskingKey) - 1 == 54 static_assert(
55 WebSocketFrameHeader::kMaskingKeyLength, 55 arraysize(kMaskingKey) - 1 == WebSocketFrameHeader::kMaskingKeyLength,
56 incorrect_masking_key_size); 56 "incorrect masking key size");
57 57
58 struct TestCase { 58 struct TestCase {
59 const char* frame_header; 59 const char* frame_header;
60 size_t frame_header_length; 60 size_t frame_header_length;
61 uint64 frame_length; 61 uint64 frame_length;
62 }; 62 };
63 static const TestCase kTests[] = { 63 static const TestCase kTests[] = {
64 { "\x81\x80\xDE\xAD\xBE\xEF", 6, GG_UINT64_C(0) }, 64 { "\x81\x80\xDE\xAD\xBE\xEF", 6, GG_UINT64_C(0) },
65 { "\x81\xFD\xDE\xAD\xBE\xEF", 6, GG_UINT64_C(125) }, 65 { "\x81\xFD\xDE\xAD\xBE\xEF", 6, GG_UINT64_C(125) },
66 { "\x81\xFE\x00\x7E\xDE\xAD\xBE\xEF", 8, GG_UINT64_C(126) }, 66 { "\x81\xFE\x00\x7E\xDE\xAD\xBE\xEF", 8, GG_UINT64_C(126) },
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 }; 287 };
288 static const size_t kTestInputSize = arraysize(kTestInput) - 1; 288 static const size_t kTestInputSize = arraysize(kTestInput) - 1;
289 static const char kTestOutput[] = { 289 static const char kTestOutput[] = {
290 "\xef\xcd\x47\xa5\xcb\x36\x12\x1d\xcb\xd7\xad\x72\xeb\x5d\x0d\xb5" 290 "\xef\xcd\x47\xa5\xcb\x36\x12\x1d\xcb\xd7\xad\x72\xeb\x5d\x0d\xb5"
291 "\xbb\x36\x80\xf5\x2e\x16\x76\x6d\x9b\x2c\x34\x34\xa9\xe0\x68\xc8" 291 "\xbb\x36\x80\xf5\x2e\x16\x76\x6d\x9b\x2c\x34\x34\xa9\xe0\x68\xc8"
292 "\x02\xab\x19\x1e\x5b\x46\x2c\x95\xc2\x95\x16\xc5\x9d\x1c\x87\x5a" 292 "\x02\xab\x19\x1e\x5b\x46\x2c\x95\xc2\x95\x16\xc5\x9d\x1c\x87\x5a"
293 "\x2e\x34\x82\xcc\x1d\xc4\x6d\x73\xe3\x77\x9b\x7e\x5b\xb6\xfd\xf2" 293 "\x2e\x34\x82\xcc\x1d\xc4\x6d\x73\xe3\x77\x9b\x7e\x5b\xb6\xfd\xf2"
294 "\x08\x12\x11\xcb\x73\x71\xf3\xc9\xcb\xf7\x34\x61\x1a\xb2\x46\x08" 294 "\x08\x12\x11\xcb\x73\x71\xf3\xc9\xcb\xf7\x34\x61\x1a\xb2\x46\x08"
295 "\xbf\x41\x62\xba\x96\x6f\xe0\xe9\x4d\xcc\xea\x90\xd5\x2b\xbc\x16" 295 "\xbf\x41\x62\xba\x96\x6f\xe0\xe9\x4d\xcc\xea\x90\xd5\x2b\xbc\x16"
296 }; 296 };
297 COMPILE_ASSERT(arraysize(kTestInput) == arraysize(kTestOutput), 297 static_assert(arraysize(kTestInput) == arraysize(kTestOutput),
298 output_and_input_arrays_have_the_same_length); 298 "output and input arrays should have the same length");
299 scoped_ptr<char, base::AlignedFreeDeleter> scratch( 299 scoped_ptr<char, base::AlignedFreeDeleter> scratch(
300 static_cast<char*>( 300 static_cast<char*>(
301 base::AlignedAlloc(kScratchBufferSize, kMaxVectorAlignment))); 301 base::AlignedAlloc(kScratchBufferSize, kMaxVectorAlignment)));
302 WebSocketMaskingKey masking_key; 302 WebSocketMaskingKey masking_key;
303 std::copy(kTestMask, kTestMask + kMaskingKeyLength, masking_key.key); 303 std::copy(kTestMask, kTestMask + kMaskingKeyLength, masking_key.key);
304 for (size_t frame_offset = 0; frame_offset < kMaskingKeyLength; 304 for (size_t frame_offset = 0; frame_offset < kMaskingKeyLength;
305 ++frame_offset) { 305 ++frame_offset) {
306 for (size_t alignment = 0; alignment < kMaxVectorAlignment; ++alignment) { 306 for (size_t alignment = 0; alignment < kMaxVectorAlignment; ++alignment) {
307 char* const aligned_scratch = scratch.get() + alignment; 307 char* const aligned_scratch = scratch.get() + alignment;
308 const size_t aligned_len = std::min(kScratchBufferSize - alignment, 308 const size_t aligned_len = std::min(kScratchBufferSize - alignment,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xF)); 385 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xF));
386 386
387 // Check that out-of-range opcodes return false 387 // Check that out-of-range opcodes return false
388 EXPECT_FALSE(Frame::IsKnownControlOpCode(-1)); 388 EXPECT_FALSE(Frame::IsKnownControlOpCode(-1));
389 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xFF)); 389 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xFF));
390 } 390 }
391 391
392 } // namespace 392 } // namespace
393 393
394 } // namespace net 394 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_frame_perftest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698