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

Side by Side Diff: net/http/http_byte_range_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/http/http_byte_range.h" 5 #include "net/http/http_byte_range.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 TEST(HttpByteRangeTest, ValidRanges) { 8 TEST(HttpByteRangeTest, ValidRanges) {
9 const struct { 9 const struct {
10 int64 first_byte_position; 10 int64 first_byte_position;
11 int64 last_byte_position; 11 int64 last_byte_position;
12 int64 suffix_length; 12 int64 suffix_length;
13 bool valid; 13 bool valid;
14 } tests[] = { 14 } tests[] = {
15 { -1, -1, 0, false }, 15 {-1, -1, 0, false},
16 { 0, 0, 0, true }, 16 {0, 0, 0, true},
17 { -10, 0, 0, false }, 17 {-10, 0, 0, false},
18 { 10, 0, 0, false }, 18 {10, 0, 0, false},
19 { 10, -1, 0, true }, 19 {10, -1, 0, true},
20 { -1, -1, -1, false }, 20 {-1, -1, -1, false},
21 { -1, 50, 0, false }, 21 {-1, 50, 0, false},
22 { 10, 10000, 0, true }, 22 {10, 10000, 0, true},
23 { -1, -1, 100000, true }, 23 {-1, -1, 100000, true},
24 }; 24 };
25 25
26 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 26 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
27 net::HttpByteRange range; 27 net::HttpByteRange range;
28 range.set_first_byte_position(tests[i].first_byte_position); 28 range.set_first_byte_position(tests[i].first_byte_position);
29 range.set_last_byte_position(tests[i].last_byte_position); 29 range.set_last_byte_position(tests[i].last_byte_position);
30 range.set_suffix_length(tests[i].suffix_length); 30 range.set_suffix_length(tests[i].suffix_length);
31 EXPECT_EQ(tests[i].valid, range.IsValid()); 31 EXPECT_EQ(tests[i].valid, range.IsValid());
32 } 32 }
33 } 33 }
34 34
35 TEST(HttpByteRangeTest, SetInstanceSize) { 35 TEST(HttpByteRangeTest, SetInstanceSize) {
36 const struct { 36 const struct {
37 int64 first_byte_position; 37 int64 first_byte_position;
38 int64 last_byte_position; 38 int64 last_byte_position;
39 int64 suffix_length; 39 int64 suffix_length;
40 int64 instance_size; 40 int64 instance_size;
41 bool expected_return_value; 41 bool expected_return_value;
42 int64 expected_lower_bound; 42 int64 expected_lower_bound;
43 int64 expected_upper_bound; 43 int64 expected_upper_bound;
44 } tests[] = { 44 } tests[] = {
45 { -10, 0, -1, 0, false, -1, -1 }, 45 {-10, 0, -1, 0, false, -1, -1},
46 { 10, 0, -1, 0, false, -1, -1 }, 46 {10, 0, -1, 0, false, -1, -1},
47 // Zero instance size is valid, this is the case that user has to handle. 47 // Zero instance size is valid, this is the case that user has to
48 { -1, -1, -1, 0, true, 0, -1 }, 48 // handle.
49 { -1, -1, 500, 0, true, 0, -1 }, 49 {-1, -1, -1, 0, true, 0, -1},
50 { -1, 50, -1, 0, false, -1, -1 }, 50 {-1, -1, 500, 0, true, 0, -1},
51 { -1, -1, 500, 300, true, 0, 299 }, 51 {-1, 50, -1, 0, false, -1, -1},
52 { -1, -1, -1, 100, true, 0, 99 }, 52 {-1, -1, 500, 300, true, 0, 299},
53 { 10, -1, -1, 100, true, 10, 99 }, 53 {-1, -1, -1, 100, true, 0, 99},
54 { -1, -1, 500, 1000, true, 500, 999 }, 54 {10, -1, -1, 100, true, 10, 99},
55 { 10, 10000, -1, 1000000, true, 10, 10000 }, 55 {-1, -1, 500, 1000, true, 500, 999},
56 }; 56 {10, 10000, -1, 1000000, true, 10, 10000},
57 };
57 58
58 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
59 net::HttpByteRange range; 60 net::HttpByteRange range;
60 range.set_first_byte_position(tests[i].first_byte_position); 61 range.set_first_byte_position(tests[i].first_byte_position);
61 range.set_last_byte_position(tests[i].last_byte_position); 62 range.set_last_byte_position(tests[i].last_byte_position);
62 range.set_suffix_length(tests[i].suffix_length); 63 range.set_suffix_length(tests[i].suffix_length);
63 64
64 bool return_value = range.ComputeBounds(tests[i].instance_size); 65 bool return_value = range.ComputeBounds(tests[i].instance_size);
65 EXPECT_EQ(tests[i].expected_return_value, return_value); 66 EXPECT_EQ(tests[i].expected_return_value, return_value);
66 if (return_value) { 67 if (return_value) {
67 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position()); 68 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position());
68 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position()); 69 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position());
69 70
70 // Try to call SetInstanceSize the second time. 71 // Try to call SetInstanceSize the second time.
71 EXPECT_FALSE(range.ComputeBounds(tests[i].instance_size)); 72 EXPECT_FALSE(range.ComputeBounds(tests[i].instance_size));
72 // And expect there's no side effect. 73 // And expect there's no side effect.
73 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position()); 74 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position());
74 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position()); 75 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position());
75 EXPECT_EQ(tests[i].suffix_length, range.suffix_length()); 76 EXPECT_EQ(tests[i].suffix_length, range.suffix_length());
76 } 77 }
77 } 78 }
78 } 79 }
79 80
80 TEST(HttpByteRangeTest, GetHeaderValue) { 81 TEST(HttpByteRangeTest, GetHeaderValue) {
81 static const struct { 82 static const struct {
82 net::HttpByteRange range; 83 net::HttpByteRange range;
83 const char* expected; 84 const char* expected;
84 } tests[] = {{net::HttpByteRange::Bounded(0, 0), "bytes=0-0"}, 85 } tests[] = {
85 {net::HttpByteRange::Bounded(0, 100), "bytes=0-100"}, 86 {net::HttpByteRange::Bounded(0, 0), "bytes=0-0"},
86 {net::HttpByteRange::Bounded(0, -1), "bytes=0-"}, 87 {net::HttpByteRange::Bounded(0, 100), "bytes=0-100"},
87 {net::HttpByteRange::RightUnbounded(100), "bytes=100-"}, 88 {net::HttpByteRange::Bounded(0, -1), "bytes=0-"},
88 {net::HttpByteRange::Suffix(100), "bytes=-100"}, }; 89 {net::HttpByteRange::RightUnbounded(100), "bytes=100-"},
90 {net::HttpByteRange::Suffix(100), "bytes=-100"},
91 };
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 92 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
90 EXPECT_EQ(tests[i].expected, tests[i].range.GetHeaderValue()); 93 EXPECT_EQ(tests[i].expected, tests[i].range.GetHeaderValue());
91 } 94 }
92 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698