llvm.org GIT mirror llvm / 10097bd
formatted_raw_ostream: Fix a serious bug in tell(). - The current_pos function is supposed to return all the written bytes, not the current position of the underlying stream. - This caused tell() to be broken whenever the underlying stream had buffered content. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163948 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 8 years ago
3 changed file(s) with 39 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
5959 /// current_pos - Return the current position within the stream,
6060 /// not counting the bytes currently in the buffer.
6161 virtual uint64_t current_pos() const {
62 // This has the same effect as calling TheStream.current_pos(),
63 // but that interface is private.
64 return TheStream->tell() - TheStream->GetNumBytesInBuffer();
62 // Our current position in the stream is all the contents which have been
63 // written to the underlying stream (*not* the current position of the
64 // underlying stream).
65 return TheStream->tell();
6566 }
6667
6768 /// ComputeColumn - Examine the given output buffer and figure out which
1717 ManagedStatic.cpp
1818 MathExtrasTest.cpp
1919 Path.cpp
20 raw_ostream_test.cpp
2120 RegexTest.cpp
2221 SwapByteOrderTest.cpp
2322 TimeValue.cpp
2423 ValueHandleTest.cpp
2524 YAMLParserTest.cpp
25 formatted_raw_ostream.cpp
26 raw_ostream_test.cpp
2627 )
0 //===- llvm/unittest/Support/formatted_raw_ostream_test.cpp ---------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include "llvm/Support/FormattedStream.h"
13
14 using namespace llvm;
15
16 namespace {
17
18 TEST(formatted_raw_ostreamTest, Test_Tell) {
19 // Check offset when underlying stream has buffer contents.
20 SmallString<128> A;
21 raw_svector_ostream B(A);
22 formatted_raw_ostream C(B);
23 char tmp[100] = "";
24
25 for (unsigned i = 0; i != 3; ++i) {
26 C.write(tmp, 100);
27
28 EXPECT_EQ(100*(i+1), (unsigned) C.tell());
29 }
30 }
31
32 }