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)); |
+} |