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

Side by Side Diff: third_party/WebKit/Source/wtf/text/CStringTest.cpp

Issue 2345893002: Make CString more similar to WTF::String. (Closed)
Patch Set: asserts. Created 4 years, 3 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 | « third_party/WebKit/Source/wtf/text/CString.cpp ('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 /* 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_EQ(0, uninitializedString.data()[length]); 104 EXPECT_EQ(0, uninitializedString.data()[length]);
105 } 105 }
106 106
107 TEST(CStringTest, ZeroTerminated) 107 TEST(CStringTest, ZeroTerminated)
108 { 108 {
109 const char* referenceString = "WebKit"; 109 const char* referenceString = "WebKit";
110 CString stringWithLength(referenceString, 3); 110 CString stringWithLength(referenceString, 3);
111 EXPECT_EQ(0, stringWithLength.data()[3]); 111 EXPECT_EQ(0, stringWithLength.data()[3]);
112 } 112 }
113 113
114 TEST(CStringTest, CopyOnWrite)
115 {
116 const char* initialString = "Webkit";
117 CString string(initialString);
118 CString copy = string;
119
120 string.mutableData()[3] = 'K';
121 EXPECT_TRUE(string != copy);
122 EXPECT_STREQ("WebKit", string.data());
123 EXPECT_STREQ(initialString, copy.data());
124 }
125
126 TEST(CStringTest, Comparison) 114 TEST(CStringTest, Comparison)
127 { 115 {
128 // Comparison with another CString. 116 // Comparison with another CString.
129 CString a; 117 CString a;
130 CString b; 118 CString b;
131 EXPECT_TRUE(a == b); 119 EXPECT_TRUE(a == b);
132 EXPECT_FALSE(a != b); 120 EXPECT_FALSE(a != b);
133 a = "a"; 121 a = "a";
134 b = CString(); 122 b = CString();
135 EXPECT_FALSE(a == b); 123 EXPECT_FALSE(a == b);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 200
213 TEST(CStringTest, Printer) 201 TEST(CStringTest, Printer)
214 { 202 {
215 EXPECT_STREQ("<null>", printedString(CString()).data()); 203 EXPECT_STREQ("<null>", printedString(CString()).data());
216 EXPECT_STREQ("\"abc\"", printedString("abc").data()); 204 EXPECT_STREQ("\"abc\"", printedString("abc").data());
217 EXPECT_STREQ("\"\\t\\n\\r\\\"\\\\\"", printedString("\t\n\r\"\\").data()); 205 EXPECT_STREQ("\"\\t\\n\\r\\\"\\\\\"", printedString("\t\n\r\"\\").data());
218 EXPECT_STREQ("\"\\xFF\\x00\\x01xyz\"", printedString(CString("\xff\0\x01xyz" , 6)).data()); 206 EXPECT_STREQ("\"\\xFF\\x00\\x01xyz\"", printedString(CString("\xff\0\x01xyz" , 6)).data());
219 } 207 }
220 208
221 } // namespace WTF 209 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/CString.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698