tests/auto/qpixmap/tst_qpixmap.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   143     void toWinHICON();
   143     void toWinHICON();
   144     void fromWinHICON_data();
   144     void fromWinHICON_data();
   145     void fromWinHICON();
   145     void fromWinHICON();
   146 #endif
   146 #endif
   147 
   147 
   148 #if defined(Q_WS_S60)
   148 #if defined(Q_OS_SYMBIAN)
   149     void fromSymbianCFbsBitmap_data();
   149     void fromSymbianCFbsBitmap_data();
   150     void fromSymbianCFbsBitmap();
   150     void fromSymbianCFbsBitmap();
       
   151     void toSymbianCFbsBitmap_data();
       
   152     void toSymbianCFbsBitmap();
   151 #endif
   153 #endif
   152 
   154 
   153     void onlyNullPixmapsOutsideGuiThread();
   155     void onlyNullPixmapsOutsideGuiThread();
   154     void refUnref();
   156     void refUnref();
   155 
   157 
   169     void fromData();
   171     void fromData();
   170     void loadFromDataNullValues();
   172     void loadFromDataNullValues();
   171 
   173 
   172     void preserveDepth();
   174     void preserveDepth();
   173     void splash_crash();
   175     void splash_crash();
       
   176 
       
   177     void loadAsBitmapOrPixmap();
   174 };
   178 };
   175 
   179 
   176 static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
   180 static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
   177 {
   181 {
   178     QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32);
   182     QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32);
  1106 #endif
  1110 #endif
  1107 }
  1111 }
  1108 
  1112 
  1109 #endif // Q_WS_WIN
  1113 #endif // Q_WS_WIN
  1110 
  1114 
  1111 #if defined(Q_WS_S60)
  1115 #if defined(Q_OS_SYMBIAN)
  1112 Q_DECLARE_METATYPE(TDisplayMode)
  1116 Q_DECLARE_METATYPE(TDisplayMode)
  1113 
  1117 
  1114 void tst_QPixmap::fromSymbianCFbsBitmap_data()
  1118 void tst_QPixmap::fromSymbianCFbsBitmap_data()
  1115 {
  1119 {
  1116     QTest::addColumn<TDisplayMode>("format");
  1120     QTest::addColumn<TDisplayMode>("format");
  1202     }
  1206     }
  1203     __UHEAP_MARKEND;
  1207     __UHEAP_MARKEND;
  1204 
  1208 
  1205     CleanupStack::PopAndDestroy(3);
  1209     CleanupStack::PopAndDestroy(3);
  1206 }
  1210 }
       
  1211 
       
  1212 void tst_QPixmap::toSymbianCFbsBitmap_data()
       
  1213 {
       
  1214     QTest::addColumn<int>("red");
       
  1215     QTest::addColumn<int>("green");
       
  1216     QTest::addColumn<int>("blue");
       
  1217 
       
  1218     QTest::newRow("red")   << 255 << 0 << 0;
       
  1219     QTest::newRow("green") << 0 << 255 << 0;
       
  1220     QTest::newRow("blue")  << 0 << 0 << 255;
       
  1221 }
       
  1222 
       
  1223 void tst_QPixmap::toSymbianCFbsBitmap()
       
  1224 {
       
  1225     QFETCH(int, red);
       
  1226     QFETCH(int, green);
       
  1227     QFETCH(int, blue);
       
  1228 
       
  1229     QPixmap pm(100, 100);
       
  1230     pm.fill(QColor(red, green, blue));
       
  1231 
       
  1232     CFbsBitmap *bitmap = pm.toSymbianCFbsBitmap();
       
  1233 
       
  1234     QVERIFY(bitmap != 0);
       
  1235 
       
  1236     // Verify size
       
  1237     QCOMPARE(100, (int) bitmap->SizeInPixels().iWidth);
       
  1238     QCOMPARE(100, (int) bitmap->SizeInPixels().iHeight);
       
  1239 
       
  1240     // Verify pixel color
       
  1241     TRgb pixel;
       
  1242     bitmap->GetPixel(pixel, TPoint(0,0));
       
  1243     QCOMPARE((int)pixel.Red(), red);
       
  1244     QCOMPARE((int)pixel.Green(), green);
       
  1245     QCOMPARE((int)pixel.Blue(), blue);
       
  1246 
       
  1247     // Clean up
       
  1248     delete bitmap;
       
  1249 }
  1207 #endif
  1250 #endif
  1208 
  1251 
  1209 void tst_QPixmap::onlyNullPixmapsOutsideGuiThread()
  1252 void tst_QPixmap::onlyNullPixmapsOutsideGuiThread()
  1210 {
  1253 {
  1211 #if !defined(Q_WS_WIN)
  1254 #if !defined(Q_WS_WIN)
  1508     painter.end();
  1551     painter.end();
  1509 
  1552 
  1510     QCOMPARE(depth, source.depth());
  1553     QCOMPARE(depth, source.depth());
  1511 }
  1554 }
  1512 
  1555 
       
  1556 void tst_QPixmap::loadAsBitmapOrPixmap()
       
  1557 {
       
  1558     QImage tmp(10, 10, QImage::Format_RGB32);
       
  1559     tmp.save("tmp.png");
       
  1560 
       
  1561     bool ok;
       
  1562 
       
  1563     // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap
       
  1564     QPixmap pixmap("tmp.png");
       
  1565     QVERIFY(!pixmap.isNull());
       
  1566     QVERIFY(pixmap.depth() > 1);
       
  1567     QVERIFY(!pixmap.isQBitmap());
       
  1568 
       
  1569     pixmap = QPixmap();
       
  1570     ok = pixmap.load("tmp.png");
       
  1571     QVERIFY(ok);
       
  1572     QVERIFY(!pixmap.isNull());
       
  1573     QVERIFY(pixmap.depth() > 1);
       
  1574     QVERIFY(!pixmap.isQBitmap());
       
  1575 
       
  1576     // The do the same check for bitmaps..
       
  1577     QBitmap bitmap("tmp.png");
       
  1578     QVERIFY(!bitmap.isNull());
       
  1579     QVERIFY(bitmap.depth() == 1);
       
  1580     QVERIFY(bitmap.isQBitmap());
       
  1581 
       
  1582     bitmap = QBitmap();
       
  1583     ok = bitmap.load("tmp.png");
       
  1584     QVERIFY(ok);
       
  1585     QVERIFY(!bitmap.isNull());
       
  1586     QVERIFY(bitmap.depth() == 1);
       
  1587     QVERIFY(bitmap.isQBitmap());
       
  1588 }
       
  1589 
       
  1590 
       
  1591 
  1513 QTEST_MAIN(tst_QPixmap)
  1592 QTEST_MAIN(tst_QPixmap)
  1514 #include "tst_qpixmap.moc"
  1593 #include "tst_qpixmap.moc"