[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/resources/mbox/libmbox
From: Bertjan Broeksema <b.broeksema () home ! nl>
Date: 2009-06-19 8:29:40
Message-ID: 1245400180.364371.11014.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 983805 by bbroeksema:
Add some tests wrt trailing blank lines.
M +10 -8 mbox.cpp
M +38 -1 tests/mboxtest.cpp
M +1 -0 tests/mboxtest.h
--- trunk/KDE/kdepim/akonadi/resources/mbox/libmbox/mbox.cpp #983804:983805
@@ -143,6 +143,8 @@
d->mAppendedEntries.append( rawEntry );
if ( rawEntry[rawEntry.size() - 1] != '\n' ) {
d->mAppendedEntries.append( "\n\n" );
+ } else {
+ d->mAppendedEntries.append( "\n" );
}
MsgInfo info;
@@ -184,13 +186,10 @@
QByteArray line;
QByteArray prevSeparator;
quint64 offs = 0; // The offset of the next message to read.
- bool previousLineIsEmpty;
while ( !d->mMboxFile.atEnd() ) {
quint64 pos = d->mMboxFile.pos();
- previousLineIsEmpty = line.isEmpty();
-
line = d->mMboxFile.readLine();
if ( regexp.indexIn(line) >= 0 || d->mMboxFile.atEnd() ) {
@@ -203,12 +202,15 @@
MsgInfo info;
info.first = offs;
- // The actual mail message size starts just before the seperator. If
- // there're two new line characters we assume that one of them was added
- // with the seperator.
- info.second = previousLineIsEmpty ? (msgSize - 2) : (msgSize - 1);
+ // There is always a blank line and a seperator line between two emails.
+ // Sometimes there are two '\n' characters added to the email (i.e. when
+ // the mail self did not end with a '\n' char) and sometimes only one to
+ // achieve this. When reading the file it is not possible to see which
+ // was the case.
if ( d->mMboxFile.atEnd() )
- info.second += 1;
+ info.second = msgSize; // We use readLine so there's no additional '\n'
+ else
+ info.second = msgSize - 1;
// Don't add the seperator size and the newline up to the message size.
info.second -= prevSeparator.size() + 1;
--- trunk/KDE/kdepim/akonadi/resources/mbox/libmbox/tests/mboxtest.cpp #983804:983805
@@ -204,10 +204,47 @@
for ( int i = 0; i < 2; ++i ) {
QCOMPARE( infos3.at(i).first, infos2.at(i).first );
- QCOMPARE( infos3.at(i).second, infos2.at(i).second );
+
+ quint64 minSize = infos2.at(i).second;
+ quint64 maxSize = infos2.at(i).second + 1;
+ QVERIFY( infos3.at(i).second >= minSize );
+ QVERIFY( infos3.at(i).second <= maxSize );
}
}
+void MboxTest::testBlankLines()
+{
+ for ( int i = 0; i < 5; ++i ) {
+ QFile file( fileName() );
+ file.remove();
+ QVERIFY( !file.exists() );
+
+ MessagePtr mail = MessagePtr( new KMime::Message );
+ mail->setContent( KMime::CRLFtoLF( sEntry1 + QByteArray( i, '\n' ) ) );
+ mail->parse();
+
+ MBox mbox1;
+ QVERIFY( mbox1.setLockType( MBox::None ) );
+ QVERIFY( mbox1.load( fileName() ) );
+ mbox1.appendEntry( mail );
+ mbox1.appendEntry( mail );
+ mbox1.appendEntry( mail );
+ mbox1.save();
+
+ MBox mbox2;
+ QVERIFY( mbox1.setLockType( MBox::None ) );
+ QVERIFY( mbox1.load( fileName() ) );
+ QCOMPARE( mbox1.entryList().size(), 3 );
+
+ quint64 minSize = sEntry1.size() + i - 1; // Possibly on '\n' falls off.
+ quint64 maxSize = sEntry1.size() + i;
+ for ( int i = 0; i < 3; ++i ) {
+ QVERIFY( mbox1.entryList().at( i ).second >= minSize );
+ QVERIFY( mbox1.entryList().at( i ).second <= maxSize );
+ }
+ }
+}
+
void MboxTest::cleanupTestCase()
{
mTempDir->unlink();
--- trunk/KDE/kdepim/akonadi/resources/mbox/libmbox/tests/mboxtest.h #983804:983805
@@ -36,6 +36,7 @@
void testProcMailLock();
void testAppend();
void testSaveAndLoad();
+ void testBlankLines();
void cleanupTestCase();
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic