TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mimelibtests.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This file is part of the KDE project
  2. Copyright (C) 2007 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "mimelibtests.h"
  17. #include "mimelibtests.moc"
  18. #include <kdebug.h>
  19. #include <tdeunittest/runner.h>
  20. #include <tdeunittest/module.h>
  21. using namespace KUnitTest;
  22. TDEUNITTEST_MODULE( tdeunittest_mimelibmodule, "Mimelib Tests" );
  23. TDEUNITTEST_MODULE_REGISTER_TESTER( MimeLibTester );
  24. #include <mimelib/string.h>
  25. #include <mimelib/message.h>
  26. #include "util.h"
  27. #include <tqfile.h>
  28. #include <assert.h>
  29. #if 0
  30. static TQString makePrintable( const TQCString& str )
  31. {
  32. TQString a = str;
  33. a = a.replace( '\r', "\\r" );
  34. a = a.replace( '\n', "\\n" );
  35. return a;
  36. }
  37. #endif
  38. static TQString makePrintable( const DwString& str )
  39. {
  40. TQString a = KMail::Util::CString( str ); // ## we assume latin1
  41. a = a.replace( '\r', "\\r" );
  42. a = a.replace( '\n', "\\n" );
  43. return a;
  44. }
  45. TQCString MimeLibTester::readFile(const TQString& fileName)
  46. {
  47. TQFile file( fileName );
  48. // #!@#$& tdeunittest... VERIFY() does nothing in setUp. Using assert instead.
  49. bool ok = file.open( IO_ReadOnly );
  50. if ( !ok ) {
  51. kdError() << fileName << " not found!" << endl;
  52. abort();
  53. }
  54. TQByteArray data = file.readAll();
  55. assert( data.size() > 1 );
  56. TQCString result;
  57. KMail::Util::setFromByteArray( result, data );
  58. return result;
  59. }
  60. void MimeLibTester::setUp()
  61. {
  62. // This multipart-mixed mail has a part that starts without headers;
  63. // the newline after the (empty) headers must be preserved.
  64. mMultipartMixedMail = readFile( TDESRCDIR "/multipartmixed.mbox" );
  65. // This is the full signed mail which was simplified to above.
  66. // Kept around in case we want to do anything else with a signed mail later :)
  67. mSignedMail = readFile( TDESRCDIR "/signedmail.mbox" );
  68. }
  69. void MimeLibTester::tearDown()
  70. {
  71. }
  72. // Simply test creating a DwMessage and then calling AsString on it.
  73. // Then the same with Parse+Assemble
  74. bool MimeLibTester::test_dwMessage_AsString( const DwString& text )
  75. {
  76. VERIFY( text.size() > 0 );
  77. // First without Parse + Assemble
  78. {
  79. DwMessage* msg = new DwMessage( text, 0 );
  80. COMPARE( makePrintable( msg->AsString() ), makePrintable( text ) );
  81. delete msg;
  82. }
  83. // Then with Parse + Assemble
  84. {
  85. DwMessage* msg = new DwMessage( text, 0 );
  86. msg->Parse();
  87. msg->Assemble();
  88. COMPARE( makePrintable( msg->AsString() ), makePrintable( text ) );
  89. if ( msg->AsString() != text )
  90. return false;
  91. delete msg;
  92. }
  93. return true;
  94. }
  95. void MimeLibTester::test_dwMessage_AsString()
  96. {
  97. if ( !test_dwMessage_AsString( mMultipartMixedMail.data() ) )
  98. return;
  99. if ( !test_dwMessage_AsString( mSignedMail.data() ) )
  100. return;
  101. }