diff options
Diffstat (limited to 'tests/utility')
-rw-r--r-- | tests/utility/filteredStreamTest.cpp | 423 | ||||
-rw-r--r-- | tests/utility/md5Test.cpp | 160 | ||||
-rw-r--r-- | tests/utility/pathTest.cpp | 508 | ||||
-rw-r--r-- | tests/utility/smartPtrTest.cpp | 345 | ||||
-rw-r--r-- | tests/utility/stringProxyTest.cpp | 241 | ||||
-rw-r--r-- | tests/utility/stringUtilsTest.cpp | 202 | ||||
-rw-r--r-- | tests/utility/urlTest.cpp | 383 |
7 files changed, 1078 insertions, 1184 deletions
diff --git a/tests/utility/filteredStreamTest.cpp b/tests/utility/filteredStreamTest.cpp index 0552902a..ca974774 100644 --- a/tests/utility/filteredStreamTest.cpp +++ b/tests/utility/filteredStreamTest.cpp @@ -17,274 +17,257 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" - -#include <iostream> -#include <ostream> -#include <algorithm> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" +#include "tests/testUtils.hpp" #include "vmime/utility/filteredStream.hpp" -using namespace unitpp; - -namespace -{ - class filteredStreamTest : public suite - { - class chunkInputStream : public vmime::utility::inputStream - { - private: +#define VMIME_TEST_SUITE filteredStreamTest +#define VMIME_TEST_SUITE_MODULE "Utility" - std::vector <std::string> m_chunks; - std::vector <std::string>::size_type m_index; - public: +VMIME_TEST_SUITE_BEGIN - chunkInputStream() : m_index(0) { } + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testDotFilteredInputStream) + VMIME_TEST(testDotFilteredOutputStream) + VMIME_TEST(testCRLFToLFFilteredOutputStream) + VMIME_TEST(testStopSequenceFilteredInputStream1) + VMIME_TEST(testStopSequenceFilteredInputStreamN_2) + VMIME_TEST(testStopSequenceFilteredInputStreamN_3) + VMIME_TEST_LIST_END - void addChunk(const std::string& chunk) { m_chunks.push_back(chunk); } - const bool eof() const { return (m_index >= m_chunks.size()); } - void reset() { m_index = 0; } + class chunkInputStream : public vmime::utility::inputStream + { + private: - const size_type read(value_type* const data, const size_type /* count */) - { - if (eof()) - return 0; + std::vector <std::string> m_chunks; + std::vector <std::string>::size_type m_index; - const std::string chunk = m_chunks[m_index]; + public: - // Warning: 'count' should be larger than chunk length. - // This is OK for our tests. - std::copy(chunk.begin(), chunk.end(), data); + chunkInputStream() : m_index(0) { } - ++m_index; + void addChunk(const std::string& chunk) { m_chunks.push_back(chunk); } - return chunk.length(); - } + const bool eof() const { return (m_index >= m_chunks.size()); } + void reset() { m_index = 0; } - const size_type skip(const size_type /* count */) - { - // Not supported + const size_type read(value_type* const data, const size_type /* count */) + { + if (eof()) return 0; - } - }; - - const std::string readWhole(vmime::utility::inputStream& is) - { - vmime::utility::stream::value_type buffer[256]; - std::string whole; + const std::string chunk = m_chunks[m_index]; - while (!is.eof()) - { - const vmime::utility::stream::size_type read = - is.read(buffer, sizeof(buffer)); + // Warning: 'count' should be larger than chunk length. + // This is OK for our tests. + std::copy(chunk.begin(), chunk.end(), data); - whole += std::string(buffer, read); - } + ++m_index; - return (whole); + return chunk.length(); } - - // dotFilteredInputStream - - void testDotFilteredInputStreamHelper - (const std::string& number, const std::string& expected, - const std::string& c1, const std::string& c2 = "", - const std::string& c3 = "", const std::string& c4 = "") + const size_type skip(const size_type /* count */) { - chunkInputStream cis; - cis.addChunk(c1); - if (!c2.empty()) cis.addChunk(c2); - if (!c3.empty()) cis.addChunk(c3); - if (!c4.empty()) cis.addChunk(c4); + // Not supported + return 0; + } + }; - vmime::utility::dotFilteredInputStream is(cis); - std::ostringstream oss; - vmime::utility::outputStreamAdapter os(oss); + const std::string readWhole(vmime::utility::inputStream& is) + { + vmime::utility::stream::value_type buffer[256]; + std::string whole; - vmime::utility::bufferedStreamCopy(is, os); + while (!is.eof()) + { + const vmime::utility::stream::size_type read = + is.read(buffer, sizeof(buffer)); - assert_eq(number, expected, oss.str()); + whole += std::string(buffer, read); } - void testDotFilteredInputStream() - { - testDotFilteredInputStreamHelper("1", "foo\n.bar", "foo\n..bar"); - testDotFilteredInputStreamHelper("2", "foo\n.bar", "foo\n", "..bar"); - testDotFilteredInputStreamHelper("3", "foo\n.bar", "foo\n.", ".bar"); - testDotFilteredInputStreamHelper("4", "foo\n.bar", "foo\n..", "bar"); - testDotFilteredInputStreamHelper("5", "foo\n.bar", "foo\n", ".", ".bar"); - testDotFilteredInputStreamHelper("6", "foo\n.bar", "foo\n", ".", ".", "bar"); - } + return (whole); + } - // dotFilteredOutputStream - // CRLFToLFFilteredOutputStream - template <typename FILTER> - void testFilteredOutputStreamHelper - (const std::string& number, const std::string& expected, - const std::string& c1, const std::string& c2 = "", - const std::string& c3 = "", const std::string& c4 = "") - { - std::ostringstream oss; - vmime::utility::outputStreamAdapter os(oss); + // dotFilteredInputStream - FILTER fos(os); + void testDotFilteredInputStreamHelper + (const std::string& number, const std::string& expected, + const std::string& c1, const std::string& c2 = "", + const std::string& c3 = "", const std::string& c4 = "") + { + chunkInputStream cis; + cis.addChunk(c1); + if (!c2.empty()) cis.addChunk(c2); + if (!c3.empty()) cis.addChunk(c3); + if (!c4.empty()) cis.addChunk(c4); - fos.write(c1.data(), c1.length()); - if (!c2.empty()) fos.write(c2.data(), c2.length()); - if (!c3.empty()) fos.write(c3.data(), c3.length()); - if (!c4.empty()) fos.write(c4.data(), c4.length()); + vmime::utility::dotFilteredInputStream is(cis); - assert_eq(number, expected, oss.str()); - } + std::ostringstream oss; + vmime::utility::outputStreamAdapter os(oss); - void testDotFilteredOutputStream() - { - typedef vmime::utility::dotFilteredOutputStream FILTER; + vmime::utility::bufferedStreamCopy(is, os); - testFilteredOutputStreamHelper<FILTER>("1", "foo\n..bar", "foo\n.bar"); - testFilteredOutputStreamHelper<FILTER>("2", "foo\n..bar", "foo\n", ".bar"); - testFilteredOutputStreamHelper<FILTER>("3", "foo\n..bar", "foo", "\n.bar"); - testFilteredOutputStreamHelper<FILTER>("4", "foo\n..bar", "foo", "\n", ".bar"); - testFilteredOutputStreamHelper<FILTER>("5", "foo\n..bar", "foo", "\n", ".", "bar"); - } + VASSERT_EQ(number, expected, oss.str()); + } - void testCRLFToLFFilteredOutputStream() - { - typedef vmime::utility::CRLFToLFFilteredOutputStream FILTER; - - testFilteredOutputStreamHelper<FILTER>("1", "foo\nbar", "foo\r\nbar"); - testFilteredOutputStreamHelper<FILTER>("2", "foo\nbar", "foo\r\n", "bar"); - testFilteredOutputStreamHelper<FILTER>("3", "foo\nbar", "foo\r", "\nbar"); - testFilteredOutputStreamHelper<FILTER>("4", "foo\nbar", "foo", "\r\nbar"); - testFilteredOutputStreamHelper<FILTER>("5", "foo\nbar", "foo", "\r", "\nbar"); - testFilteredOutputStreamHelper<FILTER>("6", "foo\nbar", "foo", "\r", "\n", "bar"); - } + void testDotFilteredInputStream() + { + testDotFilteredInputStreamHelper("1", "foo\n.bar", "foo\n..bar"); + testDotFilteredInputStreamHelper("2", "foo\n.bar", "foo\n", "..bar"); + testDotFilteredInputStreamHelper("3", "foo\n.bar", "foo\n.", ".bar"); + testDotFilteredInputStreamHelper("4", "foo\n.bar", "foo\n..", "bar"); + testDotFilteredInputStreamHelper("5", "foo\n.bar", "foo\n", ".", ".bar"); + testDotFilteredInputStreamHelper("6", "foo\n.bar", "foo\n", ".", ".", "bar"); + } + + // dotFilteredOutputStream + // CRLFToLFFilteredOutputStream + + template <typename FILTER> + void testFilteredOutputStreamHelper + (const std::string& number, const std::string& expected, + const std::string& c1, const std::string& c2 = "", + const std::string& c3 = "", const std::string& c4 = "") + { + std::ostringstream oss; + vmime::utility::outputStreamAdapter os(oss); - // stopSequenceFilteredInputStream + FILTER fos(os); - template <int N> - void testStopSequenceFISHelper - (const std::string& number, const std::string& sequence, - const std::string& expected, const std::string& c1, - const std::string& c2 = "", const std::string& c3 = "", - const std::string& c4 = "", const std::string& c5 = "") - { - chunkInputStream cis; - cis.addChunk(c1); - if (!c2.empty()) cis.addChunk(c2); - if (!c3.empty()) cis.addChunk(c3); - if (!c4.empty()) cis.addChunk(c4); - if (!c5.empty()) cis.addChunk(c5); + fos.write(c1.data(), c1.length()); + if (!c2.empty()) fos.write(c2.data(), c2.length()); + if (!c3.empty()) fos.write(c3.data(), c3.length()); + if (!c4.empty()) fos.write(c4.data(), c4.length()); - vmime::utility::stopSequenceFilteredInputStream <N> is(cis, sequence.data()); + VASSERT_EQ(number, expected, oss.str()); + } - assert_eq(number, expected, readWhole(is)); - } + void testDotFilteredOutputStream() + { + typedef vmime::utility::dotFilteredOutputStream FILTER; - void testStopSequenceFilteredInputStream1() - { - testStopSequenceFISHelper <1>("1", "x", "foo", "fooxbar"); - testStopSequenceFISHelper <1>("2", "x", "foo", "foox", "bar"); - testStopSequenceFISHelper <1>("3", "x", "foo", "foo", "x", "bar"); - testStopSequenceFISHelper <1>("4", "x", "foo", "fo", "o", "x", "bar"); - testStopSequenceFISHelper <1>("5", "x", "foo", "fo", "o", "x", "b", "ar"); - - testStopSequenceFISHelper <1>("6", "x", "foobar", "fo", "o", "b", "ar"); - testStopSequenceFISHelper <1>("7", "x", "foobar", "foo", "bar"); - testStopSequenceFISHelper <1>("8", "x", "foobar", "foo", "b", "ar"); - - testStopSequenceFISHelper <1>("9", "x", "foobar", "foobar"); - testStopSequenceFISHelper <1>("10", "x", "foobar", "foobarx"); - - testStopSequenceFISHelper <1>("11", "x", "", ""); - testStopSequenceFISHelper <1>("12", "x", "", "x"); - testStopSequenceFISHelper <1>("13", "x", "", "", "x"); - } + testFilteredOutputStreamHelper<FILTER>("1", "foo\n..bar", "foo\n.bar"); + testFilteredOutputStreamHelper<FILTER>("2", "foo\n..bar", "foo\n", ".bar"); + testFilteredOutputStreamHelper<FILTER>("3", "foo\n..bar", "foo", "\n.bar"); + testFilteredOutputStreamHelper<FILTER>("4", "foo\n..bar", "foo", "\n", ".bar"); + testFilteredOutputStreamHelper<FILTER>("5", "foo\n..bar", "foo", "\n", ".", "bar"); + } - void testStopSequenceFilteredInputStreamN_2() - { - testStopSequenceFISHelper <2>("1", "xy", "foo", "fooxybar"); - testStopSequenceFISHelper <2>("2", "xy", "foo", "foox", "ybar"); - testStopSequenceFISHelper <2>("3", "xy", "foo", "foox", "y", "bar"); - testStopSequenceFISHelper <2>("4", "xy", "foo", "foo", "x", "ybar"); - testStopSequenceFISHelper <2>("5", "xy", "foo", "foo", "xy", "bar"); - testStopSequenceFISHelper <2>("6", "xy", "foo", "foo", "x", "y", "bar"); - - testStopSequenceFISHelper <2>("7", "xy", "fooxbar", "foox", "bar"); - testStopSequenceFISHelper <2>("8", "xy", "fooxbar", "foo", "xbar"); - testStopSequenceFISHelper <2>("9", "xy", "fooxbar", "foo", "x", "bar"); - testStopSequenceFISHelper <2>("10", "xy", "foobarx", "foo", "barx"); - - testStopSequenceFISHelper <2>("11", "xy", "foobar", "foobarxy"); - testStopSequenceFISHelper <2>("12", "xy", "foobar", "foo", "barxy"); - testStopSequenceFISHelper <2>("13", "xy", "foobar", "foo", "bar", "xy"); - - testStopSequenceFISHelper <2>("14", "xy", "", ""); - testStopSequenceFISHelper <2>("15", "xy", "x", "x"); - testStopSequenceFISHelper <2>("16", "xy", "", "xy"); - testStopSequenceFISHelper <2>("17", "xy", "", "x", "y"); - } + void testCRLFToLFFilteredOutputStream() + { + typedef vmime::utility::CRLFToLFFilteredOutputStream FILTER; + + testFilteredOutputStreamHelper<FILTER>("1", "foo\nbar", "foo\r\nbar"); + testFilteredOutputStreamHelper<FILTER>("2", "foo\nbar", "foo\r\n", "bar"); + testFilteredOutputStreamHelper<FILTER>("3", "foo\nbar", "foo\r", "\nbar"); + testFilteredOutputStreamHelper<FILTER>("4", "foo\nbar", "foo", "\r\nbar"); + testFilteredOutputStreamHelper<FILTER>("5", "foo\nbar", "foo", "\r", "\nbar"); + testFilteredOutputStreamHelper<FILTER>("6", "foo\nbar", "foo", "\r", "\n", "bar"); + } + + // stopSequenceFilteredInputStream + + template <int N> + void testStopSequenceFISHelper + (const std::string& number, const std::string& sequence, + const std::string& expected, const std::string& c1, + const std::string& c2 = "", const std::string& c3 = "", + const std::string& c4 = "", const std::string& c5 = "") + { + chunkInputStream cis; + cis.addChunk(c1); + if (!c2.empty()) cis.addChunk(c2); + if (!c3.empty()) cis.addChunk(c3); + if (!c4.empty()) cis.addChunk(c4); + if (!c5.empty()) cis.addChunk(c5); - void testStopSequenceFilteredInputStreamN_3() - { - testStopSequenceFISHelper <3>("1", "xyz", "foo", "fooxyzbar"); - testStopSequenceFISHelper <3>("2", "xyz", "foo", "foox", "yzbar"); - testStopSequenceFISHelper <3>("3", "xyz", "foo", "foox", "y", "zbar"); - testStopSequenceFISHelper <3>("4", "xyz", "foo", "foox", "yz", "bar"); - testStopSequenceFISHelper <3>("5", "xyz", "foo", "foo", "xyz", "bar"); - testStopSequenceFISHelper <3>("6", "xyz", "foo", "foo", "xy", "zbar"); - testStopSequenceFISHelper <3>("7", "xyz", "foo", "foo", "x", "y", "zbar"); - testStopSequenceFISHelper <3>("8", "xyz", "foo", "foo", "x", "y", "z", "bar"); - testStopSequenceFISHelper <3>("9", "xyz", "foo", "fooxy", "z", "bar"); - - testStopSequenceFISHelper <3>("10", "xyz", "fooxybar", "foox", "y", "bar"); - testStopSequenceFISHelper <3>("11", "xyz", "fooxybar", "fooxy", "bar"); - testStopSequenceFISHelper <3>("12", "xyz", "fooxybar", "fo", "ox", "y", "bar"); - testStopSequenceFISHelper <3>("13", "xyz", "fooxybar", "fo", "o", "x", "y", "bar"); - testStopSequenceFISHelper <3>("14", "xyz", "fooxybar", "foo", "x", "ybar"); - testStopSequenceFISHelper <3>("15", "xyz", "fooxybar", "foo", "xybar"); - - testStopSequenceFISHelper <3>("16", "xyz", "xfoxoxybxar", "xfoxo", "xybxar"); - testStopSequenceFISHelper <3>("17", "xyz", "xfoxoxybxarx", "xfoxo", "xybxarx"); - testStopSequenceFISHelper <3>("18", "xyz", "xfoxoxybxarxy", "xfoxo", "xybxarxy"); - - testStopSequenceFISHelper <3>("19", "xyz", "", ""); - testStopSequenceFISHelper <3>("20", "xyz", "x", "x"); - testStopSequenceFISHelper <3>("21", "xyz", "xy", "xy"); - testStopSequenceFISHelper <3>("22", "xyz", "", "xyz"); - testStopSequenceFISHelper <3>("23", "xyz", "", "x", "yz"); - testStopSequenceFISHelper <3>("24", "xyz", "", "x", "y", "z"); - } + vmime::utility::stopSequenceFilteredInputStream <N> is(cis, sequence.data()); - public: + VASSERT_EQ(number, expected, readWhole(is)); + } - filteredStreamTest() : suite("vmime::utility::filteredStream") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); + void testStopSequenceFilteredInputStream1() + { + testStopSequenceFISHelper <1>("1", "x", "foo", "fooxbar"); + testStopSequenceFISHelper <1>("2", "x", "foo", "foox", "bar"); + testStopSequenceFISHelper <1>("3", "x", "foo", "foo", "x", "bar"); + testStopSequenceFISHelper <1>("4", "x", "foo", "fo", "o", "x", "bar"); + testStopSequenceFISHelper <1>("5", "x", "foo", "fo", "o", "x", "b", "ar"); - add("dotFilteredInputStream", testcase(this, "dotFilteredInputStream", &filteredStreamTest::testDotFilteredInputStream)); - add("dotFilteredOutputStream", testcase(this, "dotFilteredOutputStream", &filteredStreamTest::testDotFilteredOutputStream)); - add("CRLFToLFFilteredOutputStream", testcase(this, "CRLFToLFFilteredOutputStream", &filteredStreamTest::testCRLFToLFFilteredOutputStream)); - add("stopSequenceFilteredInputStream1", testcase(this, "stopSequenceFilteredInputStream1", &filteredStreamTest::testStopSequenceFilteredInputStream1)); - add("stopSequenceFilteredInputStreamN_2", testcase(this, "stopSequenceFilteredInputStreamN_2", &filteredStreamTest::testStopSequenceFilteredInputStreamN_2)); - add("stopSequenceFilteredInputStreamN_3", testcase(this, "stopSequenceFilteredInputStreamN_3", &filteredStreamTest::testStopSequenceFilteredInputStreamN_3)); + testStopSequenceFISHelper <1>("6", "x", "foobar", "fo", "o", "b", "ar"); + testStopSequenceFISHelper <1>("7", "x", "foobar", "foo", "bar"); + testStopSequenceFISHelper <1>("8", "x", "foobar", "foo", "b", "ar"); - suite::main().add("vmime::utility::filteredStream", this); - } + testStopSequenceFISHelper <1>("9", "x", "foobar", "foobar"); + testStopSequenceFISHelper <1>("10", "x", "foobar", "foobarx"); - }; + testStopSequenceFISHelper <1>("11", "x", "", ""); + testStopSequenceFISHelper <1>("12", "x", "", "x"); + testStopSequenceFISHelper <1>("13", "x", "", "", "x"); + } - filteredStreamTest* theTest = new filteredStreamTest(); -} + void testStopSequenceFilteredInputStreamN_2() + { + testStopSequenceFISHelper <2>("1", "xy", "foo", "fooxybar"); + testStopSequenceFISHelper <2>("2", "xy", "foo", "foox", "ybar"); + testStopSequenceFISHelper <2>("3", "xy", "foo", "foox", "y", "bar"); + testStopSequenceFISHelper <2>("4", "xy", "foo", "foo", "x", "ybar"); + testStopSequenceFISHelper <2>("5", "xy", "foo", "foo", "xy", "bar"); + testStopSequenceFISHelper <2>("6", "xy", "foo", "foo", "x", "y", "bar"); + + testStopSequenceFISHelper <2>("7", "xy", "fooxbar", "foox", "bar"); + testStopSequenceFISHelper <2>("8", "xy", "fooxbar", "foo", "xbar"); + testStopSequenceFISHelper <2>("9", "xy", "fooxbar", "foo", "x", "bar"); + testStopSequenceFISHelper <2>("10", "xy", "foobarx", "foo", "barx"); + + testStopSequenceFISHelper <2>("11", "xy", "foobar", "foobarxy"); + testStopSequenceFISHelper <2>("12", "xy", "foobar", "foo", "barxy"); + testStopSequenceFISHelper <2>("13", "xy", "foobar", "foo", "bar", "xy"); + + testStopSequenceFISHelper <2>("14", "xy", "", ""); + testStopSequenceFISHelper <2>("15", "xy", "x", "x"); + testStopSequenceFISHelper <2>("16", "xy", "", "xy"); + testStopSequenceFISHelper <2>("17", "xy", "", "x", "y"); + } + + void testStopSequenceFilteredInputStreamN_3() + { + testStopSequenceFISHelper <3>("1", "xyz", "foo", "fooxyzbar"); + testStopSequenceFISHelper <3>("2", "xyz", "foo", "foox", "yzbar"); + testStopSequenceFISHelper <3>("3", "xyz", "foo", "foox", "y", "zbar"); + testStopSequenceFISHelper <3>("4", "xyz", "foo", "foox", "yz", "bar"); + testStopSequenceFISHelper <3>("5", "xyz", "foo", "foo", "xyz", "bar"); + testStopSequenceFISHelper <3>("6", "xyz", "foo", "foo", "xy", "zbar"); + testStopSequenceFISHelper <3>("7", "xyz", "foo", "foo", "x", "y", "zbar"); + testStopSequenceFISHelper <3>("8", "xyz", "foo", "foo", "x", "y", "z", "bar"); + testStopSequenceFISHelper <3>("9", "xyz", "foo", "fooxy", "z", "bar"); + + testStopSequenceFISHelper <3>("10", "xyz", "fooxybar", "foox", "y", "bar"); + testStopSequenceFISHelper <3>("11", "xyz", "fooxybar", "fooxy", "bar"); + testStopSequenceFISHelper <3>("12", "xyz", "fooxybar", "fo", "ox", "y", "bar"); + testStopSequenceFISHelper <3>("13", "xyz", "fooxybar", "fo", "o", "x", "y", "bar"); + testStopSequenceFISHelper <3>("14", "xyz", "fooxybar", "foo", "x", "ybar"); + testStopSequenceFISHelper <3>("15", "xyz", "fooxybar", "foo", "xybar"); + + testStopSequenceFISHelper <3>("16", "xyz", "xfoxoxybxar", "xfoxo", "xybxar"); + testStopSequenceFISHelper <3>("17", "xyz", "xfoxoxybxarx", "xfoxo", "xybxarx"); + testStopSequenceFISHelper <3>("18", "xyz", "xfoxoxybxarxy", "xfoxo", "xybxarxy"); + + testStopSequenceFISHelper <3>("19", "xyz", "", ""); + testStopSequenceFISHelper <3>("20", "xyz", "x", "x"); + testStopSequenceFISHelper <3>("21", "xyz", "xy", "xy"); + testStopSequenceFISHelper <3>("22", "xyz", "", "xyz"); + testStopSequenceFISHelper <3>("23", "xyz", "", "x", "yz"); + testStopSequenceFISHelper <3>("24", "xyz", "", "x", "y", "z"); + } + +VMIME_TEST_SUITE_END diff --git a/tests/utility/md5Test.cpp b/tests/utility/md5Test.cpp index 94fb3cd2..a55fddf7 100644 --- a/tests/utility/md5Test.cpp +++ b/tests/utility/md5Test.cpp @@ -17,96 +17,82 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" +#include "tests/testUtils.hpp" -#include <iostream> -#include <ostream> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" #include "vmime/utility/md5.hpp" -using namespace unitpp; +#define VMIME_TEST_SUITE md5Test +#define VMIME_TEST_SUITE_MODULE "Utility" + + +VMIME_TEST_SUITE_BEGIN + + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testString) + VMIME_TEST(testUpdate) + VMIME_TEST_LIST_END -namespace -{ - class md5Test : public suite + + void testString() + { + // Test suites from RFC #1321 + VASSERT_EQ("1", "d41d8cd98f00b204e9800998ecf8427e", vmime::utility::md5("").hex()); + VASSERT_EQ("2", "0cc175b9c0f1b6a831c399e269772661", vmime::utility::md5("a").hex()); + VASSERT_EQ("3", "900150983cd24fb0d6963f7d28e17f72", vmime::utility::md5("abc").hex()); + VASSERT_EQ("4", "f96b697d7cb7938d525a2f31aaf161d0", vmime::utility::md5("message digest").hex()); + VASSERT_EQ("5", "c3fcd3d76192e4007dfb496cca67e13b", vmime::utility::md5("abcdefghijklmnopqrstuvwxyz").hex()); + VASSERT_EQ("6", "d174ab98d277d9f5a5611c2c9f419d9f", vmime::utility::md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789").hex()); + VASSERT_EQ("7", "57edf4a22be3c955ac49da2e2107b67a", vmime::utility::md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890").hex()); + } + + void testUpdate() { - void testString() - { - // Test suites from RFC #1321 - assert_eq("1", "d41d8cd98f00b204e9800998ecf8427e", vmime::utility::md5("").hex()); - assert_eq("2", "0cc175b9c0f1b6a831c399e269772661", vmime::utility::md5("a").hex()); - assert_eq("3", "900150983cd24fb0d6963f7d28e17f72", vmime::utility::md5("abc").hex()); - assert_eq("4", "f96b697d7cb7938d525a2f31aaf161d0", vmime::utility::md5("message digest").hex()); - assert_eq("5", "c3fcd3d76192e4007dfb496cca67e13b", vmime::utility::md5("abcdefghijklmnopqrstuvwxyz").hex()); - assert_eq("6", "d174ab98d277d9f5a5611c2c9f419d9f", vmime::utility::md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789").hex()); - assert_eq("7", "57edf4a22be3c955ac49da2e2107b67a", vmime::utility::md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890").hex()); - } - - void testUpdate() - { - vmime::utility::md5 m1; - m1.update(""); - assert_eq("1", "d41d8cd98f00b204e9800998ecf8427e", m1.hex()); - - vmime::utility::md5 m2; - m2.update("a"); - m2.update(""); - assert_eq("2", "0cc175b9c0f1b6a831c399e269772661", m2.hex()); - - vmime::utility::md5 m3; - m3.update("ab"); - m3.update("c"); - assert_eq("3", "900150983cd24fb0d6963f7d28e17f72", m3.hex()); - - vmime::utility::md5 m4; - m4.update(""); - m4.update("message"); - m4.update(" "); - m4.update("digest"); - assert_eq("4", "f96b697d7cb7938d525a2f31aaf161d0", m4.hex()); - - vmime::utility::md5 m5; - m5.update("abcd"); - m5.update(""); - m5.update("efghijklmnop"); - m5.update("qrstuvwx"); - m5.update("yz"); - assert_eq("5", "c3fcd3d76192e4007dfb496cca67e13b", m5.hex()); - - vmime::utility::md5 m6; - m6.update("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012"); - m6.update("345"); - m6.update("6"); - m6.update("7"); - m6.update("89"); - assert_eq("6", "d174ab98d277d9f5a5611c2c9f419d9f", m6.hex()); - - vmime::utility::md5 m7; - m7.update("12345678901234567890123456789"); - m7.update("01234567890123456789012345678901"); - m7.update("234567890123456789"); - m7.update(""); - m7.update("0"); - assert_eq("7", "57edf4a22be3c955ac49da2e2107b67a", m7.hex()); - } - - public: - - md5Test() : suite("vmime::utility::md5") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); - - add("String", testcase(this, "String", &md5Test::testString)); - add("Update", testcase(this, "Update", &md5Test::testUpdate)); - - suite::main().add("vmime::utility::md5", this); - } - - }; - - md5Test* theTest = new md5Test(); -} + vmime::utility::md5 m1; + m1.update(""); + VASSERT_EQ("1", "d41d8cd98f00b204e9800998ecf8427e", m1.hex()); + + vmime::utility::md5 m2; + m2.update("a"); + m2.update(""); + VASSERT_EQ("2", "0cc175b9c0f1b6a831c399e269772661", m2.hex()); + + vmime::utility::md5 m3; + m3.update("ab"); + m3.update("c"); + VASSERT_EQ("3", "900150983cd24fb0d6963f7d28e17f72", m3.hex()); + + vmime::utility::md5 m4; + m4.update(""); + m4.update("message"); + m4.update(" "); + m4.update("digest"); + VASSERT_EQ("4", "f96b697d7cb7938d525a2f31aaf161d0", m4.hex()); + + vmime::utility::md5 m5; + m5.update("abcd"); + m5.update(""); + m5.update("efghijklmnop"); + m5.update("qrstuvwx"); + m5.update("yz"); + VASSERT_EQ("5", "c3fcd3d76192e4007dfb496cca67e13b", m5.hex()); + + vmime::utility::md5 m6; + m6.update("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012"); + m6.update("345"); + m6.update("6"); + m6.update("7"); + m6.update("89"); + VASSERT_EQ("6", "d174ab98d277d9f5a5611c2c9f419d9f", m6.hex()); + + vmime::utility::md5 m7; + m7.update("12345678901234567890123456789"); + m7.update("01234567890123456789012345678901"); + m7.update("234567890123456789"); + m7.update(""); + m7.update("0"); + VASSERT_EQ("7", "57edf4a22be3c955ac49da2e2107b67a", m7.hex()); + } + +VMIME_TEST_SUITE_END + diff --git a/tests/utility/pathTest.cpp b/tests/utility/pathTest.cpp index 7710cf13..bb9f2098 100644 --- a/tests/utility/pathTest.cpp +++ b/tests/utility/pathTest.cpp @@ -17,301 +17,287 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" +#include "tests/testUtils.hpp" -#include <iostream> -#include <ostream> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" #include "vmime/utility/path.hpp" -using namespace unitpp; +#define VMIME_TEST_SUITE pathTest +#define VMIME_TEST_SUITE_MODULE "Utility" + + +VMIME_TEST_SUITE_BEGIN + + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testConstruct1) + VMIME_TEST(testConstruct2) + VMIME_TEST(testConstruct3) + VMIME_TEST(testConstruct4) + + VMIME_TEST(testAppendComponent) + + VMIME_TEST(testOperatorDiv1) + VMIME_TEST(testOperatorDiv2) + + VMIME_TEST(testOperatorDivEqual1) + VMIME_TEST(testOperatorDivEqual2) + + VMIME_TEST(testGetParent) + + VMIME_TEST(testComparison) + + VMIME_TEST(testGetLastComponent) + + VMIME_TEST(testIsDirectParentOf) + VMIME_TEST(testIsParentOf) + + VMIME_TEST(testRenameParent) + VMIME_TEST_LIST_END + + + typedef vmime::utility::path path; + typedef vmime::utility::path::component comp; + + + void testConstruct1() + { + VASSERT_EQ("1", true, path().isEmpty()); + VASSERT_EQ("2", 0, path().getSize()); + } + + void testConstruct2() + { + path p(comp("foo")); + + VASSERT_EQ("1", false, p.isEmpty()); + VASSERT_EQ("2", 1, p.getSize()); + VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer()); + } + + void testAppendComponent() + { + path p; + + VASSERT_EQ("1", 0, p.getSize()); + + comp c("foo"); + p.appendComponent(c); -namespace -{ - class pathTest : public suite + VASSERT_EQ("2", 1, p.getSize()); + VASSERT_EQ("3", c.getBuffer(), p.getComponentAt(0).getBuffer()); + } + + void testConstruct3() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); + + path p2(p1); + + VASSERT_EQ("1", 2, p2.getSize()); + VASSERT_EQ("2", "foo", p2.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", "bar", p2.getComponentAt(1).getBuffer()); + } + + void testConstruct4() + { + // Same as path::path(const component&) + path p("foo"); + + VASSERT_EQ("1", false, p.isEmpty()); + VASSERT_EQ("2", 1, p.getSize()); + VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer()); + } + + void testOperatorDiv1() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); + + path p2; + p2.appendComponent(comp("baz")); + + path p3 = p1 / p2; + + VASSERT_EQ("1", 3, p3.getSize()); + VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer()); + VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer()); + } + + void testOperatorDiv2() { - typedef vmime::utility::path path; - typedef vmime::utility::path::component comp; + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); + + comp c("baz"); + + path p2 = p1 / c; + VASSERT_EQ("1", 3, p2.getSize()); + VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer()); + VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer()); + } - void testConstruct1() - { - assert_eq("1", true, path().isEmpty()); - assert_eq("2", 0, path().getSize()); - } - - void testConstruct2() - { - path p(comp("foo")); - - assert_eq("1", false, p.isEmpty()); - assert_eq("2", 1, p.getSize()); - assert_eq("3", "foo", p.getComponentAt(0).getBuffer()); - } + void testOperatorDivEqual1() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); + + path p2; + p2.appendComponent(comp("baz")); - void testAppendComponent() - { - path p; + path p3(p1); + p3 /= p2; - assert_eq("1", 0, p.getSize()); - - comp c("foo"); - p.appendComponent(c); - - assert_eq("2", 1, p.getSize()); - assert_eq("3", c.getBuffer(), p.getComponentAt(0).getBuffer()); - } - - void testConstruct3() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); + VASSERT_EQ("1", 3, p3.getSize()); + VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer()); + VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer()); + } - path p2(p1); + void testOperatorDivEqual2() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); - assert_eq("1", 2, p2.getSize()); - assert_eq("2", "foo", p2.getComponentAt(0).getBuffer()); - assert_eq("3", "bar", p2.getComponentAt(1).getBuffer()); - } - - void testConstruct4() - { - // Same as path::path(const component&) - path p("foo"); + comp c("baz"); - assert_eq("1", false, p.isEmpty()); - assert_eq("2", 1, p.getSize()); - assert_eq("3", "foo", p.getComponentAt(0).getBuffer()); - } + path p2(p1); + p2 /= c; - void testOperatorDiv1() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); + VASSERT_EQ("1", 3, p2.getSize()); + VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer()); + VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer()); + } - path p2; - p2.appendComponent(comp("baz")); + void testGetParent() + { + path p1; + path p1p = p1.getParent(); - path p3 = p1 / p2; + VASSERT_EQ("1", true, p1p.isEmpty()); - assert_eq("1", 3, p3.getSize()); - assert_eq("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer()); - assert_eq("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer()); - assert_eq("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer()); - } - - void testOperatorDiv2() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); - - comp c("baz"); - - path p2 = p1 / c; - - assert_eq("1", 3, p2.getSize()); - assert_eq("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer()); - assert_eq("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer()); - assert_eq("4", c.getBuffer(), p2.getComponentAt(2).getBuffer()); - } - - void testOperatorDivEqual1() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); - - path p2; - p2.appendComponent(comp("baz")); - - path p3(p1); - p3 /= p2; - - assert_eq("1", 3, p3.getSize()); - assert_eq("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer()); - assert_eq("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer()); - assert_eq("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer()); - } - - void testOperatorDivEqual2() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); - - comp c("baz"); - - path p2(p1); - p2 /= c; - - assert_eq("1", 3, p2.getSize()); - assert_eq("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer()); - assert_eq("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer()); - assert_eq("4", c.getBuffer(), p2.getComponentAt(2).getBuffer()); - } - - void testGetParent() - { - path p1; - path p1p = p1.getParent(); - - assert_eq("1", true, p1p.isEmpty()); - - path p2; - p2.appendComponent(comp("foo")); - p2.appendComponent(comp("bar")); - - path p2p = p2.getParent(); - - assert_eq("2", 1, p2p.getSize()); - assert_eq("3", p2.getComponentAt(0).getBuffer(), p2p.getComponentAt(0).getBuffer()); - } - - void testComparison() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); - - path p2; - p2.appendComponent(comp("foo")); - p2.appendComponent(comp("bar")); - - path p3; - p3.appendComponent(comp("foo")); - p3.appendComponent(comp("bar")); - p3.appendComponent(comp("baz")); - - assert_eq("1", true, p1 == p2); - assert_eq("2", false, p1 == p3); - - assert_eq("3", false, p1 != p2); - assert_eq("4", true, p1 != p3); - - assert_eq("5", true, p3.getParent() == p1); - } - - void testGetLastComponent() - { - path p1; - p1.appendComponent(comp("foo")); - p1.appendComponent(comp("bar")); - p1.appendComponent(comp("baz")); - - assert_eq("1", "baz", p1.getLastComponent().getBuffer()); - assert_eq("2", "bar", p1.getParent().getLastComponent().getBuffer()); - assert_eq("3", "foo", p1.getParent().getParent().getLastComponent().getBuffer()); - } - - void testIsDirectParentOf() - { - path p1; - p1.appendComponent(comp("foo")); - - path p2; - p2.appendComponent(comp("foo")); - p2.appendComponent(comp("bar")); - - path p3; - p3.appendComponent(comp("foo")); - p3.appendComponent(comp("bar")); - p3.appendComponent(comp("baz")); - - assert_eq("1", true, p1.isDirectParentOf(p2)); - assert_eq("2", true, p2.isDirectParentOf(p3)); - assert_eq("3", false, p1.isDirectParentOf(p3)); - assert_eq("4", false, p2.isDirectParentOf(p1)); - } + path p2; + p2.appendComponent(comp("foo")); + p2.appendComponent(comp("bar")); - void testIsParentOf() - { - path p1; - p1.appendComponent(comp("foo")); - - path p2; - p2.appendComponent(comp("foo")); - p2.appendComponent(comp("bar")); + path p2p = p2.getParent(); - path p3; - p3.appendComponent(comp("foo")); - p3.appendComponent(comp("bar")); - p3.appendComponent(comp("baz")); + VASSERT_EQ("2", 1, p2p.getSize()); + VASSERT_EQ("3", p2.getComponentAt(0).getBuffer(), p2p.getComponentAt(0).getBuffer()); + } - assert_eq("1", true, p1.isParentOf(p2)); - assert_eq("2", true, p2.isParentOf(p3)); - assert_eq("3", true, p1.isParentOf(p3)); - assert_eq("4", false, p2.isParentOf(p1)); - } + void testComparison() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); - void testRenameParent() - { - path p1; - p1.appendComponent(comp("a")); - p1.appendComponent(comp("b")); - p1.appendComponent(comp("c")); - p1.appendComponent(comp("d")); + path p2; + p2.appendComponent(comp("foo")); + p2.appendComponent(comp("bar")); - path p2; - p2.appendComponent(comp("a")); - p2.appendComponent(comp("b")); + path p3; + p3.appendComponent(comp("foo")); + p3.appendComponent(comp("bar")); + p3.appendComponent(comp("baz")); - path p3; - p3.appendComponent(comp("x")); - p3.appendComponent(comp("y")); - p3.appendComponent(comp("z")); + VASSERT_EQ("1", true, p1 == p2); + VASSERT_EQ("2", false, p1 == p3); - path p(p1); - p.renameParent(p2, p3); + VASSERT_EQ("3", false, p1 != p2); + VASSERT_EQ("4", true, p1 != p3); - assert_eq("1", 5, p.getSize()); - assert_eq("2", "x", p.getComponentAt(0).getBuffer()); - assert_eq("3", "y", p.getComponentAt(1).getBuffer()); - assert_eq("4", "z", p.getComponentAt(2).getBuffer()); - assert_eq("5", "c", p.getComponentAt(3).getBuffer()); - assert_eq("6", "d", p.getComponentAt(4).getBuffer()); - } + VASSERT_EQ("5", true, p3.getParent() == p1); + } - public: + void testGetLastComponent() + { + path p1; + p1.appendComponent(comp("foo")); + p1.appendComponent(comp("bar")); + p1.appendComponent(comp("baz")); - pathTest() : suite("vmime::utility::path") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); - - add("Construct1", testcase(this, "Construct1", &pathTest::testConstruct1)); - add("Construct2", testcase(this, "Construct2", &pathTest::testConstruct2)); - add("Construct3", testcase(this, "Construct3", &pathTest::testConstruct3)); - add("Construct4", testcase(this, "Construct4", &pathTest::testConstruct4)); + VASSERT_EQ("1", "baz", p1.getLastComponent().getBuffer()); + VASSERT_EQ("2", "bar", p1.getParent().getLastComponent().getBuffer()); + VASSERT_EQ("3", "foo", p1.getParent().getParent().getLastComponent().getBuffer()); + } - add("AppendComponent", testcase(this, "AppendComponent", &pathTest::testAppendComponent)); + void testIsDirectParentOf() + { + path p1; + p1.appendComponent(comp("foo")); - add("OperatorDiv1", testcase(this, "OperatorDiv1", &pathTest::testOperatorDiv1)); - add("OperatorDiv2", testcase(this, "OperatorDiv2", &pathTest::testOperatorDiv2)); + path p2; + p2.appendComponent(comp("foo")); + p2.appendComponent(comp("bar")); - add("OperatorDivEqual1", testcase(this, "OperatorDivEqual1", &pathTest::testOperatorDivEqual1)); - add("OperatorDivEqual2", testcase(this, "OperatorDivEqual2", &pathTest::testOperatorDivEqual2)); + path p3; + p3.appendComponent(comp("foo")); + p3.appendComponent(comp("bar")); + p3.appendComponent(comp("baz")); - add("GetParent", testcase(this, "GetParent", &pathTest::testGetParent)); - - add("Comparison", testcase(this, "Comparison", &pathTest::testComparison)); + VASSERT_EQ("1", true, p1.isDirectParentOf(p2)); + VASSERT_EQ("2", true, p2.isDirectParentOf(p3)); + VASSERT_EQ("3", false, p1.isDirectParentOf(p3)); + VASSERT_EQ("4", false, p2.isDirectParentOf(p1)); + } - add("GetLastComponent", testcase(this, "GetLastComponent", &pathTest::testGetLastComponent)); + void testIsParentOf() + { + path p1; + p1.appendComponent(comp("foo")); - add("IsDirectParentOf", testcase(this, "IsDirectParentOf", &pathTest::testIsDirectParentOf)); - add("IsParentOf", testcase(this, "IsParentOf", &pathTest::testIsParentOf)); + path p2; + p2.appendComponent(comp("foo")); + p2.appendComponent(comp("bar")); - add("RenameParent", testcase(this, "RenameParent", &pathTest::testRenameParent)); + path p3; + p3.appendComponent(comp("foo")); + p3.appendComponent(comp("bar")); + p3.appendComponent(comp("baz")); - suite::main().add("vmime::utility::path", this); - } + VASSERT_EQ("1", true, p1.isParentOf(p2)); + VASSERT_EQ("2", true, p2.isParentOf(p3)); + VASSERT_EQ("3", true, p1.isParentOf(p3)); + VASSERT_EQ("4", false, p2.isParentOf(p1)); + } - }; + void testRenameParent() + { + path p1; + p1.appendComponent(comp("a")); + p1.appendComponent(comp("b")); + p1.appendComponent(comp("c")); + p1.appendComponent(comp("d")); + + path p2; + p2.appendComponent(comp("a")); + p2.appendComponent(comp("b")); + + path p3; + p3.appendComponent(comp("x")); + p3.appendComponent(comp("y")); + p3.appendComponent(comp("z")); + + path p(p1); + p.renameParent(p2, p3); + + VASSERT_EQ("1", 5, p.getSize()); + VASSERT_EQ("2", "x", p.getComponentAt(0).getBuffer()); + VASSERT_EQ("3", "y", p.getComponentAt(1).getBuffer()); + VASSERT_EQ("4", "z", p.getComponentAt(2).getBuffer()); + VASSERT_EQ("5", "c", p.getComponentAt(3).getBuffer()); + VASSERT_EQ("6", "d", p.getComponentAt(4).getBuffer()); + } + +VMIME_TEST_SUITE_END - pathTest* theTest = new pathTest(); -} diff --git a/tests/utility/smartPtrTest.cpp b/tests/utility/smartPtrTest.cpp index 9a7eb539..35824f42 100644 --- a/tests/utility/smartPtrTest.cpp +++ b/tests/utility/smartPtrTest.cpp @@ -17,242 +17,225 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" - -#include <iostream> -#include <ostream> -#include <vector> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" +#include "tests/testUtils.hpp" #include "vmime/utility/smartPtr.hpp" -using namespace unitpp; +#define VMIME_TEST_SUITE smartPtrTest +#define VMIME_TEST_SUITE_MODULE "Utility" -namespace -{ - class smartPtrTest : public suite - { - struct A : public vmime::object - { - const int strongCount() const { return getStrongRefCount(); } - const int weakCount() const { return getWeakRefCount(); } - }; - struct B : public virtual A { }; - struct C : public virtual A { }; - struct D : public B, public C { }; +VMIME_TEST_SUITE_BEGIN - class R : public A - { - public: + 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 - R(bool* aliveFlag) : m_aliveFlag(aliveFlag) { *m_aliveFlag = true; } - ~R() { *m_aliveFlag = false; } - private: - - bool* m_aliveFlag; - }; + struct A : public vmime::object + { + const int strongCount() const { return getStrongRefCount(); } + const int weakCount() const { return getWeakRefCount(); } + }; + struct B : public virtual A { }; + struct C : public virtual A { }; + struct D : public B, public C { }; - void testNull() - { - vmime::ref <A> r1; - - assert_true("1", r1 == NULL); - assert_true("2", r1 == 0); - assert_true("3", NULL == r1); - assert_true("4", 0 == r1); - assert_true("5", !r1); - assert_true("6", r1 == vmime::null); - assert_true("7", vmime::null == r1); - assert_eq("8", static_cast <A*>(0), r1.get()); - } + class R : public A + { + public: - void testRefCounting() - { - bool o1_alive; - vmime::ref <R> r1 = vmime::create <R>(&o1_alive); + R(bool* aliveFlag) : m_aliveFlag(aliveFlag) { *m_aliveFlag = true; } + ~R() { *m_aliveFlag = false; } - assert_true("1", r1.get() != 0); - assert_true("2", o1_alive); - assert_eq("3", 1, r1->strongCount()); - assert_eq("4", 0, r1->weakCount()); + private: - vmime::ref <R> r2 = r1; + bool* m_aliveFlag; + }; - assert_true("5", o1_alive); - assert_eq("6", 2, r1->strongCount()); - assert_eq("7", 0, r1->weakCount()); - bool o2_alive; - vmime::ref <R> r3 = vmime::create <R>(&o2_alive); + 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); - r2 = r3; + VASSERT("1", r1.get() != 0); + VASSERT("2", o1_alive); + VASSERT_EQ("3", 1, r1->strongCount()); + VASSERT_EQ("4", 0, r1->weakCount()); - assert_true("8", o1_alive); - assert_true("9", o2_alive); - assert_eq("10", 1, r1->strongCount()); - assert_eq("11", 2, r2->strongCount()); - assert_eq("12", 2, r3->strongCount()); + vmime::ref <R> r2 = r1; - { - vmime::ref <R> r4; + VASSERT("5", o1_alive); + VASSERT_EQ("6", 2, r1->strongCount()); + VASSERT_EQ("7", 0, r1->weakCount()); - r4 = r1; + bool o2_alive; + vmime::ref <R> r3 = vmime::create <R>(&o2_alive); - assert_true("13", o1_alive); - assert_true("14", o2_alive); - assert_eq("15", 2, r4->strongCount()); - assert_eq("16", 2, r1->strongCount()); + r2 = r3; - r1 = NULL; + 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()); - assert_true("17", o1_alive); - assert_true("18", o2_alive); - assert_eq("19", 1, r4->strongCount()); + { + vmime::ref <R> r4; - // Here, object1 will be deleted - } + r4 = r1; - assert_true("20", !o1_alive); - assert_true("21", o2_alive); + VASSERT("13", o1_alive); + VASSERT("14", o2_alive); + VASSERT_EQ("15", 2, r4->strongCount()); + VASSERT_EQ("16", 2, r1->strongCount()); - { - vmime::weak_ref <R> w1 = r3; + r1 = NULL; - assert_eq("22", 1, r3->weakCount()); - } + VASSERT("17", o1_alive); + VASSERT("18", o2_alive); + VASSERT_EQ("19", 1, r4->strongCount()); - assert_true("23", o2_alive); - assert_eq("24", 2, r3->strongCount()); - assert_eq("25", 0, r3->weakCount()); + // Here, object1 will be deleted } - void testWeakRef() - { - vmime::ref <A> r1 = vmime::create <A>(); - vmime::weak_ref <A> w1 = r1; + VASSERT("20", !o1_alive); + VASSERT("21", o2_alive); - assert_true("1", r1.get() != 0); - assert_true("2", r1.get() == w1.get()); - - { - vmime::ref <A> r2 = r1; + { + vmime::weak_ref <R> w1 = r3; - assert_true("3", r1.get() == r2.get()); - assert_true("4", r1.get() == w1.get()); - } + VASSERT_EQ("22", 1, r3->weakCount()); + } - assert_true("5", r1.get() != 0); - assert_true("6", r1.get() == w1.get()); + VASSERT("23", o2_alive); + VASSERT_EQ("24", 2, r3->strongCount()); + VASSERT_EQ("25", 0, r3->weakCount()); + } - r1 = 0; + void testWeakRef() + { + vmime::ref <A> r1 = vmime::create <A>(); + vmime::weak_ref <A> w1 = r1; - assert_true("7", w1.get() == 0); - } + VASSERT("1", r1.get() != 0); + VASSERT("2", r1.get() == w1.get()); - void testCast() { - // Explicit upcast - vmime::ref <A> r1 = vmime::create <C>(); - vmime::ref <C> r2 = r1.dynamicCast <C>(); + vmime::ref <A> r2 = r1; - assert_true("1", r2.get() == dynamic_cast <C*>(r1.get())); - assert_true("2", 0 == r1.dynamicCast <B>().get()); - - // Implicit downcast - vmime::ref <D> r3 = vmime::create <D>(); - vmime::ref <A> r4 = r3; - - assert_true("3", r4.get() == dynamic_cast <A*>(r3.get())); + VASSERT("3", r1.get() == r2.get()); + VASSERT("4", r1.get() == w1.get()); } - void testContainer() - { - bool o1_alive; - vmime::ref <R> r1 = vmime::create <R>(&o1_alive); + VASSERT("5", r1.get() != 0); + VASSERT("6", r1.get() == w1.get()); - bool o2_alive; - vmime::ref <R> r2 = vmime::create <R>(&o2_alive); + r1 = 0; - std::vector <vmime::ref <R> > v1; - v1.push_back(r1); - v1.push_back(r2); + VASSERT("7", w1.get() == 0); + } - assert_true("1", o1_alive); - assert_eq("2", 2, r1->strongCount()); - assert_true("3", o2_alive); - assert_eq("4", 2, r2->strongCount()); + void testCast() + { + // Explicit upcast + vmime::ref <A> r1 = vmime::create <C>(); + vmime::ref <C> r2 = r1.dynamicCast <C>(); - { - std::vector <vmime::ref <R> > v2 = v1; + VASSERT("1", r2.get() == dynamic_cast <C*>(r1.get())); + VASSERT("2", 0 == r1.dynamicCast <B>().get()); - assert_true("5", o1_alive); - assert_eq("6", 3, r1->strongCount()); - assert_true("7", o2_alive); - assert_eq("8", 3, r2->strongCount()); + // Implicit downcast + vmime::ref <D> r3 = vmime::create <D>(); + vmime::ref <A> r4 = r3; - v2[1] = NULL; + VASSERT("3", r4.get() == dynamic_cast <A*>(r3.get())); + } - assert_true("9", o1_alive); - assert_eq("10", 3, r1->strongCount()); - assert_true("11", o2_alive); - assert_eq("12", 2, r2->strongCount()); - } + void testContainer() + { + bool o1_alive; + vmime::ref <R> r1 = vmime::create <R>(&o1_alive); - assert_true("13", o1_alive); - assert_eq("14", 2, r1->strongCount()); - assert_true("15", o2_alive); - assert_eq("16", 2, r2->strongCount()); - } + bool o2_alive; + vmime::ref <R> r2 = vmime::create <R>(&o2_alive); - 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; - - assert_true("1", r1 != r2); - assert_true("2", r1.get() == r1); - assert_true("3", r1 == r1.get()); - assert_true("4", r2 != r1.get()); - assert_true("5", r1.get() != r2); - assert_true("6", r1 == r4); - assert_true("7", r1.get() == r4); - - std::vector <vmime::ref <A> > v; - v.push_back(r1); - v.push_back(r2); - - assert_true("8", std::find(v.begin(), v.end(), r1) == v.begin()); - assert_true("9", std::find(v.begin(), v.end(), r2) == v.begin() + 1); - assert_true("10", std::find(v.begin(), v.end(), r3) == v.end()); - } + std::vector <vmime::ref <R> > v1; + v1.push_back(r1); + v1.push_back(r2); - public: + VASSERT("1", o1_alive); + VASSERT_EQ("2", 2, r1->strongCount()); + VASSERT("3", o2_alive); + VASSERT_EQ("4", 2, r2->strongCount()); - smartPtrTest() : suite("vmime::utility::url") { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); + 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()); - add("Null", testcase(this, "TestNull", &smartPtrTest::testNull)); - add("RefCounting", testcase(this, "TestRefCounting", &smartPtrTest::testRefCounting)); - add("WeakRef", testcase(this, "TestWeakRef", &smartPtrTest::testWeakRef)); - add("Cast", testcase(this, "TestCast", &smartPtrTest::testCast)); - add("Container", testcase(this, "TestContainer", &smartPtrTest::testContainer)); - add("Compare", testcase(this, "TestCompare", &smartPtrTest::testCompare)); + v2[1] = NULL; - suite::main().add("vmime::utility::smartPtr", this); + 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()); + } - smartPtrTest* theTest = new smartPtrTest(); -} + 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 diff --git a/tests/utility/stringProxyTest.cpp b/tests/utility/stringProxyTest.cpp index 8c719920..b4803e82 100644 --- a/tests/utility/stringProxyTest.cpp +++ b/tests/utility/stringProxyTest.cpp @@ -17,189 +17,174 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" +#include "tests/testUtils.hpp" -#include <iostream> -#include <ostream> -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" +#define VMIME_TEST_SUITE stringProxyTest +#define VMIME_TEST_SUITE_MODULE "Utility" -using namespace unitpp; +VMIME_TEST_SUITE_BEGIN -namespace -{ - class stringProxyTest : public suite - { - void testConstruct() - { - vmime::utility::stringProxy s; - - assert_eq("1", static_cast <vmime::utility::stringProxy::size_type>(0), s.length()); - assert_eq("2", static_cast <vmime::utility::stringProxy::size_type>(0), s.start()); - assert_eq("3", static_cast <vmime::utility::stringProxy::size_type>(0), s.end()); - } - - void testConstruct2() - { - vmime::string str("This is a test string."); + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testConstruct) + VMIME_TEST(testConstruct2) - vmime::utility::stringProxy s1(str); + VMIME_TEST(testDetach) - assert_eq("1", str.length(), s1.length()); - assert_eq("2", static_cast <vmime::utility::stringProxy::size_type>(0), s1.start()); - assert_eq("3", str.length(), s1.end()); + VMIME_TEST(testSet) - vmime::utility::stringProxy s2(str, 10); + VMIME_TEST(testExtract) - assert_eq("4", str.length() - 10, s2.length()); - assert_eq("5", static_cast <vmime::utility::stringProxy::size_type>(10), s2.start()); - assert_eq("6", str.length(), s2.end()); + VMIME_TEST(testOperatorLTLT1) + VMIME_TEST(testOperatorLTLT2) + VMIME_TEST_LIST_END - vmime::utility::stringProxy s3(str, 10, 14); - assert_eq("7", static_cast <vmime::utility::stringProxy::size_type>(4), s3.length()); - assert_eq("8", static_cast <vmime::utility::stringProxy::size_type>(10), s3.start()); - assert_eq("9", static_cast <vmime::utility::stringProxy::size_type>(14), s3.end()); + void testConstruct() + { + vmime::utility::stringProxy s; - assert_eq("10", 't', *s3.it_begin()); - assert_eq("11", 'e', *(s3.it_begin() + 1)); - assert_eq("12", 's', *(s3.it_begin() + 2)); - assert_eq("13", 't', *(s3.it_begin() + 3)); - } + VASSERT_EQ("1", static_cast <vmime::utility::stringProxy::size_type>(0), s.length()); + VASSERT_EQ("2", static_cast <vmime::utility::stringProxy::size_type>(0), s.start()); + VASSERT_EQ("3", static_cast <vmime::utility::stringProxy::size_type>(0), s.end()); + } - void testDetach() - { - vmime::utility::stringProxy s; - s = "foo"; + void testConstruct2() + { + vmime::string str("This is a test string."); - s.detach(); + vmime::utility::stringProxy s1(str); - assert_eq("1", static_cast <vmime::utility::stringProxy::size_type>(0), s.length()); - assert_eq("2", static_cast <vmime::utility::stringProxy::size_type>(0), s.start()); - assert_eq("3", static_cast <vmime::utility::stringProxy::size_type>(0), s.end()); - } + VASSERT_EQ("1", str.length(), s1.length()); + VASSERT_EQ("2", static_cast <vmime::utility::stringProxy::size_type>(0), s1.start()); + VASSERT_EQ("3", str.length(), s1.end()); - void testSet() - { - vmime::string str("This is a test string."); + vmime::utility::stringProxy s2(str, 10); - vmime::utility::stringProxy s1; - s1.set(str); + VASSERT_EQ("4", str.length() - 10, s2.length()); + VASSERT_EQ("5", static_cast <vmime::utility::stringProxy::size_type>(10), s2.start()); + VASSERT_EQ("6", str.length(), s2.end()); - assert_eq("1", str.length(), s1.length()); - assert_eq("2", static_cast <vmime::utility::stringProxy::size_type>(0), s1.start()); - assert_eq("3", str.length(), s1.end()); + vmime::utility::stringProxy s3(str, 10, 14); - vmime::utility::stringProxy s2; - s2.set(str, 10); + VASSERT_EQ("7", static_cast <vmime::utility::stringProxy::size_type>(4), s3.length()); + VASSERT_EQ("8", static_cast <vmime::utility::stringProxy::size_type>(10), s3.start()); + VASSERT_EQ("9", static_cast <vmime::utility::stringProxy::size_type>(14), s3.end()); - assert_eq("4", str.length() - 10, s2.length()); - assert_eq("5", static_cast <vmime::utility::stringProxy::size_type>(10), s2.start()); - assert_eq("6", str.length(), s2.end()); + VASSERT_EQ("10", 't', *s3.it_begin()); + VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); + VASSERT_EQ("12", 's', *(s3.it_begin() + 2)); + VASSERT_EQ("13", 't', *(s3.it_begin() + 3)); + } - vmime::utility::stringProxy s3; - s3.set(str, 10, 14); + void testDetach() + { + vmime::utility::stringProxy s; + s = "foo"; - assert_eq("7", static_cast <vmime::utility::stringProxy::size_type>(4), s3.length()); - assert_eq("8", static_cast <vmime::utility::stringProxy::size_type>(10), s3.start()); - assert_eq("9", static_cast <vmime::utility::stringProxy::size_type>(14), s3.end()); + s.detach(); - assert_eq("10", 't', *s3.it_begin()); - assert_eq("11", 'e', *(s3.it_begin() + 1)); - assert_eq("12", 's', *(s3.it_begin() + 2)); - assert_eq("13", 't', *(s3.it_begin() + 3)); - } + VASSERT_EQ("1", static_cast <vmime::utility::stringProxy::size_type>(0), s.length()); + VASSERT_EQ("2", static_cast <vmime::utility::stringProxy::size_type>(0), s.start()); + VASSERT_EQ("3", static_cast <vmime::utility::stringProxy::size_type>(0), s.end()); + } - void testExtract() - { - vmime::string str("This is a test string."); + void testSet() + { + vmime::string str("This is a test string."); - vmime::utility::stringProxy s1(str, 10, 14); + vmime::utility::stringProxy s1; + s1.set(str); - std::ostringstream oss1; - vmime::utility::outputStreamAdapter osa1(oss1); + VASSERT_EQ("1", str.length(), s1.length()); + VASSERT_EQ("2", static_cast <vmime::utility::stringProxy::size_type>(0), s1.start()); + VASSERT_EQ("3", str.length(), s1.end()); - s1.extract(osa1); + vmime::utility::stringProxy s2; + s2.set(str, 10); - assert_eq("1", "test", oss1.str()); + VASSERT_EQ("4", str.length() - 10, s2.length()); + VASSERT_EQ("5", static_cast <vmime::utility::stringProxy::size_type>(10), s2.start()); + VASSERT_EQ("6", str.length(), s2.end()); - vmime::utility::stringProxy s2(str); + vmime::utility::stringProxy s3; + s3.set(str, 10, 14); - std::ostringstream oss2; - vmime::utility::outputStreamAdapter osa2(oss2); + VASSERT_EQ("7", static_cast <vmime::utility::stringProxy::size_type>(4), s3.length()); + VASSERT_EQ("8", static_cast <vmime::utility::stringProxy::size_type>(10), s3.start()); + VASSERT_EQ("9", static_cast <vmime::utility::stringProxy::size_type>(14), s3.end()); - s2.extract(osa2); + VASSERT_EQ("10", 't', *s3.it_begin()); + VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); + VASSERT_EQ("12", 's', *(s3.it_begin() + 2)); + VASSERT_EQ("13", 't', *(s3.it_begin() + 3)); + } - assert_eq("2", str, oss2.str()); - } + void testExtract() + { + vmime::string str("This is a test string."); - void testOperatorLTLT1() - { - vmime::string str("This is a test string."); + vmime::utility::stringProxy s1(str, 10, 14); - vmime::utility::stringProxy s1(str, 10, 14); + std::ostringstream oss1; + vmime::utility::outputStreamAdapter osa1(oss1); - std::ostringstream oss1; - oss1 << s1; + s1.extract(osa1); - assert_eq("1", "test", oss1.str()); + VASSERT_EQ("1", "test", oss1.str()); - vmime::utility::stringProxy s2(str); + vmime::utility::stringProxy s2(str); - std::ostringstream oss2; - oss2 << s2; + std::ostringstream oss2; + vmime::utility::outputStreamAdapter osa2(oss2); - assert_eq("2", str, oss2.str()); - } + s2.extract(osa2); - void testOperatorLTLT2() - { - vmime::string str("This is a test string."); + VASSERT_EQ("2", str, oss2.str()); + } - vmime::utility::stringProxy s1(str, 10, 14); + void testOperatorLTLT1() + { + vmime::string str("This is a test string."); - std::ostringstream oss1; - vmime::utility::outputStreamAdapter osa1(oss1); + vmime::utility::stringProxy s1(str, 10, 14); - osa1 << s1; + std::ostringstream oss1; + oss1 << s1; - assert_eq("1", "test", oss1.str()); + VASSERT_EQ("1", "test", oss1.str()); - vmime::utility::stringProxy s2(str); + vmime::utility::stringProxy s2(str); - std::ostringstream oss2; - vmime::utility::outputStreamAdapter osa2(oss2); + std::ostringstream oss2; + oss2 << s2; - osa2 << s2; + VASSERT_EQ("2", str, oss2.str()); + } - assert_eq("2", str, oss2.str()); - } + void testOperatorLTLT2() + { + vmime::string str("This is a test string."); - public: + vmime::utility::stringProxy s1(str, 10, 14); - stringProxyTest() : suite("vmime::utility::stringProxy") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); + std::ostringstream oss1; + vmime::utility::outputStreamAdapter osa1(oss1); - add("Construct", testcase(this, "Construct", &stringProxyTest::testConstruct)); - add("Construct2", testcase(this, "Construct2", &stringProxyTest::testConstruct2)); + osa1 << s1; - add("Detach", testcase(this, "Detach", &stringProxyTest::testDetach)); + VASSERT_EQ("1", "test", oss1.str()); - add("Set", testcase(this, "Set", &stringProxyTest::testSet)); + vmime::utility::stringProxy s2(str); - add("Extract", testcase(this, "Extract", &stringProxyTest::testExtract)); + std::ostringstream oss2; + vmime::utility::outputStreamAdapter osa2(oss2); - add("Operator<<(1)", testcase(this, "Operator<<(1)", &stringProxyTest::testOperatorLTLT1)); - add("Operator<<(2)", testcase(this, "Operator<<(2)", &stringProxyTest::testOperatorLTLT2)); + osa2 << s2; - suite::main().add("vmime::utility::stringProxy", this); - } + VASSERT_EQ("2", str, oss2.str()); + } - }; +VMIME_TEST_SUITE_END - stringProxyTest* theTest = new stringProxyTest(); -} diff --git a/tests/utility/stringUtilsTest.cpp b/tests/utility/stringUtilsTest.cpp index dee01f8e..9befe134 100644 --- a/tests/utility/stringUtilsTest.cpp +++ b/tests/utility/stringUtilsTest.cpp @@ -17,117 +17,103 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" +#include "tests/testUtils.hpp" -#include <iostream> -#include <ostream> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" #include "vmime/utility/stringUtils.hpp" -using namespace unitpp; +#define VMIME_TEST_SUITE stringUtilsTest +#define VMIME_TEST_SUITE_MODULE "Utility" + + +VMIME_TEST_SUITE_BEGIN + + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testIsStringEqualNoCase1) + VMIME_TEST(testIsStringEqualNoCase2) + VMIME_TEST(testIsStringEqualNoCase3) + + VMIME_TEST(testToLower) + + VMIME_TEST(testTrim) + + VMIME_TEST(testCountASCIIChars) + VMIME_TEST_LIST_END + + + typedef vmime::utility::stringUtils stringUtils; + + + void testIsStringEqualNoCase1() + { + VASSERT_EQ("1", true, stringUtils::isStringEqualNoCase(vmime::string("foo"), "foo", 3)); + VASSERT_EQ("2", true, stringUtils::isStringEqualNoCase(vmime::string("FOo"), "foo", 3)); + + VASSERT_EQ("3", false, stringUtils::isStringEqualNoCase(vmime::string("foo"), "FOo", 3)); + VASSERT_EQ("4", false, stringUtils::isStringEqualNoCase(vmime::string("foo"), "bar", 3)); + } + + void testIsStringEqualNoCase2() + { + VASSERT_EQ("1", true, stringUtils::isStringEqualNoCase(vmime::string("foo"), vmime::string("foo"))); + VASSERT_EQ("2", true, stringUtils::isStringEqualNoCase(vmime::string("FOo"), vmime::string("foo"))); + VASSERT_EQ("3", true, stringUtils::isStringEqualNoCase(vmime::string("foO"), vmime::string("FOo"))); + } + + void testIsStringEqualNoCase3() + { + vmime::string str1("FooBar"); + + VASSERT_EQ("1", true, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "foobar", 6)); + VASSERT_EQ("2", false, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "FooBar", 6)); + VASSERT_EQ("3", true, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "fooBar", 3)); + VASSERT_EQ("4", false, stringUtils::isStringEqualNoCase(str1.begin(), str1.begin() + 3, "fooBar", 6)); + } + + void testToLower() + { + VASSERT_EQ("1", "foo", stringUtils::toLower("FOO")); + VASSERT_EQ("2", "foo", stringUtils::toLower("foO")); + VASSERT_EQ("3", "foo", stringUtils::toLower("foo")); + } -namespace -{ - class stringUtilsTest : public suite + void testTrim() { - typedef vmime::utility::stringUtils stringUtils; - - - void testIsStringEqualNoCase1() - { - assert_eq("1", true, stringUtils::isStringEqualNoCase(vmime::string("foo"), "foo", 3)); - assert_eq("2", true, stringUtils::isStringEqualNoCase(vmime::string("FOo"), "foo", 3)); - - assert_eq("3", false, stringUtils::isStringEqualNoCase(vmime::string("foo"), "FOo", 3)); - assert_eq("4", false, stringUtils::isStringEqualNoCase(vmime::string("foo"), "bar", 3)); - } - - void testIsStringEqualNoCase2() - { - assert_eq("1", true, stringUtils::isStringEqualNoCase(vmime::string("foo"), vmime::string("foo"))); - assert_eq("2", true, stringUtils::isStringEqualNoCase(vmime::string("FOo"), vmime::string("foo"))); - assert_eq("3", true, stringUtils::isStringEqualNoCase(vmime::string("foO"), vmime::string("FOo"))); - } - - void testIsStringEqualNoCase3() - { - vmime::string str1("FooBar"); - - assert_eq("1", true, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "foobar", 6)); - assert_eq("2", false, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "FooBar", 6)); - assert_eq("3", true, stringUtils::isStringEqualNoCase(str1.begin(), str1.end(), "fooBar", 3)); - assert_eq("4", false, stringUtils::isStringEqualNoCase(str1.begin(), str1.begin() + 3, "fooBar", 6)); - } - - void testToLower() - { - assert_eq("1", "foo", stringUtils::toLower("FOO")); - assert_eq("2", "foo", stringUtils::toLower("foO")); - assert_eq("3", "foo", stringUtils::toLower("foo")); - } - - void testTrim() - { - assert_eq("1", "foo", stringUtils::trim(" foo")); - assert_eq("2", "foo", stringUtils::trim("\t\tfoo")); - assert_eq("3", "foo", stringUtils::trim(" \t \tfoo")); - assert_eq("4", "foo", stringUtils::trim(" \r\n\tfoo")); - - assert_eq("5", "foo", stringUtils::trim("foo ")); - assert_eq("6", "foo", stringUtils::trim("foo\t\t")); - assert_eq("7", "foo", stringUtils::trim("foo \t \t")); - assert_eq("8", "foo", stringUtils::trim("foo \r\n\t")); - - assert_eq( "9", "foo", stringUtils::trim("foo ")); - assert_eq("10", "foo", stringUtils::trim(" foo ")); - assert_eq("11", "foo", stringUtils::trim(" foo\t\t")); - assert_eq("12", "foo", stringUtils::trim("\tfoo \r \t")); - assert_eq("13", "foo", stringUtils::trim("\r \tfoo \n\t")); - } - - void testCountASCIIChars() - { - vmime::string str1("foo"); - assert_eq("1", static_cast <vmime::string::size_type>(3), - stringUtils::countASCIIchars(str1.begin(), str1.end())); - - vmime::string str2("f=?oo"); - assert_eq("2", static_cast <vmime::string::size_type>(3 + 1), - stringUtils::countASCIIchars(str2.begin(), str2.end())); - - vmime::string str3("foo\x7f"); - assert_eq("3", static_cast <vmime::string::size_type>(4), - stringUtils::countASCIIchars(str3.begin(), str3.end())); - - vmime::string str4("foo\x80"); - assert_eq("4", static_cast <vmime::string::size_type>(3), - stringUtils::countASCIIchars(str4.begin(), str4.end())); - } - - public: - - stringUtilsTest() : suite("vmime::utility::stringUtils") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); - - add("IsStringEqualNoCase1", testcase(this, "IsStringEqualNoCase1", &stringUtilsTest::testIsStringEqualNoCase1)); - add("IsStringEqualNoCase2", testcase(this, "IsStringEqualNoCase2", &stringUtilsTest::testIsStringEqualNoCase2)); - add("IsStringEqualNoCase3", testcase(this, "IsStringEqualNoCase3", &stringUtilsTest::testIsStringEqualNoCase3)); - - add("ToLower", testcase(this, "ToLower", &stringUtilsTest::testToLower)); - - add("Trim", testcase(this, "Trim", &stringUtilsTest::testTrim)); - - add("CountASCIIChars", testcase(this, "CountASCIIChars", &stringUtilsTest::testCountASCIIChars)); - - suite::main().add("vmime::utility::stringUtils", this); - } - - }; - - stringUtilsTest* theTest = new stringUtilsTest(); -} + VASSERT_EQ("1", "foo", stringUtils::trim(" foo")); + VASSERT_EQ("2", "foo", stringUtils::trim("\t\tfoo")); + VASSERT_EQ("3", "foo", stringUtils::trim(" \t \tfoo")); + VASSERT_EQ("4", "foo", stringUtils::trim(" \r\n\tfoo")); + + VASSERT_EQ("5", "foo", stringUtils::trim("foo ")); + VASSERT_EQ("6", "foo", stringUtils::trim("foo\t\t")); + VASSERT_EQ("7", "foo", stringUtils::trim("foo \t \t")); + VASSERT_EQ("8", "foo", stringUtils::trim("foo \r\n\t")); + + VASSERT_EQ( "9", "foo", stringUtils::trim("foo ")); + VASSERT_EQ("10", "foo", stringUtils::trim(" foo ")); + VASSERT_EQ("11", "foo", stringUtils::trim(" foo\t\t")); + VASSERT_EQ("12", "foo", stringUtils::trim("\tfoo \r \t")); + VASSERT_EQ("13", "foo", stringUtils::trim("\r \tfoo \n\t")); + } + + void testCountASCIIChars() + { + vmime::string str1("foo"); + VASSERT_EQ("1", static_cast <vmime::string::size_type>(3), + stringUtils::countASCIIchars(str1.begin(), str1.end())); + + vmime::string str2("f=?oo"); + VASSERT_EQ("2", static_cast <vmime::string::size_type>(3 + 1), + stringUtils::countASCIIchars(str2.begin(), str2.end())); + + vmime::string str3("foo\x7f"); + VASSERT_EQ("3", static_cast <vmime::string::size_type>(4), + stringUtils::countASCIIchars(str3.begin(), str3.end())); + + vmime::string str4("foo\x80"); + VASSERT_EQ("4", static_cast <vmime::string::size_type>(3), + stringUtils::countASCIIchars(str4.begin(), str4.end())); + } + +VMIME_TEST_SUITE_END + diff --git a/tests/utility/urlTest.cpp b/tests/utility/urlTest.cpp index 963febda..4ed45dfb 100644 --- a/tests/utility/urlTest.cpp +++ b/tests/utility/urlTest.cpp @@ -17,238 +17,223 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "../lib/unit++/unit++.h" - -#include <iostream> -#include <ostream> - -#include "vmime/vmime.hpp" -#include "vmime/platforms/posix/posixHandler.hpp" +#include "tests/testUtils.hpp" #include "vmime/utility/url.hpp" #include "vmime/utility/urlUtils.hpp" -using namespace unitpp; +#define VMIME_TEST_SUITE urlTest +#define VMIME_TEST_SUITE_MODULE "Utility" + + +VMIME_TEST_SUITE_BEGIN -namespace -{ - class urlTest : public suite + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testParse1) + VMIME_TEST(testParse2) + VMIME_TEST(testParse3) + VMIME_TEST(testParse4) + VMIME_TEST(testGenerate) + VMIME_TEST(testUtilsEncode) + VMIME_TEST(testUtilsDecode) + VMIME_TEST_LIST_END + + + static const bool parseHelper(vmime::utility::url& u, const vmime::string& str) { - static const bool parseHelper(vmime::utility::url& u, const vmime::string& str) + try { - try - { - u = vmime::utility::url(str); - } - catch (vmime::exceptions::malformed_url) - { - return false; - } - - return true; + u = vmime::utility::url(str); } - - - void testParse1() + catch (vmime::exceptions::malformed_url) { - // Test some valid constructions - vmime::utility::url u1("", ""); - - assert_eq("1.1", true, parseHelper(u1, "protocol://user:password@host:12345/path/")); - assert_eq("1.2", "protocol", u1.getProtocol()); - assert_eq("1.3", "user", u1.getUsername()); - assert_eq("1.4", "password", u1.getPassword()); - assert_eq("1.5", "host", u1.getHost()); - assert_eq("1.6", 12345, u1.getPort()); - assert_eq("1.7", "/path/", u1.getPath()); - - vmime::utility::url u2("", ""); - - assert_eq("2.1", true, parseHelper(u2, "protocol://user@host:12345/path/")); - assert_eq("2.2", "protocol", u2.getProtocol()); - assert_eq("2.3", "user", u2.getUsername()); - assert_eq("2.4", "", u2.getPassword()); - assert_eq("2.5", "host", u2.getHost()); - assert_eq("2.6", 12345, u2.getPort()); - assert_eq("2.7", "/path/", u2.getPath()); - - vmime::utility::url u3("", ""); - - assert_eq("3.1", true, parseHelper(u3, "protocol://host:12345/path/")); - assert_eq("3.2", "protocol", u3.getProtocol()); - assert_eq("3.3", "", u3.getUsername()); - assert_eq("3.4", "", u3.getPassword()); - assert_eq("3.5", "host", u3.getHost()); - assert_eq("3.6", 12345, u3.getPort()); - assert_eq("3.7", "/path/", u3.getPath()); - - vmime::utility::url u4("", ""); - - assert_eq("4.1", true, parseHelper(u4, "protocol://host/path/")); - assert_eq("4.2", "protocol", u4.getProtocol()); - assert_eq("4.3", "", u4.getUsername()); - assert_eq("4.4", "", u4.getPassword()); - assert_eq("4.5", "host", u4.getHost()); - assert_eq("4.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); - assert_eq("4.7", "/path/", u4.getPath()); - - vmime::utility::url u5("", ""); - - assert_eq("5.1", true, parseHelper(u5, "protocol://host/")); - assert_eq("5.2", "protocol", u5.getProtocol()); - assert_eq("5.3", "", u5.getUsername()); - assert_eq("5.4", "", u5.getPassword()); - assert_eq("5.5", "host", u5.getHost()); - assert_eq("5.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); - assert_eq("5.7", "", u5.getPath()); - - vmime::utility::url u6("", ""); - - assert_eq("6.1", true, parseHelper(u4, "protocol://host/path/file")); - assert_eq("6.2", "protocol", u4.getProtocol()); - assert_eq("6.3", "", u4.getUsername()); - assert_eq("6.4", "", u4.getPassword()); - assert_eq("6.5", "host", u4.getHost()); - assert_eq("6.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); - assert_eq("6.7", "/path/file", u4.getPath()); + return false; } - void testParse2() - { - // Now, test some ill-formed URLs + return true; + } - // -- missing protocol - vmime::utility::url u1("", ""); - assert_eq("1", false, parseHelper(u1, "://host")); - // -- port can contain only digits - vmime::utility::url u2("", ""); - assert_eq("2", false, parseHelper(u2, "proto://host:abc123")); + void testParse1() + { + // Test some valid constructions + vmime::utility::url u1("", ""); + + VASSERT_EQ("1.1", true, parseHelper(u1, "protocol://user:password@host:12345/path/")); + VASSERT_EQ("1.2", "protocol", u1.getProtocol()); + VASSERT_EQ("1.3", "user", u1.getUsername()); + VASSERT_EQ("1.4", "password", u1.getPassword()); + VASSERT_EQ("1.5", "host", u1.getHost()); + VASSERT_EQ("1.6", 12345, u1.getPort()); + VASSERT_EQ("1.7", "/path/", u1.getPath()); + + vmime::utility::url u2("", ""); + + VASSERT_EQ("2.1", true, parseHelper(u2, "protocol://user@host:12345/path/")); + VASSERT_EQ("2.2", "protocol", u2.getProtocol()); + VASSERT_EQ("2.3", "user", u2.getUsername()); + VASSERT_EQ("2.4", "", u2.getPassword()); + VASSERT_EQ("2.5", "host", u2.getHost()); + VASSERT_EQ("2.6", 12345, u2.getPort()); + VASSERT_EQ("2.7", "/path/", u2.getPath()); + + vmime::utility::url u3("", ""); + + VASSERT_EQ("3.1", true, parseHelper(u3, "protocol://host:12345/path/")); + VASSERT_EQ("3.2", "protocol", u3.getProtocol()); + VASSERT_EQ("3.3", "", u3.getUsername()); + VASSERT_EQ("3.4", "", u3.getPassword()); + VASSERT_EQ("3.5", "host", u3.getHost()); + VASSERT_EQ("3.6", 12345, u3.getPort()); + VASSERT_EQ("3.7", "/path/", u3.getPath()); + + vmime::utility::url u4("", ""); + + VASSERT_EQ("4.1", true, parseHelper(u4, "protocol://host/path/")); + VASSERT_EQ("4.2", "protocol", u4.getProtocol()); + VASSERT_EQ("4.3", "", u4.getUsername()); + VASSERT_EQ("4.4", "", u4.getPassword()); + VASSERT_EQ("4.5", "host", u4.getHost()); + VASSERT_EQ("4.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); + VASSERT_EQ("4.7", "/path/", u4.getPath()); + + vmime::utility::url u5("", ""); + + VASSERT_EQ("5.1", true, parseHelper(u5, "protocol://host/")); + VASSERT_EQ("5.2", "protocol", u5.getProtocol()); + VASSERT_EQ("5.3", "", u5.getUsername()); + VASSERT_EQ("5.4", "", u5.getPassword()); + VASSERT_EQ("5.5", "host", u5.getHost()); + VASSERT_EQ("5.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); + VASSERT_EQ("5.7", "", u5.getPath()); + + vmime::utility::url u6("", ""); + + VASSERT_EQ("6.1", true, parseHelper(u4, "protocol://host/path/file")); + VASSERT_EQ("6.2", "protocol", u4.getProtocol()); + VASSERT_EQ("6.3", "", u4.getUsername()); + VASSERT_EQ("6.4", "", u4.getPassword()); + VASSERT_EQ("6.5", "host", u4.getHost()); + VASSERT_EQ("6.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort()); + VASSERT_EQ("6.7", "/path/file", u4.getPath()); + } + + void testParse2() + { + // Now, test some ill-formed URLs - // -- no host specified - vmime::utility::url u3("", ""); - assert_eq("3", false, parseHelper(u3, "proto:///path")); + // -- missing protocol + vmime::utility::url u1("", ""); + VASSERT_EQ("1", false, parseHelper(u1, "://host")); - // -- no protocol separator (://) - vmime::utility::url u4("", ""); - assert_eq("4", false, parseHelper(u4, "protohost/path")); - } + // -- port can contain only digits + vmime::utility::url u2("", ""); + VASSERT_EQ("2", false, parseHelper(u2, "proto://host:abc123")); - void testParse3() - { - // Test decoding - vmime::utility::url u1("", ""); - - assert_eq("1.1", true, parseHelper(u1, "pro%12to://user%34:pass%56word@ho%78st:12345/pa%abth/")); - assert_eq("1.2", "pro%12to", u1.getProtocol()); // protocol should not be decoded - assert_eq("1.3", "user\x34", u1.getUsername()); - assert_eq("1.4", "pass\x56word", u1.getPassword()); - assert_eq("1.5", "ho\x78st", u1.getHost()); - assert_eq("1.6", 12345, u1.getPort()); - assert_eq("1.7", "/pa\xabth/", u1.getPath()); - } + // -- no host specified + vmime::utility::url u3("", ""); + VASSERT_EQ("3", false, parseHelper(u3, "proto:///path")); - void testParse4() - { - // Test parameters - vmime::utility::url u1("", ""); + // -- no protocol separator (://) + vmime::utility::url u4("", ""); + VASSERT_EQ("4", false, parseHelper(u4, "protohost/path")); + } - assert_eq("1.1", true, parseHelper(u1, "proto://host/path?p1=v1&p2=v2")); - assert_eq("1.2", "v1", u1.getParams().getProperty <vmime::string>("p1")); - assert_eq("1.3", "v2", u1.getParams().getProperty <vmime::string>("p2")); - assert_eq("1.4", "/path", u1.getPath()); + void testParse3() + { + // Test decoding + vmime::utility::url u1("", ""); + + VASSERT_EQ("1.1", true, parseHelper(u1, "pro%12to://user%34:pass%56word@ho%78st:12345/pa%abth/")); + VASSERT_EQ("1.2", "pro%12to", u1.getProtocol()); // protocol should not be decoded + VASSERT_EQ("1.3", "user\x34", u1.getUsername()); + VASSERT_EQ("1.4", "pass\x56word", u1.getPassword()); + VASSERT_EQ("1.5", "ho\x78st", u1.getHost()); + VASSERT_EQ("1.6", 12345, u1.getPort()); + VASSERT_EQ("1.7", "/pa\xabth/", u1.getPath()); + } + + void testParse4() + { + // Test parameters + vmime::utility::url u1("", ""); - vmime::utility::url u2("", ""); + VASSERT_EQ("1.1", true, parseHelper(u1, "proto://host/path?p1=v1&p2=v2")); + VASSERT_EQ("1.2", "v1", u1.getParams().getProperty <vmime::string>("p1")); + VASSERT_EQ("1.3", "v2", u1.getParams().getProperty <vmime::string>("p2")); + VASSERT_EQ("1.4", "/path", u1.getPath()); - assert_eq("2.1", true, parseHelper(u2, "proto://host/path?p1=v1&p2")); - assert_eq("2.2", "v1", u2.getParams().getProperty <vmime::string>("p1")); - assert_eq("2.3", "p2", u2.getParams().getProperty <vmime::string>("p2")); - assert_eq("2.4", "/path", u2.getPath()); + vmime::utility::url u2("", ""); - vmime::utility::url u3("", ""); + VASSERT_EQ("2.1", true, parseHelper(u2, "proto://host/path?p1=v1&p2")); + VASSERT_EQ("2.2", "v1", u2.getParams().getProperty <vmime::string>("p1")); + VASSERT_EQ("2.3", "p2", u2.getParams().getProperty <vmime::string>("p2")); + VASSERT_EQ("2.4", "/path", u2.getPath()); - assert_eq("3.1", true, parseHelper(u3, "proto://host/?p1=v1&p2=v2")); - assert_eq("3.2", "v1", u3.getParams().getProperty <vmime::string>("p1")); - assert_eq("3.3", "v2", u3.getParams().getProperty <vmime::string>("p2")); - assert_eq("3.4", "", u3.getPath()); + vmime::utility::url u3("", ""); - vmime::utility::url u4("", ""); + VASSERT_EQ("3.1", true, parseHelper(u3, "proto://host/?p1=v1&p2=v2")); + VASSERT_EQ("3.2", "v1", u3.getParams().getProperty <vmime::string>("p1")); + VASSERT_EQ("3.3", "v2", u3.getParams().getProperty <vmime::string>("p2")); + VASSERT_EQ("3.4", "", u3.getPath()); - assert_eq("4.1", true, parseHelper(u4, "proto://host/path?p1=%3D&%3D=v2")); - assert_eq("4.2", "=", u4.getParams().getProperty <vmime::string>("p1")); - assert_eq("4.3", "v2", u4.getParams().getProperty <vmime::string>("=")); - assert_eq("4.4", "/path", u4.getPath()); - } + vmime::utility::url u4("", ""); - void testGenerate() - { - vmime::utility::url u1("proto", "host", 12345, "path", "user", "password"); - assert_eq("1", "proto://user:password@host:12345/path", - static_cast <vmime::string>(u1)); - - vmime::utility::url u2("proto", "host"); - assert_eq("2", "proto://host", static_cast <vmime::string>(u2)); - - vmime::utility::url u3("proto", "host"); - u3.getParams().setProperty("p1", "v1"); - assert_eq("3.1", "proto://host/?p1=v1", - static_cast <vmime::string>(u3)); - u3.getParams().setProperty("p2", "v2"); - assert_eq("3.2", "proto://host/?p1=v1&p2=v2", - static_cast <vmime::string>(u3)); - u3.getParams().setProperty("&", "="); - assert_eq("3.3", "proto://host/?p1=v1&p2=v2&%26=%3D", - static_cast <vmime::string>(u3)); - } + VASSERT_EQ("4.1", true, parseHelper(u4, "proto://host/path?p1=%3D&%3D=v2")); + VASSERT_EQ("4.2", "=", u4.getParams().getProperty <vmime::string>("p1")); + VASSERT_EQ("4.3", "v2", u4.getParams().getProperty <vmime::string>("=")); + VASSERT_EQ("4.4", "/path", u4.getPath()); + } - void testUtilsEncode() - { - assert_eq("1", "%01", vmime::utility::urlUtils::encode("\x01")); - assert_eq("2", "%20", vmime::utility::urlUtils::encode(" ")); - assert_eq("3", "%FF", vmime::utility::urlUtils::encode("\xff")); - assert_eq("4", "a", vmime::utility::urlUtils::encode("a")); - } + void testGenerate() + { + vmime::utility::url u1("proto", "host", 12345, "path", "user", "password"); + VASSERT_EQ("1", "proto://user:password@host:12345/path", + static_cast <vmime::string>(u1)); + + vmime::utility::url u2("proto", "host"); + VASSERT_EQ("2", "proto://host", static_cast <vmime::string>(u2)); + + vmime::utility::url u3("proto", "host"); + u3.getParams().setProperty("p1", "v1"); + VASSERT_EQ("3.1", "proto://host/?p1=v1", + static_cast <vmime::string>(u3)); + u3.getParams().setProperty("p2", "v2"); + VASSERT_EQ("3.2", "proto://host/?p1=v1&p2=v2", + static_cast <vmime::string>(u3)); + u3.getParams().setProperty("&", "="); + VASSERT_EQ("3.3", "proto://host/?p1=v1&p2=v2&%26=%3D", + static_cast <vmime::string>(u3)); + } + + void testUtilsEncode() + { + VASSERT_EQ("1", "%01", vmime::utility::urlUtils::encode("\x01")); + VASSERT_EQ("2", "%20", vmime::utility::urlUtils::encode(" ")); + VASSERT_EQ("3", "%FF", vmime::utility::urlUtils::encode("\xff")); + VASSERT_EQ("4", "a", vmime::utility::urlUtils::encode("a")); + } - void testUtilsDecode() + void testUtilsDecode() + { + for (int i = 0 ; i < 255 ; ++i) { - for (int i = 0 ; i < 255 ; ++i) - { - std::ostringstream ossTest; - ossTest << "%" << "0123456789ABCDEF"[i / 16] - << "0123456789ABCDEF"[i % 16]; - - std::ostringstream ossNum; - ossNum << i; + std::ostringstream ossTest; + ossTest << "%" << "0123456789ABCDEF"[i / 16] + << "0123456789ABCDEF"[i % 16]; - vmime::string res; - res += static_cast <unsigned char>(i); + std::ostringstream ossNum; + ossNum << i; - assert_eq(ossNum.str(), res, - vmime::utility::urlUtils::decode(ossTest.str())); - } + vmime::string res; + res += static_cast <unsigned char>(i); + VASSERT_EQ(ossNum.str(), res, + vmime::utility::urlUtils::decode(ossTest.str())); } - public: - - urlTest() : suite("vmime::utility::url") - { - // VMime initialization - vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>(); - - add("Parse1", testcase(this, "Parse1", &urlTest::testParse1)); - add("Parse2", testcase(this, "Parse2", &urlTest::testParse2)); - add("Parse3", testcase(this, "Parse3", &urlTest::testParse3)); - add("Parse4", testcase(this, "Parse4", &urlTest::testParse4)); - add("Generate", testcase(this, "Generate", &urlTest::testGenerate)); - add("UtilsEncode", testcase(this, "UtilsEncode", &urlTest::testUtilsEncode)); - add("UtilsDecode", testcase(this, "UtilsDecode", &urlTest::testUtilsDecode)); - - suite::main().add("vmime::utility::url", this); - } + } - }; +VMIME_TEST_SUITE_END - urlTest* theTest = new urlTest(); -} |