summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Dionne <ldionne@apple.com>2019-02-27 01:29:09 +0000
committerLouis Dionne <ldionne@apple.com>2019-02-27 01:29:09 +0000
commit62f3900715b425ad8c43227bc0b4442197ae7635 (patch)
treed0537d2b49f4c5e50af515e91a0a6d9251a7105d
parent4b0f7f99ce137c7fe06a29d91c2abe23d53be8a1 (diff)
downloadbcm5719-llvm-62f3900715b425ad8c43227bc0b4442197ae7635.tar.gz
bcm5719-llvm-62f3900715b425ad8c43227bc0b4442197ae7635.zip
[libc++] Add a test for PR14074
PR14074 was fixed in r165884, but no tests were added. llvm-svn: 354943
-rw-r--r--libcxx/test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/libcxx/test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp b/libcxx/test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp
new file mode 100644
index 00000000000..1180008e463
--- /dev/null
+++ b/libcxx/test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <streambuf>
+
+// template <class charT, class traits = char_traits<charT> >
+// class basic_streambuf;
+
+// streamsize xsputn(const char_type* s, streamsize n);
+
+// Test https://bugs.llvm.org/show_bug.cgi?id=14074. The bug is really inside
+// basic_streambuf, but I can't seem to reproduce without going through one
+// of its derived classes.
+
+#include <cassert>
+#include <cstddef>
+#include <cstdio>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include "platform_support.h"
+
+
+// Count the number of bytes in a file -- make sure to use only functionality
+// provided by the C library to avoid relying on the C++ library, which we're
+// trying to test.
+static std::size_t count_bytes(char const* filename) {
+ std::FILE* f = std::fopen(filename, "rb");
+ std::size_t count = 0;
+ while (std::fgetc(f) != EOF)
+ ++count;
+ return count;
+}
+
+int main(int, char**) {
+ {
+ // with basic_stringbuf
+ std::basic_stringbuf<char> buf;
+ std::streamsize sz = buf.sputn("\xFF", 1);
+ assert(sz == 1);
+ assert(buf.str().size() == 1);
+ }
+ {
+ // with basic_filebuf
+ std::string temp = get_temp_file_name();
+ {
+ std::basic_filebuf<char> buf;
+ buf.open(temp.c_str(), std::ios_base::out);
+ std::streamsize sz = buf.sputn("\xFF", 1);
+ assert(sz == 1);
+ }
+ assert(count_bytes(temp.c_str()) == 1);
+ std::remove(temp.c_str());
+ }
+
+ return 0;
+}
OpenPOWER on IntegriCloud