3

I'm trying to run some tests with Roboelectic over Bitmap and Getpixel methods: ((BitmapDrawable)Robolectric.application.getResources().getDrawable(R.drawable.color_test_1)).getBitmap().getPixel(100,100); But whatever i try i'm always getting 0 as Color.

Even if I use following example:

public void testGetPixelsWithoutAlpha() throws Exception {
    int[] colors = new int[100];
    for (int i = 0; i < 100; i++) {
        colors[i] = i;
    }

    Bitmap bm = Bitmap.createBitmap(colors, 10, 10, Bitmap.Config.RGB_565);


    int[] pixels = new int[100];
    bm.getPixels(pixels, 0, 10, 0, 0, 10, 10);
    for (int i = 0; i < 100; i++) {
        int p = bm.getPixel(i % 10, i / 10);
        System.out.println(p);
        assertEquals("getPixels", p, pixels[i]);
    }

I'm still getting 0 as pixels.

saikek
  • 1,099
  • 1
  • 8
  • 15

1 Answers1

2

Sadly, I don't think there's a way to do this kind of testing in Robolectric. The interesting parts of Bitmap are in native code, which doesn't get run by Robolectric. As a result, the pixels don't actually get set or changed.

BenTobin
  • 1,201
  • 1
  • 8
  • 16