Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "Test.h" | |
| 2 #include "TestClassDef.h" | |
| 3 | |
| 4 #include "SkPixelRef.h" | |
| 5 #include "SkMallocPixelRef.h" | |
| 6 | |
| 7 namespace { | |
| 8 | |
| 9 class TestListener : public SkPixelRef::InvalidationListener { | |
| 10 public: | |
| 11 explicit TestListener(int* ptr) : fPtr(ptr) {} | |
| 12 void onInvalidate() SK_OVERRIDE { (*fPtr)++; } | |
| 13 private: | |
| 14 int* fPtr; | |
| 15 }; | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 DEF_TEST(PixelRef_Invalidation, r) { | |
| 20 SkMallocPixelRef pixelRef(NULL, 0, NULL); // We don't really care about the pixels here. | |
| 21 | |
| 22 // Register a listener. | |
| 23 int count = 0; | |
| 24 pixelRef.addInvalidationListener(SkNEW_ARGS(TestListener, (&count))); | |
| 25 REPORTER_ASSERT(r, 0 == count); | |
| 26 | |
| 27 // No one has looked at our pixelRef's generation ID, so invalidating it doe sn't make sense. | |
| 28 // (An SkPixelRef tree falls in the forest but there's nobody around to hear it. Do we care?) | |
| 29 pixelRef.notifyPixelsChanged(); | |
| 30 REPORTER_ASSERT(r, 0 == count); | |
| 31 | |
| 32 // Force the generation ID to be calculated. | |
| 33 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); | |
| 34 | |
| 35 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi s is a no-op. | |
| 36 pixelRef.notifyPixelsChanged(); | |
| 37 REPORTER_ASSERT(r, 0 == count); | |
| 38 | |
| 39 // Force the generation ID to be recalculated, then add a listener. | |
| 40 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); | |
| 41 pixelRef.addInvalidationListener(SkNEW_ARGS(TestListener, (&count))); | |
| 42 pixelRef.notifyPixelsChanged(); | |
| 43 REPORTER_ASSERT(r, 1 == count); | |
| 44 | |
| 45 // Quick check that NULL is safe. | |
|
scroggo
2013/10/22 21:04:02
Is the goal here to test that we don't crash? Can
bsalomon
2013/10/23 13:52:57
¿If there was a bug it could crash in release, no?
mtklein
2013/10/23 15:28:10
Right. This is relevant in both Release and Debug
| |
| 46 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); | |
| 47 pixelRef.addInvalidationListener(NULL); | |
| 48 pixelRef.notifyPixelsChanged(); | |
| 49 } | |
| OLD | NEW |