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

Side by Side Diff: third_party/WebKit/Source/wtf/StringExtrasTest.cpp

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #include "config.h" 26 #include "config.h"
27 #include "wtf/StringExtras.h" 27 #include "wtf/StringExtras.h"
28 28
29 #include "wtf/text/CString.h" 29 #include "wtf/text/CString.h"
30 #include "wtf/text/WTFString.h" 30 #include "wtf/text/WTFString.h"
31 #include <gtest/gtest.h> 31 #include <gtest/gtest.h>
32 #include <limits> 32 #include <limits>
33 33
34 namespace WTF { 34 namespace WTF {
35 35
36 template<typename IntegerType> struct PrintfFormatTrait { static const char form at[]; }; 36 template <typename IntegerType>
37 struct PrintfFormatTrait { static const char format[]; };
37 38
38 template<> struct PrintfFormatTrait<short> { static const char format[]; }; 39 template <>
40 struct PrintfFormatTrait<short> { static const char format[]; };
39 const char PrintfFormatTrait<short>::format[] = "%hd"; 41 const char PrintfFormatTrait<short>::format[] = "%hd";
40 42
41 template<> struct PrintfFormatTrait<int> { static const char format[]; }; 43 template <>
44 struct PrintfFormatTrait<int> { static const char format[]; };
42 const char PrintfFormatTrait<int>::format[] = "%d"; 45 const char PrintfFormatTrait<int>::format[] = "%d";
43 46
44 template<> struct PrintfFormatTrait<long> { static const char format[]; }; 47 template <>
48 struct PrintfFormatTrait<long> { static const char format[]; };
45 const char PrintfFormatTrait<long>::format[] = "%ld"; 49 const char PrintfFormatTrait<long>::format[] = "%ld";
46 50
47 template<> struct PrintfFormatTrait<long long> { static const char format[]; }; 51 template <>
52 struct PrintfFormatTrait<long long> { static const char format[]; };
48 #if OS(WIN) 53 #if OS(WIN)
49 const char PrintfFormatTrait<long long>::format[] = "%I64i"; 54 const char PrintfFormatTrait<long long>::format[] = "%I64i";
50 #else 55 #else
51 const char PrintfFormatTrait<long long>::format[] = "%lli"; 56 const char PrintfFormatTrait<long long>::format[] = "%lli";
52 #endif // OS(WIN) 57 #endif // OS(WIN)
53 58
54 template<> struct PrintfFormatTrait<unsigned short> { static const char format[] ; }; 59 template <>
60 struct PrintfFormatTrait<unsigned short> { static const char format[]; };
55 const char PrintfFormatTrait<unsigned short>::format[] = "%hu"; 61 const char PrintfFormatTrait<unsigned short>::format[] = "%hu";
56 62
57 template<> struct PrintfFormatTrait<unsigned> { static const char format[]; }; 63 template <>
64 struct PrintfFormatTrait<unsigned> { static const char format[]; };
58 const char PrintfFormatTrait<unsigned>::format[] = "%u"; 65 const char PrintfFormatTrait<unsigned>::format[] = "%u";
59 66
60 template<> struct PrintfFormatTrait<unsigned long> { static const char format[]; }; 67 template <>
68 struct PrintfFormatTrait<unsigned long> { static const char format[]; };
61 const char PrintfFormatTrait<unsigned long>::format[] = "%lu"; 69 const char PrintfFormatTrait<unsigned long>::format[] = "%lu";
62 70
63 template<> struct PrintfFormatTrait<unsigned long long> { static const char form at[]; }; 71 template <>
72 struct PrintfFormatTrait<unsigned long long> { static const char format[]; };
64 #if OS(WIN) 73 #if OS(WIN)
65 const char PrintfFormatTrait<unsigned long long>::format[] = "%I64u"; 74 const char PrintfFormatTrait<unsigned long long>::format[] = "%I64u";
66 #else 75 #else
67 const char PrintfFormatTrait<unsigned long long>::format[] = "%llu"; 76 const char PrintfFormatTrait<unsigned long long>::format[] = "%llu";
68 #endif // OS(WIN) 77 #endif // OS(WIN)
69
70 78
71 // FIXME: use snprintf from StringExtras.h 79 // FIXME: use snprintf from StringExtras.h
72 template<typename IntegerType> 80 template <typename IntegerType>
73 void testBoundaries() 81 void testBoundaries() {
74 { 82 const unsigned bufferSize = 256;
75 const unsigned bufferSize = 256; 83 Vector<char, bufferSize> buffer;
76 Vector<char, bufferSize> buffer; 84 buffer.resize(bufferSize);
77 buffer.resize(bufferSize);
78 85
79 const IntegerType min = std::numeric_limits<IntegerType>::min(); 86 const IntegerType min = std::numeric_limits<IntegerType>::min();
80 CString minStringData = String::number(min).latin1(); 87 CString minStringData = String::number(min).latin1();
81 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, min); 88 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, mi n);
82 EXPECT_STREQ(buffer.data(), minStringData.data()); 89 EXPECT_STREQ(buffer.data(), minStringData.data());
83 90
84 const IntegerType max = std::numeric_limits<IntegerType>::max(); 91 const IntegerType max = std::numeric_limits<IntegerType>::max();
85 CString maxStringData = String::number(max).latin1(); 92 CString maxStringData = String::number(max).latin1();
86 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, max); 93 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, ma x);
87 EXPECT_STREQ(buffer.data(), maxStringData.data()); 94 EXPECT_STREQ(buffer.data(), maxStringData.data());
88 } 95 }
89 96
90 template<typename IntegerType> 97 template <typename IntegerType>
91 void testNumbers() 98 void testNumbers() {
92 { 99 const unsigned bufferSize = 256;
93 const unsigned bufferSize = 256; 100 Vector<char, bufferSize> buffer;
94 Vector<char, bufferSize> buffer; 101 buffer.resize(bufferSize);
95 buffer.resize(bufferSize);
96 102
97 for (int i = -100; i < 100; ++i) { 103 for (int i = -100; i < 100; ++i) {
98 const IntegerType number = static_cast<IntegerType>(i); 104 const IntegerType number = static_cast<IntegerType>(i);
99 CString numberStringData = String::number(number).latin1(); 105 CString numberStringData = String::number(number).latin1();
100 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::form at, number); 106 snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, number);
101 EXPECT_STREQ(buffer.data(), numberStringData.data()); 107 EXPECT_STREQ(buffer.data(), numberStringData.data());
102 } 108 }
103 } 109 }
104 110
105 TEST(StringExtraTest, IntegerToStringConversionSignedIntegerBoundaries) 111 TEST(StringExtraTest, IntegerToStringConversionSignedIntegerBoundaries) {
106 { 112 testBoundaries<short>();
107 testBoundaries<short>(); 113 testBoundaries<int>();
108 testBoundaries<int>(); 114 testBoundaries<long>();
109 testBoundaries<long>(); 115 testBoundaries<long long>();
110 testBoundaries<long long>();
111 } 116 }
112 117
113 TEST(StringExtraTest, IntegerToStringConversionSignedIntegerRegularNumbers) 118 TEST(StringExtraTest, IntegerToStringConversionSignedIntegerRegularNumbers) {
114 { 119 testNumbers<short>();
115 testNumbers<short>(); 120 testNumbers<int>();
116 testNumbers<int>(); 121 testNumbers<long>();
117 testNumbers<long>(); 122 testNumbers<long long>();
118 testNumbers<long long>();
119 } 123 }
120 124
121 TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerBoundaries) 125 TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerBoundaries) {
122 { 126 testBoundaries<unsigned short>();
123 testBoundaries<unsigned short>(); 127 testBoundaries<unsigned>();
124 testBoundaries<unsigned>(); 128 testBoundaries<unsigned long>();
125 testBoundaries<unsigned long>(); 129 testBoundaries<unsigned long long>();
126 testBoundaries<unsigned long long>();
127 } 130 }
128 131
129 TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerRegularNumbers) 132 TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerRegularNumbers) {
130 { 133 testNumbers<unsigned short>();
131 testNumbers<unsigned short>(); 134 testNumbers<unsigned>();
132 testNumbers<unsigned>(); 135 testNumbers<unsigned long>();
133 testNumbers<unsigned long>(); 136 testNumbers<unsigned long long>();
134 testNumbers<unsigned long long>();
135 } 137 }
136 138
137 } // namespace WTF 139 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/StringExtras.h ('k') | third_party/WebKit/Source/wtf/StringHasher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698