@@ -49,7 +49,8 @@ class TestQgsImageCache : public QObject
49
49
void cleanup () {} // will be called after every testfunction.
50
50
void fillCache ();
51
51
void threadSafeImage ();
52
- void changeImage (); // check that cache is updated if image source file changes
52
+ void changeImage (); // check that cache is updated if image source file changes
53
+ void size (); // check various size-specific handling
53
54
void base64 ();
54
55
55
56
};
@@ -193,6 +194,29 @@ void TestQgsImageCache::changeImage()
193
194
QVERIFY ( imageCheck ( " imagecache_changed_before" , img, 30 ) );
194
195
}
195
196
197
+ void TestQgsImageCache::size ()
198
+ {
199
+ QgsImageCache cache;
200
+ QImage img;
201
+ bool inCache;
202
+ QString originalImage = TEST_DATA_DIR + QStringLiteral ( " /sample_image.png" );
203
+
204
+ // null size should return image using original size
205
+ img = cache.pathAsImage ( originalImage, QSize (), true , 1.0 , inCache );
206
+ QCOMPARE ( img.width (), 511 );
207
+ QCOMPARE ( img.height (), 800 );
208
+
209
+ // a size with an height set to 0 while keep aspect ratio is true should return an image with automatically computed height
210
+ img = cache.pathAsImage ( originalImage, QSize ( 100 , 0 ), true , 1.0 , inCache );
211
+ QCOMPARE ( img.width (), 100 );
212
+ QCOMPARE ( img.height (), 157 );
213
+
214
+ // a size with an width set to 0 while keep aspect ratio is true should return an image with automatically computed width
215
+ img = cache.pathAsImage ( originalImage, QSize ( 0 , 100 ), true , 1.0 , inCache );
216
+ QCOMPARE ( img.width (), 64 );
217
+ QCOMPARE ( img.height (), 100 );
218
+ }
219
+
196
220
void TestQgsImageCache::base64 ()
197
221
{
198
222
// test rendering images encoded in base 64
0 commit comments