aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--SConstruct4
-rw-r--r--src/charset.cpp52
-rw-r--r--src/encoderB64.cpp18
-rw-r--r--src/encoderQP.cpp28
-rw-r--r--src/encoderUUE.cpp17
-rw-r--r--src/messaging/IMAPConnection.cpp2
-rw-r--r--src/messaging/IMAPUtils.cpp2
-rw-r--r--src/messaging/authHelper.cpp2
-rw-r--r--src/platforms/posix/posixSocket.cpp10
-rw-r--r--src/text.cpp9
-rw-r--r--src/utility/md5.cpp14
-rw-r--r--src/utility/stringUtils.cpp2
-rw-r--r--tests/utility/md5Test.cpp112
-rw-r--r--vmime/messaging/IMAPParser.hpp2
15 files changed, 214 insertions, 66 deletions
diff --git a/ChangeLog b/ChangeLog
index f5b80d00..61443f25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,12 @@
VERSION 0.6.2-cvs
=================
+2005-01-01 Vincent Richard <[email protected]>
+
+ * Converted all C-style casts to C++-style casts.
+
+ * Added unit test for utility::md5.
+
2004-12-31 Vincent Richard <[email protected]>
* Started version 0.6.2.
diff --git a/SConstruct b/SConstruct
index 2936d816..754ba276 100644
--- a/SConstruct
+++ b/SConstruct
@@ -305,7 +305,8 @@ libvmimetest_sources = [
[ 'tests/parser/headerTest', [ 'tests/parser/headerTest.cpp' ] ],
[ 'tests/parser/mailboxTest', [ 'tests/parser/mailboxTest.cpp' ] ],
[ 'tests/parser/mediaTypeTest', [ 'tests/parser/mediaTypeTest.cpp' ] ],
- [ 'tests/parser/textTest', [ 'tests/parser/textTest.cpp' ] ]
+ [ 'tests/parser/textTest', [ 'tests/parser/textTest.cpp' ] ],
+ [ 'tests/utility/md5Test', [ 'tests/utility/md5Test.cpp' ] ]
]
libvmime_autotools = [
@@ -505,6 +506,7 @@ env.Append(CXXFLAGS = ['-Wall'])
env.Append(CXXFLAGS = ['-ansi'])
env.Append(CXXFLAGS = ['-pedantic'])
env.Append(CXXFLAGS = ['-Wpointer-arith'])
+env.Append(CXXFLAGS = ['-Wold-style-cast'])
env.Append(TARFLAGS = ['-c'])
env.Append(TARFLAGS = ['--bzip2'])
diff --git a/src/charset.cpp b/src/charset.cpp
index 4d2e005a..f8c8c50e 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -26,17 +26,26 @@
extern "C"
{
- #include <iconv.h>
-
#ifndef VMIME_BUILDING_DOC
+ #include <iconv.h>
+
// HACK: prototypes may differ depending on the compiler and/or system (the
// second parameter may or may not be 'const'). This redeclaration is a hack
// to have a common prototype "iconv_cast".
- typedef size_t (*iconv_const_hack)(iconv_t cd, const char* * inbuf,
- size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
+ class ICONV_HACK
+ {
+ public:
+
+ ICONV_HACK(const char** ptr) : m_ptr(ptr) { }
- #define iconv_const ((iconv_const_hack) iconv)
+ operator const char**() { return m_ptr; }
+ operator char**() { return const_cast <char**>(m_ptr); }
+
+ private:
+
+ const char** m_ptr;
+ };
#endif // VMIME_BUILDING_DOC
}
@@ -80,13 +89,23 @@ void charset::generate(utility::outputStream& os, const string::size_type /* max
}
+struct X
+{
+ X(const char**);
+
+ operator const char**() { return x; }
+ operator char**() { return const_cast <char**>(x); }
+
+ const char** x;
+};
+
void charset::convert(utility::inputStream& in, utility::outputStream& out,
const charset& source, const charset& dest)
{
// Get an iconv descriptor
const iconv_t cd = iconv_open(dest.getName().c_str(), source.getName().c_str());
- if (cd != (iconv_t) -1)
+ if (cd != reinterpret_cast <iconv_t>(-1))
{
char inBuffer[5];
char outBuffer[32768];
@@ -97,14 +116,15 @@ void charset::convert(utility::inputStream& in, utility::outputStream& out,
while (true)
{
// Fullfill the buffer
- size_t inLength = (size_t) in.read(inBuffer + inPos, sizeof(inBuffer) - inPos) + inPos;
+ size_t inLength = static_cast <size_t>(in.read(inBuffer + inPos, sizeof(inBuffer) - inPos) + inPos);
size_t outLength = sizeof(outBuffer);
const char* inPtr = inBuffer;
char* outPtr = outBuffer;
// Convert input bytes
- if (iconv_const(cd, &inPtr, &inLength, &outPtr, &outLength) == (size_t) -1)
+ if (iconv(cd, ICONV_HACK(&inPtr), &inLength,
+ &outPtr, &outLength) == static_cast <size_t>(-1))
{
// Illegal input sequence or input sequence has no equivalent
// sequence in the destination charset.
@@ -118,7 +138,7 @@ void charset::convert(utility::inputStream& in, utility::outputStream& out,
out.write("?", 1);
// Skip a byte and leave unconverted bytes in the input buffer
- std::copy((char*) inPtr + 1, inBuffer + sizeof(inBuffer), inBuffer);
+ std::copy(const_cast <char*>(inPtr + 1), inBuffer + sizeof(inBuffer), inBuffer);
inPos = inLength - 1;
}
else
@@ -127,7 +147,7 @@ void charset::convert(utility::inputStream& in, utility::outputStream& out,
out.write(outBuffer, sizeof(outBuffer) - outLength);
// Leave unconverted bytes in the input buffer
- std::copy((char*) inPtr, inBuffer + sizeof(inBuffer), inBuffer);
+ std::copy(const_cast <char*>(inPtr), inBuffer + sizeof(inBuffer), inBuffer);
inPos = inLength;
prevIsInvalid = true;
@@ -166,13 +186,13 @@ void charset::iconvert(const STRINGF& in, STRINGT& out, const charset& from, con
typedef typename STRINGF::value_type ivt;
typedef typename STRINGT::value_type ovt;
- if (cd != (iconv_t) -1)
+ if (cd != reinterpret_cast <iconv_t>(-1))
{
out.clear();
char buffer[65536];
- const char* inBuffer = (const char*) in.data();
+ const char* inBuffer = static_cast <const char*>(in.data());
size_t inBytesLeft = in.length();
for ( ; inBytesLeft > 0 ; )
@@ -180,10 +200,10 @@ void charset::iconvert(const STRINGF& in, STRINGT& out, const charset& from, con
size_t outBytesLeft = sizeof(buffer);
char* outBuffer = buffer;
- if (iconv_const(cd, &inBuffer, &inBytesLeft,
- &outBuffer, &outBytesLeft) == (size_t) -1)
+ if (iconv(cd, ICONV_HACK(&inBuffer), &inBytesLeft,
+ &outBuffer, &outBytesLeft) == static_cast <size_t>(-1))
{
- out += STRINGT((ovt*) buffer, sizeof(buffer) - outBytesLeft);
+ out += STRINGT(static_cast <ovt*>(buffer), sizeof(buffer) - outBytesLeft);
// Ignore this "blocking" character and continue
out += '?';
@@ -192,7 +212,7 @@ void charset::iconvert(const STRINGF& in, STRINGT& out, const charset& from, con
}
else
{
- out += STRINGT((ovt*) buffer, sizeof(buffer) - outBytesLeft);
+ out += STRINGT(static_cast <ovt*>(buffer), sizeof(buffer) - outBytesLeft);
}
}
diff --git a/src/encoderB64.cpp b/src/encoderB64.cpp
index 79ed4418..8c0827e0 100644
--- a/src/encoderB64.cpp
+++ b/src/encoderB64.cpp
@@ -64,6 +64,10 @@ const unsigned char encoderB64::sm_decodeMap[256] =
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 0xf0 - 0xff
};
+#ifndef VMIME_BUILDING_DOC
+ #define B64_WRITE(s, x, l) s.write(reinterpret_cast <utility::stream::value_type*>(x), l)
+#endif // VMIME_BUILDING_DOC
+
const utility::stream::size_type encoderB64::encode(utility::inputStream& in, utility::outputStream& out)
@@ -150,7 +154,7 @@ const utility::stream::size_type encoderB64::encode(utility::inputStream& in, ut
}
// Write encoded data to output stream
- out.write((char*) output, 4);
+ B64_WRITE(out, output, 4);
total += 4;
curCol += 4;
@@ -230,31 +234,31 @@ const utility::stream::size_type encoderB64::decode(utility::inputStream& in, ut
if (c1 == '=' || c2 == '=') // end
break;
- output[0] = (unsigned char)((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4));
+ output[0] = static_cast <unsigned char>((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4));
c1 = bytes[2];
if (c1 == '=') // end
{
- out.write((char*) output, 1);
+ B64_WRITE(out, output, 1);
total += 1;
break;
}
- output[1] = (unsigned char)(((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2));
+ output[1] = static_cast <unsigned char>(((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2));
c2 = bytes[3];
if (c2 == '=') // end
{
- out.write((char*) output, 2);
+ B64_WRITE(out, output, 2);
total += 2;
break;
}
- output[2] = (unsigned char)(((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]);
+ output[2] = static_cast <unsigned char>(((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]);
- out.write((char*) output, 3);
+ B64_WRITE(out, output, 3);
total += 3;
}
diff --git a/src/encoderQP.cpp b/src/encoderQP.cpp
index 6ae9de64..0e26cc06 100644
--- a/src/encoderQP.cpp
+++ b/src/encoderQP.cpp
@@ -80,6 +80,8 @@ const unsigned char encoderQP::sm_hexDecodeTable[256] =
outBufferPos += 3; \
curCol += 3;
+#define QP_WRITE(s, x, l) s.write(reinterpret_cast <utility::stream::value_type*>(x), l)
+
#endif // VMIME_BUILDING_DOC
@@ -88,13 +90,13 @@ const utility::stream::size_type encoderQP::encode(utility::inputStream& in, uti
in.reset(); // may not work...
const string::size_type propMaxLineLength =
- getProperties().getProperty <string::size_type>("maxlinelength", (string::size_type) -1);
+ getProperties().getProperty <string::size_type>("maxlinelength", static_cast <string::size_type>(-1));
const bool rfc2047 = getProperties().getProperty <bool>("rfc2047", false);
const bool text = getProperties().getProperty <bool>("text", false); // binary mode by default
- const bool cutLines = (propMaxLineLength != (string::size_type) -1);
- const string::size_type maxLineLength = std::min(propMaxLineLength, (string::size_type) 74);
+ const bool cutLines = (propMaxLineLength != static_cast <string::size_type>(-1));
+ const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast <string::size_type>(74));
// Process the data
char buffer[16384];
@@ -111,9 +113,9 @@ const utility::stream::size_type encoderQP::encode(utility::inputStream& in, uti
while (bufferPos < bufferLength || !in.eof())
{
// Flush current output buffer
- if (outBufferPos + 6 >= (int) sizeof(outBuffer))
+ if (outBufferPos + 6 >= static_cast <int>(sizeof(outBuffer)))
{
- out.write((char*) outBuffer, outBufferPos);
+ QP_WRITE(out, outBuffer, outBufferPos);
total += outBufferPos;
outBufferPos = 0;
@@ -131,7 +133,7 @@ const utility::stream::size_type encoderQP::encode(utility::inputStream& in, uti
}
// Get the next char and encode it
- const unsigned char c = (unsigned char) buffer[bufferPos++];
+ const unsigned char c = static_cast <unsigned char>(buffer[bufferPos++]);
switch (c)
{
@@ -270,7 +272,7 @@ const utility::stream::size_type encoderQP::encode(utility::inputStream& in, uti
// Flush remaining output buffer
if (outBufferPos != 0)
{
- out.write((char*) outBuffer, outBufferPos);
+ QP_WRITE(out, outBuffer, outBufferPos);
total += outBufferPos;
}
@@ -297,9 +299,9 @@ const utility::stream::size_type encoderQP::decode(utility::inputStream& in, uti
while (bufferPos < bufferLength || !in.eof())
{
// Flush current output buffer
- if (outBufferPos >= (int) sizeof(outBuffer))
+ if (outBufferPos >= static_cast <int>(sizeof(outBuffer)))
{
- out.write((char*) outBuffer, outBufferPos);
+ QP_WRITE(out, outBuffer, outBufferPos);
total += outBufferPos;
outBufferPos = 0;
@@ -317,7 +319,7 @@ const utility::stream::size_type encoderQP::decode(utility::inputStream& in, uti
}
// Decode the next sequence (hex-encoded byte or printable character)
- unsigned char c = (unsigned char) buffer[bufferPos++];
+ unsigned char c = static_cast <unsigned char>(buffer[bufferPos++]);
switch (c)
{
@@ -331,7 +333,7 @@ const utility::stream::size_type encoderQP::decode(utility::inputStream& in, uti
if (bufferPos < bufferLength)
{
- c = (unsigned char) buffer[bufferPos++];
+ c = static_cast <unsigned char>(buffer[bufferPos++]);
switch (c)
{
@@ -366,7 +368,7 @@ const utility::stream::size_type encoderQP::decode(utility::inputStream& in, uti
if (bufferPos < bufferLength)
{
- const unsigned char next = (unsigned char) buffer[bufferPos++];
+ const unsigned char next = static_cast <unsigned char>(buffer[bufferPos++]);
const unsigned char value =
sm_hexDecodeTable[c] * 16
@@ -415,7 +417,7 @@ const utility::stream::size_type encoderQP::decode(utility::inputStream& in, uti
// Flush remaining output buffer
if (outBufferPos != 0)
{
- out.write((char*) outBuffer, outBufferPos);
+ QP_WRITE(out, outBuffer, outBufferPos);
total += outBufferPos;
}
diff --git a/src/encoderUUE.cpp b/src/encoderUUE.cpp
index 26c0410f..3040cb9d 100644
--- a/src/encoderUUE.cpp
+++ b/src/encoderUUE.cpp
@@ -101,9 +101,9 @@ const utility::stream::size_type encoderUUE::encode(utility::inputStream& in, ut
for (utility::stream::size_type i = 0 ; i < inLength ; i += 3, j += 4)
{
- const unsigned char c1 = (unsigned char) inBuffer[i];
- const unsigned char c2 = (unsigned char) inBuffer[i + 1];
- const unsigned char c3 = (unsigned char) inBuffer[i + 2];
+ const unsigned char c1 = static_cast <unsigned char>(inBuffer[i]);
+ const unsigned char c2 = static_cast <unsigned char>(inBuffer[i + 1]);
+ const unsigned char c3 = static_cast <unsigned char>(inBuffer[i + 2]);
outBuffer[j] = UUENCODE(c1 >> 2);
outBuffer[j + 1] = UUENCODE((c1 << 4) & 060 | (c2 >> 4) & 017);
@@ -149,7 +149,8 @@ const utility::stream::size_type encoderUUE::decode(utility::inputStream& in, ut
break;
const utility::stream::size_type outLength = UUDECODE(lengthChar);
- const utility::stream::size_type inLength = std::min((outLength * 4) / 3, (utility::stream::size_type) 64);
+ const utility::stream::size_type inLength =
+ std::min((outLength * 4) / 3, static_cast <utility::stream::size_type>(64));
utility::stream::value_type inPos = 0;
switch (lengthChar)
@@ -257,10 +258,10 @@ const utility::stream::size_type encoderUUE::decode(utility::inputStream& in, ut
// Decode data
for (utility::stream::size_type i = 0, j = 0 ; i < inLength ; i += 4, j += 3)
{
- const unsigned char c1 = (unsigned char) inBuffer[i];
- const unsigned char c2 = (unsigned char) inBuffer[i + 1];
- const unsigned char c3 = (unsigned char) inBuffer[i + 2];
- const unsigned char c4 = (unsigned char) inBuffer[i + 3];
+ const unsigned char c1 = static_cast <unsigned char>(inBuffer[i]);
+ const unsigned char c2 = static_cast <unsigned char>(inBuffer[i + 1]);
+ const unsigned char c3 = static_cast <unsigned char>(inBuffer[i + 2]);
+ const unsigned char c4 = static_cast <unsigned char>(inBuffer[i + 3]);
const utility::stream::size_type n =
std::min(inLength - i, static_cast <utility::stream::size_type>(3));
diff --git a/src/messaging/IMAPConnection.cpp b/src/messaging/IMAPConnection.cpp
index d6f79ed3..c2ae2418 100644
--- a/src/messaging/IMAPConnection.cpp
+++ b/src/messaging/IMAPConnection.cpp
@@ -218,7 +218,7 @@ void IMAPConnection::send(bool tag, const string& what, bool end)
{
++(*m_tag);
- oss << (string) *m_tag;
+ oss << string(*m_tag);
oss << " ";
}
diff --git a/src/messaging/IMAPUtils.cpp b/src/messaging/IMAPUtils.cpp
index ef25c103..b56b33f7 100644
--- a/src/messaging/IMAPUtils.cpp
+++ b/src/messaging/IMAPUtils.cpp
@@ -152,7 +152,7 @@ const string IMAPUtils::toModifiedUTF7
const char base64alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,=";
- const unsigned int hs = (unsigned int)(unsigned char) hierarchySeparator;
+ const unsigned int hs = static_cast <unsigned int>(static_cast <unsigned char>(hierarchySeparator));
string hsUTF7;
hsUTF7.resize(3);
diff --git a/src/messaging/authHelper.cpp b/src/messaging/authHelper.cpp
index 5ddb8111..7ce50e0a 100644
--- a/src/messaging/authHelper.cpp
+++ b/src/messaging/authHelper.cpp
@@ -46,7 +46,7 @@ void hmac_md5(const string& text, const string& key, string& hexDigest)
if (key.length() > 64)
{
utility::md5 keyMD5;
- keyMD5.update((vmime_uint8*) key.data(), key.length());
+ keyMD5.update(reinterpret_cast <const vmime_uint8*>(key.data()), key.length());
std::copy(keyMD5.hash(), keyMD5.hash() + 16, tkey);
tkeyLen = 16;
diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp
index 09c8820e..40fa71e5 100644
--- a/src/platforms/posix/posixSocket.cpp
+++ b/src/platforms/posix/posixSocket.cpp
@@ -70,12 +70,12 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons((unsigned short) port);
+ addr.sin_port = htons(static_cast <unsigned short>(port));
addr.sin_addr.s_addr = ::inet_addr(address.c_str());
- if (addr.sin_addr.s_addr == (::in_addr_t) -1)
+ if (addr.sin_addr.s_addr == static_cast <in_addr_t>(-1))
{
- ::hostent* hostInfo = (hostent*) ::gethostbyname(address.c_str());
+ ::hostent* hostInfo = ::gethostbyname(address.c_str());
if (hostInfo == NULL)
{
@@ -83,7 +83,7 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
throw vmime::exceptions::connection_error();
}
- bcopy(hostInfo->h_addr, (char*) &addr.sin_addr, hostInfo->h_length);
+ bcopy(hostInfo->h_addr, reinterpret_cast <char*>(&addr.sin_addr), hostInfo->h_length);
}
else
{
@@ -98,7 +98,7 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
throw vmime::exceptions::connection_error();
// Start connection
- if (::connect(m_desc, (sockaddr*) &addr, sizeof(addr)) == -1)
+ if (::connect(m_desc, reinterpret_cast <sockaddr*>(&addr), sizeof(addr)) == -1)
{
::close(m_desc);
m_desc = -1;
diff --git a/src/text.cpp b/src/text.cpp
index 4fb5337b..fd210bab 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -490,7 +490,7 @@ void text::encodeAndFold(utility::outputStream& os, const string::size_type maxL
const string::size_type maxLineLength3 =
(maxLineLength == lineLengthLimits::infinite)
? maxLineLength
- : std::min(maxLineLength, (const string::size_type) 76);
+ : std::min(maxLineLength, static_cast <string::size_type>(76));
// Base64 if more than 60% non-ascii, quoted-printable else (default)
const string::size_type asciiPercent = (100 * asciiCount) / buffer.length();
@@ -534,9 +534,10 @@ void text::encodeAndFold(utility::outputStream& os, const string::size_type maxL
string::const_iterator pos = buffer.begin();
string::size_type remaining = buffer.length();
- encoder* theEncoder = ((encoding == 'B')
- ? ((encoder*) new encoderB64)
- : ((encoder*) new encoderQP));
+ encoder* theEncoder;
+
+ if (encoding == 'B') theEncoder == new encoderB64;
+ else theEncoder = new encoderQP;
string qpEncodedBuffer;
diff --git a/src/utility/md5.cpp b/src/utility/md5.cpp
index 53bf17ae..5ad8e973 100644
--- a/src/utility/md5.cpp
+++ b/src/utility/md5.cpp
@@ -70,7 +70,7 @@ md5::md5(const string& in)
: m_finalized(false)
{
init();
- update((vmime_uint8*) in.c_str(), in.length());
+ update(reinterpret_cast <const vmime_uint8*>(in.c_str()), in.length());
}
@@ -102,7 +102,7 @@ static void copyUint8Array(vmime_uint8* dest, const vmime_uint8* src, unsigned l
void md5::update(const string& in)
{
- update((vmime_uint8*) in.c_str(), in.length());
+ update(reinterpret_cast <const vmime_uint8*>(in.c_str()), in.length());
}
@@ -159,8 +159,8 @@ void md5::finalize()
memset(p, 0, padding);
- ((vmime_uint32*) m_block)[14] = (m_byteCount << 3);
- ((vmime_uint32*) m_block)[15] = (m_byteCount >> 29);
+ reinterpret_cast <vmime_uint32*>(m_block)[14] = (m_byteCount << 3);
+ reinterpret_cast <vmime_uint32*>(m_block)[15] = (m_byteCount >> 29);
#if VMIME_BYTE_ORDER_BIG_ENDIAN
swapUint32Array((vmime_uint32*) m_block, (64 - 8) / 4);
@@ -208,7 +208,7 @@ void md5::transformHelper()
void md5::transform()
{
- const vmime_uint32* const in = (vmime_uint32*) m_block;
+ const vmime_uint32* const in = reinterpret_cast <vmime_uint32*>(m_block);
vmime_uint32 a = m_hash[0];
vmime_uint32 b = m_hash[1];
@@ -306,7 +306,7 @@ const string md5::hex()
static const unsigned char hex[] = "0123456789abcdef";
std::ostringstream oss;
- const vmime_uint8* const digest = (vmime_uint8*) m_hash;
+ const vmime_uint8* const digest = reinterpret_cast <vmime_uint8*>(m_hash);
for (int i = 0 ; i < 16 ; ++i)
{
@@ -323,7 +323,7 @@ const vmime_uint8* md5::hash()
if (!m_finalized)
finalize();
- return ((vmime_uint8*) m_hash);
+ return (reinterpret_cast <const vmime_uint8*>(m_hash));
}
diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp
index 59e9bffd..eeb6f5a6 100644
--- a/src/utility/stringUtils.cpp
+++ b/src/utility/stringUtils.cpp
@@ -60,7 +60,7 @@ const bool stringUtils::isStringEqualNoCase
(const string::const_iterator begin, const string::const_iterator end,
const char* s, const string::size_type n)
{
- if ((string::size_type)(end - begin) < n)
+ if (static_cast <string::size_type>(end - begin) < n)
return (false);
bool equal = true;
diff --git a/tests/utility/md5Test.cpp b/tests/utility/md5Test.cpp
new file mode 100644
index 00000000..a6acf920
--- /dev/null
+++ b/tests/utility/md5Test.cpp
@@ -0,0 +1,112 @@
+//
+// VMime library (http://vmime.sourceforge.net)
+// Copyright (C) 2002-2004 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 2 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., 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 "vmime/utility/md5.hpp"
+
+using namespace unitpp;
+
+
+namespace
+{
+ class md5Test : public suite
+ {
+ 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();
+}
diff --git a/vmime/messaging/IMAPParser.hpp b/vmime/messaging/IMAPParser.hpp
index 585f086d..9755d4d2 100644
--- a/vmime/messaging/IMAPParser.hpp
+++ b/vmime/messaging/IMAPParser.hpp
@@ -382,7 +382,7 @@ public:
}
}
- if (tagString == (string) *(parser.tag()))
+ if (tagString == string(*(parser.tag())))
{
*currentPos = pos;
}