summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-17 16:14:59 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-17 16:14:59 +0000
commit501adac7aa2951dca2dfbb50d37b2d307e7af915 (patch)
tree3e173ab2fb8008978fe733065fd399a03a683710 /unittests
parent12a9dc8c14301ae199f2c2d6ab55cc5c995101cd (diff)
downloadllvm-501adac7aa2951dca2dfbb50d37b2d307e7af915.tar.gz
llvm-501adac7aa2951dca2dfbb50d37b2d307e7af915.tar.bz2
llvm-501adac7aa2951dca2dfbb50d37b2d307e7af915.tar.xz
Minimal raw_ostream unit tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Makefile2
-rw-r--r--unittests/Support/Makefile15
-rw-r--r--unittests/Support/raw_ostream.cpp85
3 files changed, 101 insertions, 1 deletions
diff --git a/unittests/Makefile b/unittests/Makefile
index d96df4f52d..2a13b8d536 100644
--- a/unittests/Makefile
+++ b/unittests/Makefile
@@ -16,7 +16,7 @@ BUILD_ARCHIVE = 1
CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
CPP.Flags += -Wno-variadic-macros
-PARALLEL_DIRS = ADT
+PARALLEL_DIRS = ADT Support
include $(LEVEL)/Makefile.common
diff --git a/unittests/Support/Makefile b/unittests/Support/Makefile
new file mode 100644
index 0000000000..815bdd269d
--- /dev/null
+++ b/unittests/Support/Makefile
@@ -0,0 +1,15 @@
+##===- unittests/ADT/Makefile ------------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TESTNAME = Support
+LINK_COMPONENTS := core support
+
+include $(LEVEL)/Makefile.config
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/unittests/Support/raw_ostream.cpp b/unittests/Support/raw_ostream.cpp
new file mode 100644
index 0000000000..7b86b2341a
--- /dev/null
+++ b/unittests/Support/raw_ostream.cpp
@@ -0,0 +1,85 @@
+//===- llvm/unittest/Support/raw_ostream.cpp - raw_ostream unit tests -----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+
+template<typename T> std::string printToString(const T &Value) {
+ std::string res;
+ llvm::raw_string_ostream(res) << Value;
+ return res;
+}
+
+template<typename T> std::string printToStringUnbuffered(const T &Value) {
+ std::string res;
+ llvm::raw_string_ostream OS(res);
+ OS.SetUnbuffered();
+ OS << Value;
+ return res;
+}
+
+TEST(raw_ostreamTest, Types_Buffered) {
+ // Char
+ EXPECT_EQ("c", printToString('c'));
+
+ // String
+ EXPECT_EQ("hello", printToString("hello"));
+ EXPECT_EQ("hello", printToString(std::string("hello")));
+
+ // Int
+ EXPECT_EQ("0", printToString(0));
+ EXPECT_EQ("2425", printToString(2425));
+ EXPECT_EQ("-2425", printToString(-2425));
+
+ // Long long
+ EXPECT_EQ("0", printToString(0LL));
+ EXPECT_EQ("257257257235709", printToString(257257257235709LL));
+ EXPECT_EQ("-257257257235709", printToString(-257257257235709LL));
+
+ // Double
+ EXPECT_EQ("1.100000e+00", printToString(1.1));
+
+ // void*
+ EXPECT_EQ("0x0", printToString((void*) 0));
+ EXPECT_EQ("0xbeef", printToString((void*) 0xbeef));
+ EXPECT_EQ("0xdeadbeef", printToString((void*) 0xdeadbeef));
+}
+
+TEST(raw_ostreamTest, Types_Unbuffered) {
+ // Char
+ EXPECT_EQ("c", printToStringUnbuffered('c'));
+
+ // String
+ EXPECT_EQ("hello", printToStringUnbuffered("hello"));
+ EXPECT_EQ("hello", printToStringUnbuffered(std::string("hello")));
+
+ // Int
+ EXPECT_EQ("0", printToStringUnbuffered(0));
+ EXPECT_EQ("2425", printToStringUnbuffered(2425));
+ EXPECT_EQ("-2425", printToStringUnbuffered(-2425));
+
+ // Long long
+ EXPECT_EQ("0", printToStringUnbuffered(0LL));
+ EXPECT_EQ("257257257235709", printToStringUnbuffered(257257257235709LL));
+ EXPECT_EQ("-257257257235709", printToStringUnbuffered(-257257257235709LL));
+
+ // Double
+ EXPECT_EQ("1.100000e+00", printToStringUnbuffered(1.1));
+
+ // void*
+ EXPECT_EQ("0x0", printToStringUnbuffered((void*) 0));
+ EXPECT_EQ("0xbeef", printToStringUnbuffered((void*) 0xbeef));
+ EXPECT_EQ("0xdeadbeef", printToStringUnbuffered((void*) 0xdeadbeef));
+}
+
+}