MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/gfx/draw_line.hpp:7–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "fl/gfx/gfx.h"
6
7FL_TEST_FILE(FL_FILEPATH) {
8
9FL_TEST_CASE("drawLine horizontal and vertical lines") {
10 FL_SUBCASE("horizontal line at y=8") {
11 CRGB buffer[256] = {};
12 fl::CanvasRGB canvas(buffer, 16, 16);
13 canvas.drawLine(CRGB(255, 0, 0), 2, 8, 13, 8);
14
15 // Count non-zero pixels in row 8
16 int non_zero = 0;
17 for (int x = 0; x < 16; ++x) {
18 if (buffer[8 * 16 + x].r > 0) non_zero++;
19 }
20 FL_CHECK(non_zero >= 10); // Should have at least 10 pixels lit
21 }
22
23 FL_SUBCASE("vertical line at x=8") {
24 CRGB buffer[256] = {};
25 fl::CanvasRGB canvas(buffer, 16, 16);
26 canvas.drawLine(CRGB(255, 0, 0), 8, 2, 8, 13);
27
28 // Count non-zero pixels in column 8
29 int non_zero = 0;
30 for (int y = 0; y < 16; ++y) {
31 if (buffer[y * 16 + 8].r > 0) non_zero++;
32 }
33 FL_CHECK(non_zero >= 10); // Should have at least 10 pixels lit
34 }
35}
36
37FL_TEST_CASE("drawLine edge cases") {
38 FL_SUBCASE("zero-length line (no crash)") {
39 CRGB buffer[256] = {};
40 fl::CanvasRGB canvas(buffer, 16, 16);
41 canvas.drawLine(CRGB(255, 0, 0), 5, 5, 5, 5);
42 // Should not crash
43 FL_CHECK(true);
44 }
45
46 FL_SUBCASE("fully off-screen line (no crash)") {
47 CRGB buffer[256] = {};
48 fl::CanvasRGB canvas(buffer, 16, 16);
49 canvas.drawLine(CRGB(255, 0, 0), -100, 8, -50, 8);
50 // Should not crash, all pixels should be black
51 FL_CHECK(true);
52 }
53
54 FL_SUBCASE("partially clipped line") {
55 CRGB buffer[256] = {};
56 fl::CanvasRGB canvas(buffer, 16, 16);
57 canvas.drawLine(CRGB(255, 0, 0), -2, 8, 5, 8);
58 // Count non-zero pixels in row 8
59 int non_zero = 0;
60 for (int x = 0; x < 16; ++x) {
61 if (buffer[8 * 16 + x].r > 0) non_zero++;
62 }
63 FL_CHECK(non_zero >= 3); // Should have at least 3 pixels lit
64 }

Callers

nothing calls this directly

Calls 4

CRGBClass · 0.50
s16x16Class · 0.50
drawLineMethod · 0.45
to_floatMethod · 0.45

Tested by

no test coverage detected