summaryrefslogtreecommitdiffstats
path: root/base/template_util_unittest.cc
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 01:27:38 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 01:27:38 +0000
commitb38d3578e53d0a7f441c6858334a2d9f08e5c024 (patch)
tree917a1d893c40fd10408e172b1a66cba692a0fedc /base/template_util_unittest.cc
parentc41fe6697e38057138cbe33332d9882e0d7d9b4b (diff)
downloadchromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.zip
chromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.tar.gz
chromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.tar.bz2
Unified callback system based on tr1::function/tr1::bind and Google's internal callback code.
This callback system allows for creation of functors for normal functions, methods, and const methods. It is a superset of the functionality of NewRunnableMethod, NewRunnableFunction, NewCallback, and CreateFunctor. We support partial binding of function arguments, and also specification of refcounting semantics by wrapping a target object in a wrapper object. BUG=35223 TEST=none Review URL: http://codereview.chromium.org/6109007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/template_util_unittest.cc')
-rw-r--r--base/template_util_unittest.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc
new file mode 100644
index 0000000..020872a
--- /dev/null
+++ b/base/template_util_unittest.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2011 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/template_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace {
+
+struct AStruct {};
+class AClass {};
+enum AnEnum {};
+
+class Parent {};
+class Child : public Parent {};
+
+TEST(TemplateUtilTest, IsPointer) {
+ EXPECT_FALSE(is_pointer<int>::value);
+ EXPECT_FALSE(is_pointer<int&>::value);
+ EXPECT_TRUE(is_pointer<int*>::value);
+ EXPECT_TRUE(is_pointer<const int*>::value);
+}
+
+TEST(TemplateUtilTest, IsArray) {
+ EXPECT_FALSE(is_array<int>::value);
+ EXPECT_FALSE(is_array<int*>::value);
+ EXPECT_FALSE(is_array<int(*)[3]>::value);
+ EXPECT_TRUE(is_array<int[]>::value);
+ EXPECT_TRUE(is_array<const int[]>::value);
+ EXPECT_TRUE(is_array<int[3]>::value);
+}
+
+TEST(TemplateUtilTest, IsNonConstReference) {
+ EXPECT_FALSE(is_non_const_reference<int>::value);
+ EXPECT_FALSE(is_non_const_reference<const int&>::value);
+ EXPECT_TRUE(is_non_const_reference<int&>::value);
+}
+
+#if !defined(OS_WIN)
+// TODO(ajwong): Why is is_convertible disabled on windows?
+TEST(TemplateUtilTest, IsConvertible) {
+ // Extra parents needed to make EXPECT_*'s parsing happy. Otherwise,
+ // it sees the equivalent of
+ //
+ // EXPECT_TRUE( (is_convertible < Child), (Parent > ::value));
+ //
+ // Silly C++.
+ EXPECT_TRUE( (is_convertible<Child, Parent>::value) );
+ EXPECT_FALSE( (is_convertible<Parent, Child>::value) );
+}
+#endif // !defined(OS_WIN)
+
+TEST(TemplateUtilTest, IsClass) {
+ EXPECT_EQ(true, is_class<AStruct>::value);
+ EXPECT_EQ(true, is_class<AClass>::value);
+
+ EXPECT_EQ(false, is_class<AnEnum>::value);
+ EXPECT_EQ(false, is_class<int>::value);
+ EXPECT_EQ(false, is_class<char*>::value);
+ EXPECT_EQ(false, is_class<int&>::value);
+ EXPECT_EQ(false, is_class<char[3]>::value);
+}
+
+} // namespace
+} // namespace base