Teach symstore more duplicated DLLs
[LibreOffice.git] / io / qa / textinputstream.cxx
blobdfeb478f975cbb332ba556398c2dead110f10a10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <algorithm>
13 #include <cassert>
14 #include <cstring>
16 #include <com/sun/star/io/NotConnectedException.hpp>
17 #include <com/sun/star/io/TextInputStream.hpp>
18 #include <com/sun/star/io/XInputStream.hpp>
19 #include <com/sun/star/io/XTextInputStream2.hpp>
20 #include <com/sun/star/uno/Sequence.hxx>
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <cppuhelper/implbase.hxx>
23 #include <cppunit/TestAssert.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/plugin/TestPlugIn.h>
26 #include <osl/mutex.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <unotest/bootstrapfixturebase.hxx>
31 namespace {
33 class Input: public cppu::WeakImplHelper<css::io::XInputStream> {
34 public:
35 Input(): open_(true), index_(0) {}
37 private:
38 virtual ~Input() override {}
40 sal_Int32 SAL_CALL readBytes(css::uno::Sequence<sal_Int8> &, sal_Int32)
41 override
42 { CPPUNIT_FAIL("readLine is supposed to call readSomeBytes instead"); }
44 sal_Int32 SAL_CALL readSomeBytes(
45 css::uno::Sequence<sal_Int8 > & aData, sal_Int32 nMaxBytesToRead) override
47 assert(nMaxBytesToRead >= 0);
48 osl::MutexGuard g(mutex_);
49 checkClosed();
50 assert(index_ >= 0 && index_ <= SIZE);
51 sal_Int32 n = std::min<sal_Int32>(
52 std::min<sal_Int32>(nMaxBytesToRead, 2), SIZE - index_);
53 assert(n >= 0 && n <= SIZE - index_);
54 aData.realloc(n);
55 std::memcpy(aData.getArray(), data + index_, n);
56 index_ += n;
57 assert(index_ >= 0 && index_ <= SIZE);
58 return n;
61 void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
63 assert(nBytesToSkip >= 0);
64 osl::MutexGuard g(mutex_);
65 checkClosed();
66 assert(index_ >= 0 && index_ <= SIZE);
67 index_ += std::min<sal_Int32>(nBytesToSkip, SIZE - index_);
68 assert(index_ >= 0 && index_ <= SIZE);
71 sal_Int32 SAL_CALL available() override
73 osl::MutexGuard g(mutex_);
74 checkClosed();
75 assert(index_ >= 0 && index_ <= SIZE);
76 return SIZE - index_;
79 void SAL_CALL closeInput() override
81 osl::MutexGuard g(mutex_);
82 checkClosed();
83 open_ = true;
86 void checkClosed() {
87 if (!open_) {
88 throw css::io::NotConnectedException(
89 "test input stream already closed");
93 static sal_Int32 const SIZE = 9;
94 static char const data[SIZE];
96 osl::Mutex mutex_;
97 bool open_;
98 sal_Int32 index_;
101 char const Input::data[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
103 class Test: public test::BootstrapFixtureBase {
104 private:
105 CPPUNIT_TEST_SUITE(Test);
106 CPPUNIT_TEST(testReadLine);
107 CPPUNIT_TEST_SUITE_END();
109 void testReadLine();
112 void Test::testReadLine() {
113 css::uno::Reference<css::io::XTextInputStream2> s(
114 css::io::TextInputStream::create(getComponentContext()));
115 s->setInputStream(new Input);
116 OUString l(s->readLine());
117 CPPUNIT_ASSERT_EQUAL(OUString("123456789"), l);
120 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
124 CPPUNIT_PLUGIN_IMPLEMENT();
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */