summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-01 17:01:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-01 17:01:54 +0000
commit048afc6aba4848d5296affb4335500f960262580 (patch)
tree1cef231f4c264542412b8ad67db4f622f8eea81d /testing
parentb5902c78075141d9d569a463486d20ccabd78a2d (diff)
downloadpdfium-048afc6aba4848d5296affb4335500f960262580.tar.xz
Fix CFX_XML and add unit tests
This CL fixes several issues in the CFX_XML class and adds unit tests. Change-Id: I05270690de8f3c45dceb866e17ef899ae6d23389 Reviewed-on: https://pdfium-review.googlesource.com/31753 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'testing')
-rw-r--r--testing/string_write_stream.cpp32
-rw-r--r--testing/string_write_stream.h30
2 files changed, 62 insertions, 0 deletions
diff --git a/testing/string_write_stream.cpp b/testing/string_write_stream.cpp
new file mode 100644
index 0000000000..47474389c5
--- /dev/null
+++ b/testing/string_write_stream.cpp
@@ -0,0 +1,32 @@
+// Copyright 2018 PDFium 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 "testing/string_write_stream.h"
+#include "core/fxcrt/bytestring.h"
+#include "core/fxcrt/widestring.h"
+
+StringWriteStream::StringWriteStream() = default;
+
+StringWriteStream::~StringWriteStream() = default;
+
+FX_FILESIZE StringWriteStream::GetSize() {
+ return stream_.tellp();
+}
+
+bool StringWriteStream::Flush() {
+ return true;
+}
+
+bool StringWriteStream::WriteBlock(const void* pData,
+ FX_FILESIZE offset,
+ size_t size) {
+ ASSERT(offset == 0);
+ stream_.write(static_cast<const char*>(pData), size);
+ return true;
+}
+
+bool StringWriteStream::WriteString(const ByteStringView& str) {
+ stream_.write(str.unterminated_c_str(), str.GetLength());
+ return true;
+}
diff --git a/testing/string_write_stream.h b/testing/string_write_stream.h
new file mode 100644
index 0000000000..7d28a8267d
--- /dev/null
+++ b/testing/string_write_stream.h
@@ -0,0 +1,30 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_STRING_WRITE_STREAM_H_
+#define TESTING_STRING_WRITE_STREAM_H_
+
+#include <sstream>
+#include <string>
+
+#include "core/fxcrt/fx_stream.h"
+
+class StringWriteStream : public IFX_SeekableWriteStream {
+ public:
+ StringWriteStream();
+ ~StringWriteStream() override;
+
+ // IFX_SeekableWriteStream
+ FX_FILESIZE GetSize() override;
+ bool Flush() override;
+ bool WriteBlock(const void* pData, FX_FILESIZE offset, size_t size) override;
+ bool WriteString(const ByteStringView& str) override;
+
+ std::string ToString() const { return stream_.str(); }
+
+ private:
+ std::ostringstream stream_;
+};
+
+#endif // TESTING_STRING_WRITE_STREAM_H_