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

Side by Side Diff: net/base/mime_util_unittest.cc

Issue 662553002: Convert ARRAYSIZE_UNSAFE -> arraysize in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/base/ip_endpoint_unittest.cc ('k') | net/base/net_log_logger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/strings/string_split.h" 6 #include "base/strings/string_split.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "net/base/mime_util.h" 8 #include "net/base/mime_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 15 matching lines...) Expand all
26 { FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true }, 26 { FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true },
27 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
28 { FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true }, 28 { FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true },
29 #endif 29 #endif
30 { FILE_PATH_LITERAL("not an extension / for sure"), "", false }, 30 { FILE_PATH_LITERAL("not an extension / for sure"), "", false },
31 }; 31 };
32 32
33 std::string mime_type; 33 std::string mime_type;
34 bool rv; 34 bool rv;
35 35
36 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 36 for (size_t i = 0; i < arraysize(tests); ++i) {
37 rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type); 37 rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type);
38 EXPECT_EQ(tests[i].valid, rv); 38 EXPECT_EQ(tests[i].valid, rv);
39 if (rv) 39 if (rv)
40 EXPECT_EQ(tests[i].mime_type, mime_type); 40 EXPECT_EQ(tests[i].mime_type, mime_type);
41 } 41 }
42 } 42 }
43 43
44 TEST(MimeUtilTest, FileTest) { 44 TEST(MimeUtilTest, FileTest) {
45 const struct { 45 const struct {
46 const base::FilePath::CharType* file_path; 46 const base::FilePath::CharType* file_path;
47 const char* mime_type; 47 const char* mime_type;
48 bool valid; 48 bool valid;
49 } tests[] = { 49 } tests[] = {
50 { FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true }, 50 { FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true },
51 { FILE_PATH_LITERAL("c:\\blah"), "", false }, 51 { FILE_PATH_LITERAL("c:\\blah"), "", false },
52 { FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false }, 52 { FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false },
53 { FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true }, 53 { FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true },
54 { FILE_PATH_LITERAL("/blah."), "", false }, 54 { FILE_PATH_LITERAL("/blah."), "", false },
55 { FILE_PATH_LITERAL("c:\\blah."), "", false }, 55 { FILE_PATH_LITERAL("c:\\blah."), "", false },
56 }; 56 };
57 57
58 std::string mime_type; 58 std::string mime_type;
59 bool rv; 59 bool rv;
60 60
61 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 61 for (size_t i = 0; i < arraysize(tests); ++i) {
62 rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path), 62 rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path),
63 &mime_type); 63 &mime_type);
64 EXPECT_EQ(tests[i].valid, rv); 64 EXPECT_EQ(tests[i].valid, rv);
65 if (rv) 65 if (rv)
66 EXPECT_EQ(tests[i].mime_type, mime_type); 66 EXPECT_EQ(tests[i].mime_type, mime_type);
67 } 67 }
68 } 68 }
69 69
70 TEST(MimeUtilTest, LookupTypes) { 70 TEST(MimeUtilTest, LookupTypes) {
71 EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana")); 71 EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana"));
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, 267 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
268 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, 268 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
269 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, 269 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
270 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, 270 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
271 { "", 0, { } }, 271 { "", 0, { } },
272 { "\"\"", 0, { } }, 272 { "\"\"", 0, { } },
273 { "\" \"", 0, { } }, 273 { "\" \"", 0, { } },
274 { ",", 2, { "", "" } }, 274 { ",", 2, { "", "" } },
275 }; 275 };
276 276
277 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 277 for (size_t i = 0; i < arraysize(tests); ++i) {
278 std::vector<std::string> codecs_out; 278 std::vector<std::string> codecs_out;
279 ParseCodecString(tests[i].original, &codecs_out, true); 279 ParseCodecString(tests[i].original, &codecs_out, true);
280 ASSERT_EQ(tests[i].expected_size, codecs_out.size()); 280 ASSERT_EQ(tests[i].expected_size, codecs_out.size());
281 for (size_t j = 0; j < tests[i].expected_size; ++j) 281 for (size_t j = 0; j < tests[i].expected_size; ++j)
282 EXPECT_EQ(tests[i].results[j], codecs_out[j]); 282 EXPECT_EQ(tests[i].results[j], codecs_out[j]);
283 } 283 }
284 284
285 // Test without stripping the codec type. 285 // Test without stripping the codec type.
286 std::vector<std::string> codecs_out; 286 std::vector<std::string> codecs_out;
287 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); 287 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 { "video/*", 6, "mp4" }, 394 { "video/*", 6, "mp4" },
395 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS) 395 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS)
396 { "video/*", 6, "mpg" }, 396 { "video/*", 6, "mpg" },
397 #else 397 #else
398 { "video/*", 6, "mpeg" }, 398 { "video/*", 6, "mpeg" },
399 #endif 399 #endif
400 { "audio/*", 6, "oga" }, 400 { "audio/*", 6, "oga" },
401 { "aUDIo/*", 6, "wav" }, 401 { "aUDIo/*", 6, "wav" },
402 }; 402 };
403 403
404 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 404 for (size_t i = 0; i < arraysize(tests); ++i) {
405 std::vector<base::FilePath::StringType> extensions; 405 std::vector<base::FilePath::StringType> extensions;
406 GetExtensionsForMimeType(tests[i].mime_type, &extensions); 406 GetExtensionsForMimeType(tests[i].mime_type, &extensions);
407 ASSERT_TRUE(tests[i].min_expected_size <= extensions.size()); 407 ASSERT_TRUE(tests[i].min_expected_size <= extensions.size());
408 408
409 if (!tests[i].contained_result) 409 if (!tests[i].contained_result)
410 continue; 410 continue;
411 411
412 bool found = false; 412 bool found = false;
413 for (size_t j = 0; !found && j < extensions.size(); ++j) { 413 for (size_t j = 0; !found && j < extensions.size(); ++j) {
414 #if defined(OS_WIN) 414 #if defined(OS_WIN)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 std::string post_data; 453 std::string post_data;
454 AddMultipartValueForUpload("value name", "value", "boundary", 454 AddMultipartValueForUpload("value name", "value", "boundary",
455 "content type", &post_data); 455 "content type", &post_data);
456 AddMultipartValueForUpload("value name", "value", "boundary", 456 AddMultipartValueForUpload("value name", "value", "boundary",
457 "", &post_data); 457 "", &post_data);
458 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 458 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
459 EXPECT_STREQ(ref_output, post_data.c_str()); 459 EXPECT_STREQ(ref_output, post_data.c_str());
460 } 460 }
461 461
462 } // namespace net 462 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ip_endpoint_unittest.cc ('k') | net/base/net_log_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698