| 12 | #include "fl/stl/shared_ptr.h" |
| 13 | |
| 14 | FL_TEST_FILE(FL_FILEPATH) { |
| 15 | using namespace fl; |
| 16 | namespace { |
| 17 | int allocation_count = 0; |
| 18 | |
| 19 | void* custom_malloc(size_t size) { |
| 20 | allocation_count++; |
| 21 | return ::malloc(size); |
| 22 | } |
| 23 | |
| 24 | void custom_free(void* ptr) { |
| 25 | allocation_count--; |
| 26 | ::free(ptr); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | FL_TEST_CASE("test frame custom allocator") { |
| 31 | // Set our custom allocator |
| 32 | SetPSRamAllocator(custom_malloc, custom_free); |
| 33 | |
| 34 | FramePtr frame = fl::make_shared<Frame>(100); // 100 pixels. |
| 35 | FL_CHECK(allocation_count == 1); // One for RGB. |
| 36 | frame.reset(); |
| 37 | |
| 38 | // Frame should be destroyed here |
| 39 | FL_CHECK(allocation_count == 0); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | FL_TEST_CASE("test blend by black") { |
| 44 | SetPSRamAllocator(custom_malloc, custom_free); |
| 45 | FramePtr frame = fl::make_shared<Frame>(1); // 1 pixels. |
| 46 | frame->rgb()[0] = CRGB(255, 0, 0); // Red |
| 47 | CRGB out[1]; |
| 48 | frame->draw(out, DrawMode::DRAW_MODE_BLEND_BY_MAX_BRIGHTNESS); |
| 49 | FL_CHECK(out[0] == CRGB(255, 0, 0)); // full red because max luma is 255 |
| 50 | out[0] = CRGB(0, 0, 0); |
| 51 | frame->rgb()[0] = CRGB(128, 0, 0); // Red |
| 52 | frame->draw(out, DrawMode::DRAW_MODE_BLEND_BY_MAX_BRIGHTNESS); |
| 53 | FL_CHECK(out[0] == CRGB(64, 0, 0)); |
| 54 | } |
| 55 | |
| 56 | } // FL_TEST_FILE |
nothing calls this directly
no test coverage detected