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

Unified Diff: Source/web/WebVectorTest.cpp

Issue 1014933002: Add begin()/end() to WebVector to enable range-based for loops (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add unit test Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/web/web.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebVectorTest.cpp
diff --git a/Source/web/WebVectorTest.cpp b/Source/web/WebVectorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..434753753736e9fe9b48337a1f4fe24e08a6d300
--- /dev/null
+++ b/Source/web/WebVectorTest.cpp
@@ -0,0 +1,51 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
Peter Beverloo 2015/03/19 12:03:19 nit: 2015
johnme 2015/03/19 12:47:23 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "public/platform/WebVector.h"
+
+#include "wtf/Vector.h"
+#include <gtest/gtest.h>
Peter Beverloo 2015/03/19 12:03:19 nit: no blank line on line 7, add one between 8 an
johnme 2015/03/19 12:47:23 Disagree - other tests I've looked at (WebNodeTest
+
+namespace blink {
+
+TEST(WebVectorTest, beginend)
+{
+ Vector<int> input;
+ for (int i = 0; i < 5; ++i)
+ input.append(i);
+
+ WebVector<int> webVector(input);
+ ASSERT_EQ(input.size(), webVector.size());
+
+ EXPECT_EQ(webVector.data(), webVector.begin());
+ EXPECT_EQ(webVector.data() + webVector.size(), webVector.end());
+
+ // Use begin()/end() iterators directly.
+ Vector<int> output;
+ for (WebVector<int>::iterator it = webVector.begin(); it != webVector.end(); ++it)
+ output.append(*it);
+ ASSERT_EQ(input.size(), output.size());
+ for (size_t i = 0; i < input.size(); ++i)
+ EXPECT_EQ(input[i], output[i]);
+
+ // Use begin()/end() const_iterators directly.
+ output.clear();
+ const WebVector<int>& constWebVector = webVector;
+ for (WebVector<int>::const_iterator it = constWebVector.begin(); it != constWebVector.end(); ++it)
+ output.append(*it);
+ ASSERT_EQ(input.size(), output.size());
+ for (size_t i = 0; i < input.size(); ++i)
+ EXPECT_EQ(input[i], output[i]);
+
+ // Use range-based for loop.
+ output.clear();
+ for (int x : webVector)
+ output.append(x);
+ ASSERT_EQ(input.size(), output.size());
+ for (size_t i = 0; i < input.size(); ++i)
+ EXPECT_EQ(input[i], output[i]);
+}
+
+} // namespace blink
« no previous file with comments | « no previous file | Source/web/web.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698