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

Unified Diff: base/nullptr_unittest.cc

Issue 11411318: DO NOT COMMIT: NullPtr support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WIP Created 8 years 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 | « base/nullptr.cc ('k') | build/build_config.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/nullptr_unittest.cc
diff --git a/base/nullptr_unittest.cc b/base/nullptr_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a19102361631b03ba9f36526ada362358dc2158
--- /dev/null
+++ b/base/nullptr_unittest.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/nullptr.h"
+
+#include "base/basictypes.h"
+#include "base/template_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Overloaded free function used to test pointers do not match nullptr_t.
+bool VoidParamMatchesNullptr(base::nullptr_t pointer) {
+ return true;
+}
+
+bool VoidParamMatchesNullptr(void* pointer) {
+ return false;
+}
+
+// Overloaded free function used to test integral constants do not
+// match nullptr_t.
+bool IntParamMatchesNullptr(base::nullptr_t param) {
+ return true;
+}
+
+bool IntParamMatchesNullptr(intptr_t param) {
+ return false;
+}
+
+template <typename T> struct TemplateMatchesNullptr : base::false_type {};
+template <> struct TemplateMatchesNullptr<base::nullptr_t> : base::true_type {};
+
+COMPILE_ASSERT(!TemplateMatchesNullptr<int>::value, MatchesNullptr);
+COMPILE_ASSERT(!TemplateMatchesNullptr<void*>::value, MatchesNullptr);
+COMPILE_ASSERT(TemplateMatchesNullptr<base::nullptr_t>::value, MatchesNullptr);
+
+template <typename T>
+bool TemplateMethodMatchesNullptr(T param) {
+ return false;
+}
+
+template <>
+bool TemplateMethodMatchesNullptr<base::nullptr_t>(base::nullptr_t param) {
+ return true;
+}
+
+} // namespace
+
+TEST(NullptrTest, VoidParamsDontMatch) {
+ void* dummy_param = NULL;
+ EXPECT_FALSE(VoidParamMatchesNullptr(dummy_param));
+ EXPECT_TRUE(VoidParamMatchesNullptr(base::NullPtr));
+}
+
+TEST(NullptrTest, IntParamsDontMatch) {
+ int dummy_param = 0;
+ EXPECT_FALSE(IntParamMatchesNullptr(dummy_param));
+ EXPECT_TRUE(IntParamMatchesNullptr(base::NullPtr));
+}
+
+TEST(NullptrTest, TemplateMethodParamsDontMatch) {
+ void* dummy_param = NULL;
+ EXPECT_FALSE(TemplateMethodMatchesNullptr(dummy_param));
+ EXPECT_TRUE(TemplateMethodMatchesNullptr(base::NullPtr));
+}
« no previous file with comments | « base/nullptr.cc ('k') | build/build_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698