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.

kfiltertest.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2002, 2003 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 "kfilterdev.h"
  19. #include "kfilterbase.h"
  20. #include <unistd.h>
  21. #include <limits.h>
  22. #include <tqfile.h>
  23. #include <tqtextstream.h>
  24. #include <kdebug.h>
  25. #include <kinstance.h>
  26. void test_block( const TQString & fileName )
  27. {
  28. TQIODevice * dev = KFilterDev::deviceForFile( fileName );
  29. if (!dev) { kdWarning() << "dev=0" << endl; return; }
  30. if ( !dev->open( IO_ReadOnly ) ) { kdWarning() << "open failed " << endl; return; }
  31. // This is what KGzipDev::readAll could do, if TQIODevice::readAll was virtual....
  32. TQByteArray array(1024);
  33. int n;
  34. while ( ( n = dev->tqreadBlock( array.data(), array.size() ) ) )
  35. {
  36. kdDebug() << "readBlock returned " << n << endl << endl;
  37. // TQCString s(array,n+1); // Terminate with 0 before printing
  38. // printf("%s", s.data());
  39. kdDebug() << "dev.at = " << dev->at() << endl;
  40. //kdDebug() << "f.at = " << f.at() << endl;
  41. }
  42. dev->close();
  43. delete dev;
  44. }
  45. void test_block_write( const TQString & fileName )
  46. {
  47. TQIODevice * dev = KFilterDev::deviceForFile( fileName );
  48. if (!dev) { kdWarning() << "dev=0" << endl; return; }
  49. if ( !dev->open( IO_WriteOnly ) ) { kdWarning() << "open failed " << endl; return; }
  50. TQCString s("hello\n");
  51. int ret = dev->tqwriteBlock( s, s.size()-1 );
  52. kdDebug() << "writeBlock ret=" << ret << endl;
  53. //ret = dev->tqwriteBlock( s, s.size()-1 );
  54. //kdDebug() << "writeBlock ret=" << ret << endl;
  55. dev->close();
  56. delete dev;
  57. }
  58. void test_getch( const TQString & fileName )
  59. {
  60. TQIODevice * dev = KFilterDev::deviceForFile( fileName );
  61. if (!dev) { kdWarning() << "dev=0" << endl; return; }
  62. if ( !dev->open( IO_ReadOnly ) ) { kdWarning() << "open failed " << endl; return; }
  63. int ch;
  64. while ( ( ch = dev->getch() ) != -1 )
  65. printf("%c",ch);
  66. dev->close();
  67. delete dev;
  68. }
  69. void test_textstream( const TQString & fileName )
  70. {
  71. TQIODevice * dev = KFilterDev::deviceForFile( fileName );
  72. if (!dev) { kdWarning() << "dev=0" << endl; return; }
  73. if ( !dev->open( IO_ReadOnly ) ) { kdWarning() << "open failed " << endl; return; }
  74. TQTextStream ts( dev );
  75. printf("%s\n", ts.read().latin1());
  76. dev->close();
  77. delete dev;
  78. }
  79. int main()
  80. {
  81. TDEInstance instance("kfiltertest");
  82. char currentdir[PATH_MAX+1];
  83. getcwd( currentdir, PATH_MAX );
  84. TQString pathgz = TQFile::decodeName(currentdir) + "/test.gz";
  85. TQString pathbz2 = TQFile::decodeName(currentdir) + "/test.bz2";
  86. TQString pathxz = TQFile::decodeName(currentdir) + "/test.xz";
  87. kdDebug() << " -- test_block_write gzip -- " << endl;
  88. test_block_write(pathgz);
  89. kdDebug() << " -- test_block_write bzip2 -- " << endl;
  90. test_block_write(pathbz2);
  91. kdDebug() << " -- test_block_write xz -- " << endl;
  92. test_block_write(pathxz);
  93. kdDebug() << " -- test_block gzip -- " << endl;
  94. test_block(pathgz);
  95. kdDebug() << " -- test_getch gzip -- " << endl;
  96. test_getch(pathgz);
  97. kdDebug() << " -- test_textstream gzip -- " << endl;
  98. test_textstream(pathgz);
  99. kdDebug() << " -- test_block bzip2 -- " << endl;
  100. test_block(pathbz2);
  101. kdDebug() << " -- test_getch bzip2 -- " << endl;
  102. test_getch(pathbz2);
  103. kdDebug() << " -- test_textstream bzip2 -- " << endl;
  104. test_textstream(pathbz2);
  105. kdDebug() << " -- test_block xz -- " << endl;
  106. test_block(pathxz);
  107. kdDebug() << " -- test_getch xz -- " << endl;
  108. test_getch(pathxz);
  109. kdDebug() << " -- test_textstream xz -- " << endl;
  110. test_textstream(pathxz);
  111. return 0;
  112. }