@@ -696,7 +696,7 @@ TEST test_string_to_color_invalid(void)
696
696
struct setting s ;
697
697
s .type = TYPE_COLOR ;
698
698
s .value = & val ;
699
- s .name = "test_color " ;
699
+ s .name = "test_color_invalid " ;
700
700
701
701
const char * inputs [] = {
702
702
"" ,
@@ -727,6 +727,69 @@ TEST test_string_to_color_invalid(void)
727
727
PASS ();
728
728
}
729
729
730
+ TEST test_string_to_gradient (void )
731
+ {
732
+ struct gradient * grad = NULL ;
733
+ struct setting s ;
734
+ s .type = TYPE_GRADIENT ;
735
+ s .value = & grad ;
736
+ s .name = "test_gradient" ;
737
+
738
+ const char * inputs [] = {
739
+ "#123456" ,
740
+ "#ab123c" ,
741
+ "#abc, #ebf, #aaafff" ,
742
+ "#abc123, #acaf8f" ,
743
+ };
744
+
745
+ // NOTE: Flexible array shenanigans
746
+ struct gradient * results [] = {
747
+ gradient_alloc (1 ),
748
+ gradient_alloc (1 ),
749
+ gradient_alloc (3 ),
750
+ gradient_alloc (2 ),
751
+ };
752
+
753
+ results [0 ]-> colors [0 ] = (struct color ) { (double )0x12 / 0xff , (double )0x34 / 0xff , (double )0x56 / 0xff , 1.0 };
754
+
755
+ results [1 ]-> colors [0 ] = (struct color ) { (double )0xab / 0xff , (double )0x12 / 0xff , (double )0x3c / 0xff , 1.0 };
756
+
757
+ results [2 ]-> colors [0 ] = (struct color ) { (double )0xaa / 0xff , (double )0xbb / 0xff , (double )0xcc / 0xff , 1.0 };
758
+ results [2 ]-> colors [1 ] = (struct color ) { (double )0xee / 0xff , (double )0xbb / 0xff , (double )0xff / 0xff , 1.0 };
759
+ results [2 ]-> colors [2 ] = (struct color ) { (double )0xaa / 0xff , (double )0xaf / 0xff , (double )0xff / 0xff , 1.0 };
760
+
761
+ results [3 ]-> colors [0 ] = (struct color ) { (double )0xab / 0xff , (double )0xc1 / 0xff , (double )0x23 / 0xff , 1.0 };
762
+ results [3 ]-> colors [1 ] = (struct color ) { (double )0xac / 0xff , (double )0xaf / 0xff , (double )0x8f / 0xff , 1.0 };
763
+
764
+ ARRAY_SAME_LENGTH (inputs , results );
765
+
766
+ static char buf [100 ];
767
+
768
+ for (int i = 0 ; i < G_N_ELEMENTS (inputs ); i ++ ) {
769
+ sprintf (buf , "Failed in round %i" , i );
770
+ ASSERTm (buf , set_from_string (& grad , s , inputs [i ]));
771
+
772
+ char * t1 = gradient_to_string (results [i ]);
773
+ char * t2 = gradient_to_string (grad );
774
+
775
+ sprintf (buf , "Failed in round %i. Expected %s, got %s" , i , t1 , t2 );
776
+
777
+ g_free (t1 );
778
+ g_free (t2 );
779
+
780
+ ASSERTm (buf , grad != NULL );
781
+ ASSERTm (buf , grad -> length == results [i ]-> length );
782
+
783
+ for (int k = 0 ; k < grad -> length ; k ++ )
784
+ ASSERTm (buf , COLOR_SAME (grad -> colors [k ], results [i ]-> colors [k ]));
785
+ }
786
+
787
+ for (int i = 0 ; i < G_N_ELEMENTS (results ); i ++ )
788
+ gradient_free (results [i ]);
789
+
790
+ PASS ();
791
+ }
792
+
730
793
TEST test_string_to_length (void )
731
794
{
732
795
struct length val = {0 };
@@ -999,6 +1062,7 @@ SUITE(suite_option_parser)
999
1062
RUN_TEST (test_string_to_sepcolor_invalid );
1000
1063
RUN_TEST (test_string_to_color );
1001
1064
RUN_TEST (test_string_to_color_invalid );
1065
+ RUN_TEST (test_string_to_gradient );
1002
1066
RUN_TEST (test_enum_size );
1003
1067
RUN_TEST (test_string_to_length );
1004
1068
RUN_TEST (test_string_to_length_invalid );
0 commit comments