[llvm-commits] [llvm] r67083 - in /llvm/trunk/unittests: Makefile Support/ Support/Makefile Support/raw_ostream.cpp
Daniel Dunbar
daniel at zuster.org
Tue Mar 17 09:15:03 PDT 2009
Author: ddunbar
Date: Tue Mar 17 11:14:59 2009
New Revision: 67083
URL: http://llvm.org/viewvc/llvm-project?rev=67083&view=rev
Log:
Minimal raw_ostream unit tests
Added:
llvm/trunk/unittests/Support/ (with props)
llvm/trunk/unittests/Support/Makefile
llvm/trunk/unittests/Support/raw_ostream.cpp
Modified:
llvm/trunk/unittests/Makefile
Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=67083&r1=67082&r2=67083&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Tue Mar 17 11:14:59 2009
@@ -16,7 +16,7 @@
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
Propchange: llvm/trunk/unittests/Support/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Mar 17 11:14:59 2009
@@ -0,0 +1,4 @@
+Debug
+Release
+Release-Asserts
+
Added: llvm/trunk/unittests/Support/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Makefile?rev=67083&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/Makefile (added)
+++ llvm/trunk/unittests/Support/Makefile Tue Mar 17 11:14:59 2009
@@ -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
Added: llvm/trunk/unittests/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/raw_ostream.cpp?rev=67083&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/raw_ostream.cpp (added)
+++ llvm/trunk/unittests/Support/raw_ostream.cpp Tue Mar 17 11:14:59 2009
@@ -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));
+}
+
+}
More information about the llvm-commits
mailing list