⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlib_test.cpp

📁 Jabber code library, developed with c
💻 CPP
字号:
#include "../../compressionzlib.h"#include "../../compressiondatahandler.h"using namespace gloox;#ifdef _WIN32# include "../../../config.h.win"#elif defined( _WIN32_WCE )# include "../../../config.h.win"#else# include "config.h"#endif#include <stdio.h>#include <locale.h>#include <string>#ifdef HAVE_ZLIBclass ZlibTest : public CompressionDataHandler{  public:    ZlibTest() : m_zlib( this ) {}    ~ZlibTest() {}    virtual void handleCompressedData( const std::string& data );    virtual void handleDecompressedData( const std::string& data );    const std::string data() { std::string ret = m_decompressed; m_decompressed = ""; return ret; }    void compress(  const std::string& data );  private:    CompressionZlib m_zlib;    std::string m_decompressed;};void ZlibTest::compress( const std::string& data ){  m_zlib.compress( data );}void ZlibTest::handleCompressedData( const std::string& data ){  m_zlib.decompress( data );}void ZlibTest::handleDecompressedData( const std::string& data ){  m_decompressed += data;}int main( int /*argc*/, char** /*argv*/ ){  int fail = 0;  std::string name;  ZlibTest t;  // -------  name = "short test";  const std::string a( 10, 'a' );  t.compress( a );  if( t.data() != a )  {    ++fail;    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "longer test";  const std::string b( 1000, 'b' );  t.compress( b );  if( t.data() != b )  {    ++fail;    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "long test";  const std::string c( 100000, 'b' );  t.compress( c );  if( t.data() != c )  {    ++fail;    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "large test";  const std::string d( 10000000, 'b' );  t.compress( d );  if( t.data() != d )  {    ++fail;    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "concat test";  t.compress( a );  t.compress( b );  t.compress( c );  t.compress( d );  if( t.data() != a + b + c + d )  {    ++fail;    printf( "test '%s' failed\n", name.c_str() );  }  if( fail == 0 )  {    printf( "CompressionZlib: all tests passed\n" );    return 0;  }  else  {    printf( "CompressionZlib: %d test(s) failed\n", fail );    return 1;  }}#elseint main( int /*argc*/, char** /*argv*/ ){  printf( "Zlib not available. Skipped tests.\n" );}#endif // HAVE_ZLIB

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -