Skip to content

Commit 4503cc9

Browse files
committed
Add tests
1 parent a444f75 commit 4503cc9

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

tests/yup_graphics/yup_Color.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,37 @@ TEST (ColorTests, String_Operations)
467467
EXPECT_EQ (fromInvalid.getARGB(), 0); // Should return default/empty color
468468
}
469469

470+
TEST (ColorTests, HexString_ZeroPadding)
471+
{
472+
// Test that hex string properly zero-pads all components
473+
// This was a bug where #E30000 would display as #e300ff instead of #e30000ff
474+
Color red (0xffe30000);
475+
String hexString = red.toString();
476+
EXPECT_EQ (hexString, "#e30000ff");
477+
EXPECT_EQ (hexString.length(), 9);
478+
479+
// Test with zeros in different positions
480+
Color zeroRed (0xff003456);
481+
EXPECT_EQ (zeroRed.toString(), "#003456ff");
482+
483+
Color zeroGreen (0xff120056);
484+
EXPECT_EQ (zeroGreen.toString(), "#120056ff");
485+
486+
Color zeroBlue (0xff123400);
487+
EXPECT_EQ (zeroBlue.toString(), "#123400ff");
488+
489+
Color zeroAlpha (0x00123456);
490+
EXPECT_EQ (zeroAlpha.toString(), "#12345600");
491+
492+
// Test all zeros
493+
Color allZeros (0x00000000);
494+
EXPECT_EQ (allZeros.toString(), "#00000000");
495+
496+
// Test single digit hex values
497+
Color singleDigits (0x0f010203);
498+
EXPECT_EQ (singleDigits.toString(), "#0102030f");
499+
}
500+
470501
TEST (ColorTests, Random_Color)
471502
{
472503
// Test opaqueRandom

tests/yup_graphics/yup_Path.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,3 +982,58 @@ TEST (PathTests, AppendPathWithTransformComplex)
982982
EXPECT_FALSE (p1.getBounds().isEmpty());
983983
EXPECT_GT (p1.size(), 0);
984984
}
985+
986+
TEST (PathTests, FillRule_DefaultIsNonZeroWinding)
987+
{
988+
// Test that paths default to non-zero winding rule
989+
Path p;
990+
EXPECT_TRUE (p.isUsingNonZeroWinding());
991+
}
992+
993+
TEST (PathTests, FillRule_SetToEvenOdd)
994+
{
995+
// Test setting to even-odd rule
996+
Path p;
997+
p.setUsingNonZeroWinding (false);
998+
EXPECT_FALSE (p.isUsingNonZeroWinding());
999+
}
1000+
1001+
TEST (PathTests, FillRule_SetToNonZeroWinding)
1002+
{
1003+
// Test setting to non-zero winding rule
1004+
Path p;
1005+
p.setUsingNonZeroWinding (false);
1006+
p.setUsingNonZeroWinding (true);
1007+
EXPECT_TRUE (p.isUsingNonZeroWinding());
1008+
}
1009+
1010+
TEST (PathTests, FillRule_PersistsAfterPathOperations)
1011+
{
1012+
// Test that fill rule persists after adding shapes
1013+
Path p;
1014+
p.setUsingNonZeroWinding (false);
1015+
1016+
p.addRectangle (0, 0, 10, 10);
1017+
EXPECT_FALSE (p.isUsingNonZeroWinding());
1018+
1019+
p.addEllipse (5, 5, 8, 8);
1020+
EXPECT_FALSE (p.isUsingNonZeroWinding());
1021+
1022+
p.lineTo (100, 100);
1023+
EXPECT_FALSE (p.isUsingNonZeroWinding());
1024+
}
1025+
1026+
TEST (PathTests, FillRule_IndependentBetweenPaths)
1027+
{
1028+
// Test that each path maintains its own fill rule
1029+
Path p1;
1030+
Path p2;
1031+
1032+
p1.setUsingNonZeroWinding (false);
1033+
EXPECT_FALSE (p1.isUsingNonZeroWinding());
1034+
EXPECT_TRUE (p2.isUsingNonZeroWinding()); // p2 should still be default
1035+
1036+
p2.setUsingNonZeroWinding (true);
1037+
EXPECT_FALSE (p1.isUsingNonZeroWinding()); // p1 should remain even-odd
1038+
EXPECT_TRUE (p2.isUsingNonZeroWinding());
1039+
}

0 commit comments

Comments
 (0)