imagehandlingutilities/thumbnailmanager/thumbnailmanagerqt/tsrc/test_qtnmwrapper.cpp
changeset 17 ffa62e555b02
parent 15 7197e789b953
child 22 a67f74060682
equal deleted inserted replaced
15:7197e789b953 17:ffa62e555b02
    37 public slots:
    37 public slots:
    38     void thumbnailReady( QPixmap , void * , int , int );
    38     void thumbnailReady( QPixmap , void * , int , int );
    39 
    39 
    40     void thumbnailReady_p( QPixmap , void * , int , int );
    40     void thumbnailReady_p( QPixmap , void * , int , int );
    41 
    41 
       
    42     void thumbnailReadyPixmap( QPixmap , void * , int , int );
       
    43 
       
    44     void thumbnailReadyImage( QImage , void * , int , int );
       
    45 
    42 private slots:
    46 private slots:
    43     void initTestCase();
    47     void init();
    44     void cleanupTestCase();
    48     void cleanup();
    45     
    49 
       
    50     void testThumbnailReadyError();
       
    51     void testThumbnailReadyValid();
       
    52     
       
    53     void testThumbnailReadyImage();
       
    54     void testThumbnailReadyPixmap();
       
    55     void testThumbnailReadyImageAndPixmap();
       
    56 
    46     void createAndDestroy();
    57     void createAndDestroy();
    47     void qualityPreference();
    58     void qualityPreference();
    48     void thumbnailSize();
    59     void thumbnailSize();
    49     void thumbnailMode();
    60     void thumbnailMode();
    50     
    61     
    54     void cancelRequest();
    65     void cancelRequest();
    55     void changePriority();
    66     void changePriority();
    56     void deleteThumbnailsByName();
    67     void deleteThumbnailsByName();
    57     void deleteThumbnailsById();
    68     void deleteThumbnailsById();
    58 
    69 
    59     void testThumbnailReadyError();
    70     void testPriorities_data();
    60     void testThumbnailReadyValid();
    71     void testPriorities();
       
    72 
    61 
    73 
    62 public:
    74 public:
    63     ThumbnailManager* wrapper;
    75     ThumbnailManager *wrapper;
       
    76     ThumbnailManagerPrivate *wrapper_p;
       
    77     
    64     QPixmap* ipixmap;
    78     QPixmap* ipixmap;
    65     
    79     
    66     int aid; 
    80     int aid; 
    67     int aerrorCode;
    81     int aerrorCode;
    68     bool pixmapNull;
    82     bool pixmapNull;
       
    83     
       
    84     //pixmap
       
    85     int pixmapId;
       
    86     int pixmapErr;
       
    87     void *pixmapDataPtr;
       
    88     
       
    89     //image
       
    90     int imageId;
       
    91     int imageErr;
       
    92     void *imageDataPtr;
    69     
    93     
    70 };
    94 };
    71 
    95 
    72 enum testDataType{
    96 enum testDataType{
    73     AllNull,
    97     AllNull,
    75 };
    99 };
    76 
   100 
    77 class TestThumbnailData : public MThumbnailData
   101 class TestThumbnailData : public MThumbnailData
    78 {
   102 {
    79 public:
   103 public:
    80     TestThumbnailData( testDataType type) : bitmap(0), clientData(0)
   104     static const int BITMAP_WIDTH = 26;
       
   105     static const int BITMAP_HEIGHT = 15;
       
   106     
       
   107 public:
       
   108     TestThumbnailData( testDataType type, void* clientData_ = 0) : bitmap(0), clientData(clientData_)
    81     {
   109     {
    82         switch( type ){
   110         switch( type ){
    83         case AllNull:
   111         case AllNull:
    84         break;
   112         break;
    85 
   113 
    86         case BitmapValid:
   114         case BitmapValid:
    87             bitmap = new CFbsBitmap();
   115             bitmap = new CFbsBitmap();
    88             QVERIFY( !bitmap->Create(TSize(26,15),EColor64K) );
   116             QVERIFY( !bitmap->Create(TSize(BITMAP_WIDTH, BITMAP_HEIGHT),EColor64K) );
    89             QVERIFY( !bitmap->Load( _L("c:\\tnmwrapper_tsrc.mbm") ) );
   117             QVERIFY( !bitmap->Load( _L("c:\\tnmwrapper_tsrc.mbm") ) );
    90         break;
   118         break;
    91         };
   119         };
    92     
   120     
    93     };
   121     };
    94 
   122 
    95     ~TestThumbnailData() { 
   123     ~TestThumbnailData() { 
    96         if( bitmap )
   124         if( bitmap ) {
    97             delete bitmap; 
   125             delete bitmap;
    98         if( clientData )
   126         }
    99             delete clientData; 
       
   100     };
   127     };
   101     
   128     
   102     CFbsBitmap* Bitmap() {return bitmap;};
   129     CFbsBitmap* Bitmap() {return bitmap;};
   103 
   130 
   104     CFbsBitmap* DetachBitmap() {return bitmap;};
   131     CFbsBitmap* DetachBitmap() {return bitmap;};
   109     CFbsBitmap* bitmap;
   136     CFbsBitmap* bitmap;
   110     TAny* clientData;
   137     TAny* clientData;
   111 
   138 
   112 };
   139 };
   113 
   140 
   114 
   141 // --- test initialization ---
   115 // ======== MEMBER FUNCTIONS ========
   142 
   116 void TestThumbnailManager::initTestCase()
   143 void TestThumbnailManager::init()
   117 {
   144 {
   118     wrapper = new ThumbnailManager();
   145     wrapper = new ThumbnailManager();
   119     connect( wrapper, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   146     connect( wrapper, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   120             this, SLOT( thumbnailReady( QPixmap , void* , int , int )));
   147             this, SLOT( thumbnailReady( QPixmap , void* , int , int )));
   121 }
   148     
   122     
   149     wrapper_p = new ThumbnailManagerPrivate();
   123 void TestThumbnailManager::cleanupTestCase()
   150 }
       
   151     
       
   152 void TestThumbnailManager::cleanup()
   124 {
   153 {
   125     disconnect( wrapper, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   154     disconnect( wrapper, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   126             this, SLOT( thumbnailReady( QPixmap , void* , int , int )));
   155             this, SLOT( thumbnailReady( QPixmap , void* , int , int )));
   127     delete wrapper;
   156     delete wrapper;
   128     wrapper = NULL;
   157     wrapper = NULL;
   129 
   158 
   130     if( ipixmap ){
   159     if( ipixmap ) {
   131         delete ipixmap;
   160         delete ipixmap;
   132         ipixmap = NULL;
   161         ipixmap = NULL;
   133         }
   162         }
   134 }
   163  
   135 
   164     delete wrapper_p;
   136 
   165 }
       
   166 
       
   167 // --- test ---
       
   168 
       
   169 /**
       
   170  * Simple create and destroy.
       
   171  */
   137 void TestThumbnailManager::createAndDestroy()
   172 void TestThumbnailManager::createAndDestroy()
   138 {
   173 {
   139     //empty
   174     //empty
   140 }
   175 }
   141 
   176 
       
   177 /**
       
   178  * Checking quality preference flag.
       
   179  */
   142 void TestThumbnailManager::qualityPreference()
   180 void TestThumbnailManager::qualityPreference()
   143 {
   181 {
   144     QVERIFY( wrapper->setQualityPreference( ThumbnailManager::OptimizeForQuality ) );
   182     QVERIFY( wrapper->setQualityPreference( ThumbnailManager::OptimizeForQuality ) );
   145     QVERIFY( wrapper->setQualityPreference( ThumbnailManager::OptimizeForPerformance ) );
   183     QVERIFY( wrapper->setQualityPreference( ThumbnailManager::OptimizeForPerformance ) );
   146     QVERIFY( wrapper->qualityPreference() == ThumbnailManager::OptimizeForPerformance );
   184     QVERIFY( wrapper->qualityPreference() == ThumbnailManager::OptimizeForPerformance );
   147 }
   185 }
   148 
   186 
       
   187 /**
       
   188  * Checking thumbnail size flag.
       
   189  */
   149 void TestThumbnailManager::thumbnailSize()
   190 void TestThumbnailManager::thumbnailSize()
   150 {
   191 {
   151     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailSmall ) );
   192     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailSmall ) );
   152     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailMedium ) );
   193     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailMedium ) );
   153     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailLarge ) );
   194     QVERIFY( wrapper->setThumbnailSize( ThumbnailManager::ThumbnailLarge ) );
   154     QVERIFY( wrapper->setThumbnailSize( QSize( 100, 100 ) ) );
   195     QVERIFY( wrapper->setThumbnailSize( QSize( 100, 100 ) ) );
   155     QVERIFY( wrapper->thumbnailSize() == QSize( 100, 100 ) );
   196     QVERIFY( wrapper->thumbnailSize() == QSize( 100, 100 ) );
   156 }
   197 }
   157 
   198 
       
   199 /**
       
   200  * Checking thumbnail mode flag.
       
   201  */
   158 void TestThumbnailManager::thumbnailMode()
   202 void TestThumbnailManager::thumbnailMode()
   159 {
   203 {
   160     QVERIFY( wrapper->setMode( ThumbnailManager::Default ) );
   204     QVERIFY( wrapper->setMode( ThumbnailManager::Default ) );
   161     QVERIFY( wrapper->setMode( ThumbnailManager::AllowAnySize ) );
   205     QVERIFY( wrapper->setMode( ThumbnailManager::AllowAnySize ) );
   162     QVERIFY( wrapper->setMode( ThumbnailManager::DoNotCreate ) );
   206     QVERIFY( wrapper->setMode( ThumbnailManager::DoNotCreate ) );
   163     
   207     
   164     QVERIFY( wrapper->setMode( ThumbnailManager::CropToAspectRatio ) );
   208     QVERIFY( wrapper->setMode( ThumbnailManager::CropToAspectRatio ) );
   165     QVERIFY( wrapper->mode() == ThumbnailManager::CropToAspectRatio );
   209     QVERIFY( wrapper->mode() == ThumbnailManager::CropToAspectRatio );
   166 }
   210 }
   167 
   211 
       
   212 /**
       
   213  * Checking thumbnail mode flag.
       
   214  */
   168 void TestThumbnailManager::getThumbnailByName()
   215 void TestThumbnailManager::getThumbnailByName()
   169 {
   216 {
   170     wrapper->setMode( ThumbnailManager::CropToAspectRatio );
   217     wrapper->setMode( ThumbnailManager::CropToAspectRatio );
   171     wrapper->setThumbnailSize( QSize( 200, 50 )); 
   218     wrapper->setThumbnailSize( QSize( 200, 50 )); 
   172     QVERIFY( wrapper->getThumbnail( "c:\\tnmwrapper_tsrc.png", NULL, -99 ) != -1 );
   219     QVERIFY( wrapper->getThumbnail( "c:\\tnmwrapper_tsrc.png", NULL, -99 ) != -1 );
   222 void TestThumbnailManager::deleteThumbnailsById()
   269 void TestThumbnailManager::deleteThumbnailsById()
   223 {
   270 {
   224     wrapper->deleteThumbnails( 2 );
   271     wrapper->deleteThumbnails( 2 );
   225 }
   272 }
   226 
   273 
   227 void TestThumbnailManager::thumbnailReady( QPixmap /*pixmap*/, void * /*clientData*/, int /*id*/, int /*errorCode*/ )
       
   228 {
       
   229     //do nothing, we dont test Thumbnail Manager's functionality, we just use it
       
   230 }
       
   231 
       
   232 void TestThumbnailManager::thumbnailReady_p( QPixmap pixmap, void * /*clientData*/, int id, int errorCode )
       
   233 {
       
   234     QVERIFY( pixmap.isNull() == pixmapNull );
       
   235     QVERIFY( errorCode == aerrorCode );
       
   236     QVERIFY( aid == id );
       
   237 }
       
   238 
       
   239 void TestThumbnailManager::testThumbnailReadyError()
   274 void TestThumbnailManager::testThumbnailReadyError()
   240 {
   275 {
   241     ThumbnailManagerPrivate* wrapper_p = new ThumbnailManagerPrivate();
   276     int a=0;
   242 
   277 
   243     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   278     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   244         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )), Qt::DirectConnection ) );
   279         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )), Qt::DirectConnection ) );
   245 
   280 
   246     //test bytearray not null and thumbnail error
   281     //test bytearray not null and thumbnail error
   250     pixmapNull = true;
   285     pixmapNull = true;
   251     wrapper_p->ThumbnailReady( aerrorCode, tdata1, aid );
   286     wrapper_p->ThumbnailReady( aerrorCode, tdata1, aid );
   252     
   287     
   253     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   288     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   254         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )));
   289         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )));
   255     delete wrapper_p;
       
   256 }
   290 }
   257 
   291 
   258 void TestThumbnailManager::testThumbnailReadyValid()
   292 void TestThumbnailManager::testThumbnailReadyValid()
   259 {
   293 {
   260     ThumbnailManagerPrivate* wrapper_p = new ThumbnailManagerPrivate();
       
   261 
       
   262     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   294     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   263         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )), Qt::DirectConnection ) );
   295         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )), Qt::DirectConnection ) );
   264 
   296 
   265     TestThumbnailData tdata3( BitmapValid );
   297     TestThumbnailData tdata3( BitmapValid );
   266     aid = 10; 
   298     aid = 10; 
   268     pixmapNull = false;
   300     pixmapNull = false;
   269     wrapper_p->ThumbnailReady( aerrorCode, tdata3, aid );
   301     wrapper_p->ThumbnailReady( aerrorCode, tdata3, aid );
   270 
   302 
   271     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   303     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
   272         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )));
   304         this, SLOT( thumbnailReady_p( QPixmap , void* , int , int )));
   273     delete wrapper_p;
   305 }
       
   306 
       
   307 void TestThumbnailManager::testThumbnailReadyImage()
       
   308 {
       
   309     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QImage , void* , int, int ) ),
       
   310         this, SLOT( thumbnailReadyImage( QImage , void* , int , int )), Qt::DirectConnection ) );
       
   311 
       
   312     pixmapId = 0;
       
   313     pixmapErr = 0;
       
   314     pixmapDataPtr = 0;
       
   315 
       
   316     imageId = 432;
       
   317     imageErr = KErrNone;
       
   318     imageDataPtr = reinterpret_cast<void*>(0x1234);
       
   319     
       
   320     TestThumbnailData td = TestThumbnailData(BitmapValid);
       
   321     td.clientData = imageDataPtr;
       
   322 
       
   323     wrapper_p->ThumbnailReady(imageErr, td, imageId);
       
   324     
       
   325     QVERIFY(td.bitmap!=0);
       
   326     QVERIFY(td.bitmap->SizeInPixels().iWidth == TestThumbnailData::BITMAP_WIDTH);
       
   327     QVERIFY(td.bitmap->SizeInPixels().iHeight == TestThumbnailData::BITMAP_HEIGHT);
       
   328 
       
   329     disconnect( wrapper_p, SIGNAL(thumbnailReady( QImage , void* , int, int ) ),
       
   330         this, SLOT( thumbnailReadyImage(QImage, void* , int , int )));
       
   331     
       
   332 }
       
   333 
       
   334 void TestThumbnailManager::testThumbnailReadyPixmap()
       
   335 {
       
   336     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
       
   337         this, SLOT( thumbnailReadyPixmap( QPixmap , void* , int , int )), Qt::DirectConnection ) );
       
   338 
       
   339     pixmapId = 432;
       
   340     pixmapErr = -7;
       
   341     pixmapDataPtr = reinterpret_cast<void*>(0x1234);
       
   342 
       
   343     imageId = 0;
       
   344     imageErr = 0;
       
   345     imageDataPtr = 0;
       
   346 
       
   347     TestThumbnailData td = TestThumbnailData(BitmapValid);
       
   348     td.clientData = pixmapDataPtr;
       
   349 
       
   350     wrapper_p->ThumbnailReady(pixmapErr, td, pixmapId);
       
   351     
       
   352     QVERIFY(td.bitmap!=0);
       
   353     QVERIFY(td.bitmap->SizeInPixels().iWidth == TestThumbnailData::BITMAP_WIDTH);
       
   354     QVERIFY(td.bitmap->SizeInPixels().iHeight == TestThumbnailData::BITMAP_HEIGHT);
       
   355 
       
   356     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
       
   357         this, SLOT( thumbnailReadyPixmap( QPixmap , void* , int , int )));
       
   358 
       
   359 }
       
   360 
       
   361 void TestThumbnailManager::testThumbnailReadyImageAndPixmap()
       
   362 {
       
   363     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
       
   364         this, SLOT( thumbnailReadyPixmap( QPixmap , void* , int , int )), Qt::DirectConnection ) );
       
   365 
       
   366     QVERIFY( connect( wrapper_p, SIGNAL(thumbnailReady( QImage , void* , int, int ) ),
       
   367         this, SLOT( thumbnailReadyImage( QImage , void* , int , int )), Qt::DirectConnection ) );
       
   368 
       
   369     pixmapId = 432;
       
   370     pixmapErr = KErrNone;
       
   371     pixmapDataPtr = reinterpret_cast<void*>(0x1234);
       
   372 
       
   373     imageId = pixmapId;
       
   374     imageErr = pixmapErr;
       
   375     imageDataPtr = pixmapDataPtr;
       
   376 
       
   377     TestThumbnailData td = TestThumbnailData(BitmapValid);
       
   378     td.clientData = pixmapDataPtr;
       
   379 
       
   380     wrapper_p->ThumbnailReady(pixmapErr, td, pixmapId);
       
   381 
       
   382     QVERIFY(td.bitmap!=0);
       
   383     QVERIFY(td.bitmap->SizeInPixels().iWidth == TestThumbnailData::BITMAP_WIDTH);
       
   384     QVERIFY(td.bitmap->SizeInPixels().iHeight == TestThumbnailData::BITMAP_HEIGHT);
       
   385 
       
   386     disconnect( wrapper_p, SIGNAL(thumbnailReady( QImage , void* , int, int ) ),
       
   387         this, SLOT( thumbnailReadyImage( QImage , void* , int , int )));
       
   388 
       
   389     disconnect( wrapper_p, SIGNAL(thumbnailReady( QPixmap , void* , int, int ) ),
       
   390         this, SLOT( thumbnailReadyPixmap( QPixmap , void* , int , int )));
       
   391     
       
   392 }
       
   393 
       
   394 void TestThumbnailManager::testPriorities_data()
       
   395 {
       
   396     // note: current bounds for priorites are [-100:20] (from: CActive::TPriority)
       
   397     
       
   398     QTest::addColumn<int>("priority");
       
   399     QTest::addColumn<int>("expectedPriority");
       
   400     QTest::newRow("priority 0") << 0 << 0;
       
   401     QTest::newRow("priority 10") << 10 << 10;
       
   402     QTest::newRow("priority 20") << 20 << 20;
       
   403     QTest::newRow("priority 100") << 100 << 20;
       
   404     QTest::newRow("priority 200") << 200 << 20;
       
   405     QTest::newRow("priority -10") << -10 << -10;
       
   406     QTest::newRow("priority -100") << -100 << -100;
       
   407     QTest::newRow("priority -200") << -200 << -100;
       
   408 }
       
   409 
       
   410 void TestThumbnailManager::testPriorities()
       
   411 {
       
   412     QFETCH(int, priority);
       
   413     QFETCH(int, expectedPriority);
       
   414     QCOMPARE(wrapper_p->convertPriority(priority), expectedPriority);
       
   415 }
       
   416  
       
   417 
       
   418 // --- private slots - callback  ---
       
   419 
       
   420 void TestThumbnailManager::thumbnailReady( QPixmap /*pixmap*/, void * /*clientData*/, int /*id*/, int /*errorCode*/ )
       
   421 {
       
   422     //do nothing, we dont test Thumbnail Manager's functionality, we just use it
       
   423 }
       
   424 
       
   425 void TestThumbnailManager::thumbnailReady_p( QPixmap pixmap, void * /*clientData*/, int id, int errorCode )
       
   426 {
       
   427     QVERIFY( pixmap.isNull() == pixmapNull );
       
   428     QVERIFY( errorCode == aerrorCode );
       
   429     QVERIFY( id == aid );
       
   430 }
       
   431 
       
   432 void TestThumbnailManager::thumbnailReadyPixmap( QPixmap pixmap, void *clientData, int id, int errorCode )
       
   433 {
       
   434     Q_UNUSED( pixmap );
       
   435     QVERIFY( errorCode == pixmapErr );
       
   436     QVERIFY( id == pixmapId );
       
   437     QVERIFY( clientData = pixmapDataPtr );
       
   438 }
       
   439 
       
   440 void TestThumbnailManager::thumbnailReadyImage( QImage image, void *clientData, int id, int errorCode )
       
   441 {
       
   442     Q_UNUSED( image );
       
   443     QVERIFY( errorCode == imageErr );
       
   444     QVERIFY( id == imageId );
       
   445     QVERIFY( clientData = imageDataPtr );
   274 }
   446 }
   275 
   447 
   276 #ifdef _LOG_TO_C_
   448 #ifdef _LOG_TO_C_
   277     int main (int argc, char* argv[]) 
   449     int main (int argc, char* argv[]) 
   278     {
   450     {