TDE core libraries
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.

kmimetypetest.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2005 David Faure <faure@kde.org>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License version 2 as published by the Free Software Foundation;
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public License
  14. * along with this library; see the file COPYING.LIB. If not, write to
  15. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. #include <kmimetype.h>
  19. #include <kinstance.h>
  20. #include <ktempdir.h>
  21. #include <kprotocolinfo.h>
  22. #include <tqdir.h>
  23. #include <assert.h>
  24. #include <stdlib.h>
  25. #include <unistd.h>
  26. static void checkIcon( const KURL& url, const TQString& expectedIcon )
  27. {
  28. TQString icon = KMimeType::iconForURL( url );
  29. if ( icon == expectedIcon )
  30. tqDebug( "icon for %s is %s, OK", url.prettyURL().latin1(), icon.latin1() );
  31. else {
  32. tqDebug( "ERROR: icon for %s is %s, expected %s!", url.prettyURL().latin1(), icon.latin1(), expectedIcon.latin1() );
  33. exit(1);
  34. }
  35. }
  36. static void checkExtention( const TQString& fileName, const TQString& expectedExtention ) {
  37. TQString ext;
  38. KMimeType::diagnoseFileName(fileName, ext);
  39. if ( ext == expectedExtention) {
  40. tqDebug("extension of %s is '%s: OK'", fileName.latin1(), ext.latin1());
  41. } else {
  42. tqDebug("extension of %s is '%s, expected %s!'", fileName.latin1(), ext.latin1(), expectedExtention.latin1());
  43. exit(1);
  44. }
  45. }
  46. int main( int argc, char** argv )
  47. {
  48. TDEInstance blah("kmimetypetest");
  49. // Obviously those tests will need to be fixed if we ever change the name of the icons
  50. // but at least they unit-test KMimeType::iconForURL.
  51. KURL url;
  52. // safely check a "regular" folder
  53. url.setPath( TQDir::homeDirPath() );
  54. checkIcon( url, "folder" );
  55. // safely check a non-readable folder
  56. if (0 != geteuid()) { // can't do this test if we're root
  57. KTempDir tmp( TQString::null, 0 );
  58. tmp.setAutoDelete( true );
  59. url.setPath( tmp.name() );
  60. checkIcon( url, "folder_locked" );
  61. chmod( TQFile::encodeName( tmp.name() ), 0500 ); // so we can 'rm -rf' it
  62. }
  63. // safely check the trash folder
  64. if ( KProtocolInfo::isKnownProtocol( TQString("trash") ) ) {
  65. checkIcon( "trash:/", "trashcan_full" ); // #100321
  66. checkIcon( "trash:/foo/", "folder" );
  67. }
  68. checkExtention(TQString::fromLatin1("foo.pdf"), TQString::fromLatin1("*.pdf"));
  69. checkExtention(TQString::fromLatin1("foo.ps"), TQString::fromLatin1("*.ps"));
  70. return 0;
  71. }