diff options
Diffstat (limited to 'tests/utility')
-rw-r--r-- | tests/utility/encoder/encoderTestUtils.hpp | 8 | ||||
-rw-r--r-- | tests/utility/outputStreamSocketAdapterTest.cpp | 6 | ||||
-rw-r--r-- | tests/utility/seekableInputStreamRegionAdapterTest.cpp | 30 | ||||
-rw-r--r-- | tests/utility/smartPtrTest.cpp | 241 |
4 files changed, 24 insertions, 261 deletions
diff --git a/tests/utility/encoder/encoderTestUtils.hpp b/tests/utility/encoder/encoderTestUtils.hpp index 0eb93871..d74c4709 100644 --- a/tests/utility/encoder/encoderTestUtils.hpp +++ b/tests/utility/encoder/encoderTestUtils.hpp @@ -23,10 +23,10 @@ // Helper function to obtain an encoder given its name -static vmime::ref <vmime::utility::encoder::encoder> getEncoder(const vmime::string& name, +static vmime::shared_ptr <vmime::utility::encoder::encoder> getEncoder(const vmime::string& name, int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet()) { - vmime::ref <vmime::utility::encoder::encoder> enc = + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = vmime::utility::encoder::encoderFactory::getInstance()->create(name); enc->getProperties() = props; @@ -42,7 +42,7 @@ static vmime::ref <vmime::utility::encoder::encoder> getEncoder(const vmime::str static const vmime::string encode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet()) { - vmime::ref <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength, props); + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength, props); vmime::utility::inputStreamStringAdapter vin(in); @@ -58,7 +58,7 @@ static const vmime::string encode(const vmime::string& name, const vmime::string // Decoding helper function static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0) { - vmime::ref <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength); + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength); vmime::utility::inputStreamStringAdapter vin(in); diff --git a/tests/utility/outputStreamSocketAdapterTest.cpp b/tests/utility/outputStreamSocketAdapterTest.cpp index 920c7f47..417eff8b 100644 --- a/tests/utility/outputStreamSocketAdapterTest.cpp +++ b/tests/utility/outputStreamSocketAdapterTest.cpp @@ -37,7 +37,7 @@ VMIME_TEST_SUITE_BEGIN(outputStreamSocketAdapterTest) void testWrite() { - vmime::ref <testSocket> socket = vmime::create <testSocket>(); + vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); vmime::utility::outputStreamSocketAdapter stream(*socket); stream << "some data"; @@ -55,7 +55,7 @@ VMIME_TEST_SUITE_BEGIN(outputStreamSocketAdapterTest) "\xc5\x9a\xc3\xb8\xc9\xb1\xc9\x9b\x20\xc9\x93\xc9\xa8\xc9\xb2\xc9" "\x91\xc5\x95\xc9\xa3\x20\xc9\x96\xc9\x90\xca\x88\xc9\x92"; - vmime::ref <testSocket> socket = vmime::create <testSocket>(); + vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); vmime::utility::outputStreamSocketAdapter stream(*socket); stream.write(binaryData, sizeof(binaryData)); @@ -69,7 +69,7 @@ VMIME_TEST_SUITE_BEGIN(outputStreamSocketAdapterTest) void testWriteCRLF() { - vmime::ref <testSocket> socket = vmime::create <testSocket>(); + vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); vmime::utility::outputStreamSocketAdapter stream(*socket); stream << "some data"; diff --git a/tests/utility/seekableInputStreamRegionAdapterTest.cpp b/tests/utility/seekableInputStreamRegionAdapterTest.cpp index 3ed024e8..1c33c056 100644 --- a/tests/utility/seekableInputStreamRegionAdapterTest.cpp +++ b/tests/utility/seekableInputStreamRegionAdapterTest.cpp @@ -42,16 +42,16 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) VMIME_TEST_LIST_END - vmime::ref <seekableInputStreamRegionAdapter> createStream - (vmime::ref <seekableInputStream>* underlyingStream = NULL) + vmime::shared_ptr <seekableInputStreamRegionAdapter> createStream + (vmime::shared_ptr <seekableInputStream>* underlyingStream = NULL) { vmime::string buffer("THIS IS A TEST BUFFER"); - vmime::ref <seekableInputStream> strStream = - vmime::create <inputStreamStringAdapter>(buffer); + vmime::shared_ptr <seekableInputStream> strStream = + vmime::make_shared <inputStreamStringAdapter>(buffer); - vmime::ref <seekableInputStreamRegionAdapter> rgnStream = - vmime::create <seekableInputStreamRegionAdapter>(strStream, 10, 11); + vmime::shared_ptr <seekableInputStreamRegionAdapter> rgnStream = + vmime::make_shared <seekableInputStreamRegionAdapter>(strStream, 10, 11); if (underlyingStream) *underlyingStream = strStream; @@ -61,7 +61,7 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) void testInitialPosition() { - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(); + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(); VASSERT_EQ("Pos", 0, stream->getPosition()); VASSERT_FALSE("EOF", stream->eof()); @@ -69,7 +69,7 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) void testSeekAndGetPosition() { - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(); + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(); stream->seek(5); @@ -84,11 +84,12 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) void testRead() { - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(); + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(); stream->seek(5); stream::value_type buffer[100]; + std::fill(vmime::begin(buffer), vmime::end(buffer), 0); stream::size_type read = stream->read(buffer, 6); VASSERT_EQ("Pos", 11, stream->getPosition()); @@ -99,7 +100,7 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) void testSkip() { - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(); + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(); stream->skip(5); @@ -107,6 +108,7 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) VASSERT_FALSE("EOF 1", stream->eof()); stream::value_type buffer[100]; + std::fill(vmime::begin(buffer), vmime::end(buffer), 0); stream::size_type read = stream->read(buffer, 3); VASSERT_EQ("Pos 2", 8, stream->getPosition()); @@ -122,7 +124,7 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) void testReset() { - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(); + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(); stream->skip(100); stream->reset(); @@ -136,15 +138,17 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) // seekableInputStreamRegionAdapter should keep track of its own position // in the underlying stream, and not be affected by possible seek/read // operations on it... - vmime::ref <seekableInputStream> ustream; - vmime::ref <seekableInputStreamRegionAdapter> stream = createStream(&ustream); + vmime::shared_ptr <seekableInputStream> ustream; + vmime::shared_ptr <seekableInputStreamRegionAdapter> stream = createStream(&ustream); stream->seek(5); stream::value_type buffer1[100]; + std::fill(vmime::begin(buffer1), vmime::end(buffer1), 0); stream::size_type read = ustream->read(buffer1, 7); stream::value_type buffer2[100]; + std::fill(vmime::begin(buffer2), vmime::end(buffer2), 0); stream::size_type read2 = stream->read(buffer2, 6); VASSERT_EQ("Buffer 1", "THIS IS", vmime::string(buffer1, 0, 7)); diff --git a/tests/utility/smartPtrTest.cpp b/tests/utility/smartPtrTest.cpp deleted file mode 100644 index 584adf3b..00000000 --- a/tests/utility/smartPtrTest.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// -// VMime library (http://www.vmime.org) -// Copyright (C) 2002-2013 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 3 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// Linking this library statically or dynamically with other modules is making -// a combined work based on this library. Thus, the terms and conditions of -// the GNU General Public License cover the whole combination. -// - -#include "tests/testUtils.hpp" - -#include "vmime/utility/smartPtr.hpp" - - -VMIME_TEST_SUITE_BEGIN(smartPtrTest) - - VMIME_TEST_LIST_BEGIN - VMIME_TEST(testNull) - VMIME_TEST(testRefCounting) - VMIME_TEST(testWeakRef) - VMIME_TEST(testCast) - VMIME_TEST(testContainer) - VMIME_TEST(testCompare) - VMIME_TEST_LIST_END - - - struct A : public vmime::object - { - int strongCount() const { return getRefManager()->getStrongRefCount(); } - int weakCount() const { return getRefManager()->getWeakRefCount(); } - }; - - struct B : public virtual A { }; - struct C : public virtual A { }; - struct D : public B, public C { }; - - class R : public A - { - public: - - R(bool* aliveFlag) : m_aliveFlag(aliveFlag) { *m_aliveFlag = true; } - ~R() { *m_aliveFlag = false; } - - private: - - bool* m_aliveFlag; - }; - - - void testNull() - { - vmime::ref <A> r1; - - VASSERT("1", r1 == NULL); - VASSERT("2", r1 == 0); - VASSERT("3", NULL == r1); - VASSERT("4", 0 == r1); - VASSERT("5", !r1); - VASSERT("6", r1 == vmime::null); - VASSERT("7", vmime::null == r1); - VASSERT_EQ("8", static_cast <A*>(0), r1.get()); - } - - void testRefCounting() - { - bool o1_alive; - vmime::ref <R> r1 = vmime::create <R>(&o1_alive); - - VASSERT("1", r1.get() != 0); - VASSERT("2", o1_alive); - VASSERT_EQ("3", 1, r1->strongCount()); - VASSERT_EQ("4", 1, r1->weakCount()); - - vmime::ref <R> r2 = r1; - - VASSERT("5", o1_alive); - VASSERT_EQ("6", 2, r1->strongCount()); - VASSERT_EQ("7", 2, r1->weakCount()); - - bool o2_alive; - vmime::ref <R> r3 = vmime::create <R>(&o2_alive); - - r2 = r3; - - VASSERT("8", o1_alive); - VASSERT("9", o2_alive); - VASSERT_EQ("10", 1, r1->strongCount()); - VASSERT_EQ("11", 2, r2->strongCount()); - VASSERT_EQ("12", 2, r3->strongCount()); - - { - vmime::ref <R> r4; - - r4 = r1; - - VASSERT("13", o1_alive); - VASSERT("14", o2_alive); - VASSERT_EQ("15", 2, r4->strongCount()); - VASSERT_EQ("16", 2, r1->strongCount()); - - r1 = NULL; - - VASSERT("17", o1_alive); - VASSERT("18", o2_alive); - VASSERT_EQ("19", 1, r4->strongCount()); - - // Here, object1 will be deleted - } - - VASSERT("20", !o1_alive); - VASSERT("21", o2_alive); - - { - vmime::weak_ref <R> w1 = r3; - - VASSERT_EQ("22", 3, r3->weakCount()); - } - - VASSERT("23", o2_alive); - VASSERT_EQ("24", 2, r3->strongCount()); - VASSERT_EQ("25", 2, r3->weakCount()); - } - - void testWeakRef() - { - vmime::ref <A> r1 = vmime::create <A>(); - vmime::weak_ref <A> w1 = r1; - - VASSERT("1", r1.get() != 0); - VASSERT("2", r1.get() == w1.acquire().get()); - - { - vmime::ref <A> r2 = r1; - - VASSERT("3", r1.get() == r2.get()); - VASSERT("4", r1.get() == w1.acquire().get()); - } - - VASSERT("5", r1.get() != 0); - VASSERT("6", r1.get() == w1.acquire().get()); - - r1 = 0; - - VASSERT("7", w1.acquire().get() == 0); - } - - void testCast() - { - // Explicit upcast - vmime::ref <A> r1 = vmime::create <C>(); - vmime::ref <C> r2 = r1.dynamicCast <C>(); - - VASSERT("1", r2.get() == dynamic_cast <C*>(r1.get())); - VASSERT("2", 0 == r1.dynamicCast <B>().get()); - - // Implicit downcast - vmime::ref <D> r3 = vmime::create <D>(); - vmime::ref <A> r4 = r3; - - VASSERT("3", r4.get() == dynamic_cast <A*>(r3.get())); - } - - void testContainer() - { - bool o1_alive; - vmime::ref <R> r1 = vmime::create <R>(&o1_alive); - - bool o2_alive; - vmime::ref <R> r2 = vmime::create <R>(&o2_alive); - - std::vector <vmime::ref <R> > v1; - v1.push_back(r1); - v1.push_back(r2); - - VASSERT("1", o1_alive); - VASSERT_EQ("2", 2, r1->strongCount()); - VASSERT("3", o2_alive); - VASSERT_EQ("4", 2, r2->strongCount()); - - { - std::vector <vmime::ref <R> > v2 = v1; - - VASSERT("5", o1_alive); - VASSERT_EQ("6", 3, r1->strongCount()); - VASSERT("7", o2_alive); - VASSERT_EQ("8", 3, r2->strongCount()); - - v2[1] = NULL; - - VASSERT("9", o1_alive); - VASSERT_EQ("10", 3, r1->strongCount()); - VASSERT("11", o2_alive); - VASSERT_EQ("12", 2, r2->strongCount()); - } - - VASSERT("13", o1_alive); - VASSERT_EQ("14", 2, r1->strongCount()); - VASSERT("15", o2_alive); - VASSERT_EQ("16", 2, r2->strongCount()); - } - - void testCompare() - { - vmime::ref <A> r1 = vmime::create <A>(); - vmime::ref <A> r2 = vmime::create <B>(); - vmime::ref <A> r3 = vmime::create <C>(); - vmime::ref <A> r4 = r1; - - VASSERT("1", r1 != r2); - VASSERT("2", r1.get() == r1); - VASSERT("3", r1 == r1.get()); - VASSERT("4", r2 != r1.get()); - VASSERT("5", r1.get() != r2); - VASSERT("6", r1 == r4); - VASSERT("7", r1.get() == r4); - - std::vector <vmime::ref <A> > v; - v.push_back(r1); - v.push_back(r2); - - VASSERT("8", std::find(v.begin(), v.end(), r1) == v.begin()); - VASSERT("9", std::find(v.begin(), v.end(), r2) == v.begin() + 1); - VASSERT("10", std::find(v.begin(), v.end(), r3) == v.end()); - } - -VMIME_TEST_SUITE_END - |