MCPcopy Index your code
hub / github.com/HumbleUI/Skija / BitmapTest

Class BitmapTest

tests/java/BitmapTest.java:11–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import io.github.humbleui.skija.test.runner.*;
10
11public class BitmapTest implements Executable {
12 @Override
13 public void execute() throws Exception {
14 TestRunner.testMethod(this, "base");
15 TestRunner.testMethod(this, "swap");
16 TestRunner.testMethod(this, "getSurfaceNull");
17 }
18
19 public void base() throws Exception {
20 try (var bitmap = new Bitmap()) {
21 int id1 = bitmap.getGenerationId();
22 assertEquals(true, bitmap.isNull());
23 assertEquals(true, bitmap.isEmpty());
24
25 bitmap.allocPixels(ImageInfo.makeS32(7, 3, ColorAlphaType.OPAQUE));
26 assertNotEquals(id1, bitmap.getGenerationId());
27
28 assertEquals(false, bitmap.isNull());
29 assertEquals(false, bitmap.isEmpty());
30
31 assertEquals(7L * 4, bitmap.getRowBytes());
32 assertEquals(4, bitmap.getBytesPerPixel());
33 assertEquals(7, bitmap.getRowBytesAsPixels());
34
35 bitmap.allocPixels(ImageInfo.makeS32(7, 3, ColorAlphaType.OPAQUE), 32);
36 assertEquals(32L, bitmap.getRowBytes());
37 assertEquals(4, bitmap.getBytesPerPixel());
38 assertEquals(8, bitmap.getRowBytesAsPixels());
39
40 bitmap.setImageInfo(ImageInfo.makeS32(7, 3, ColorAlphaType.OPAQUE));
41 assertEquals(true, bitmap.isNull());
42 assertEquals(false, bitmap.isEmpty());
43 assertEquals(false, bitmap.isReadyToDraw());
44 bitmap.allocPixels();
45 assertEquals(false, bitmap.isNull());
46 assertEquals(true, bitmap.isReadyToDraw());
47
48 bitmap.getGenerationId();
49 }
50 }
51
52 public void swap() throws Exception {
53 try (Bitmap a = new Bitmap(); Bitmap b = new Bitmap()) {
54 a.allocN32Pixels(10, 20);
55 b.allocN32Pixels(5, 6);
56 int aW = a.getWidth();
57 int aH = a.getHeight();
58 int bW = b.getWidth();
59 int bH = b.getHeight();
60 assertNotEquals(aW, bW);
61 a.swap(b);
62 // After swap, a should now have original b dimensions and vice versa
63 assertEquals(bW, a.getWidth());
64 assertEquals(bH, a.getHeight());
65 assertEquals(aW, b.getWidth());
66 assertEquals(aH, b.getHeight());
67 }
68 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected