2323#endif
2424
2525
26- string tostring (int x ) { return format ("%d" , x ); }
27- string tostring (float x ) { return format ("%g" , x ); }
28- string tostring (color x ) { return format ("%g" , x ); }
29- string tostring (point x ) { return format ("%g" , x ); }
30- string tostring (vector x ) { return format ("%g" , x ); }
31- string tostring (normal x ) { return format ("%g" , x ); }
32- string tostring (string x ) { return x ; }
26+
27+ void failmsg (string file , int line , string xs , int x , string ys , int y )
28+ {
29+ printf ("\nFAIL: %s:%d: %s (%d) == %s (%d)\n\n" , file , line , xs , x , ys , y );
30+ }
31+
32+ void failmsg (string file , int line , string xs , float x , string ys , float y )
33+ {
34+ printf ("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n" , file , line , xs , x , ys , y );
35+ }
36+
37+ void failmsg (string file , int line , string xs , color x , string ys , color y )
38+ {
39+ printf ("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n" , file , line , xs , x , ys , y );
40+ }
41+
42+ void failmsg (string file , int line , string xs , vector x , string ys , vector y )
43+ {
44+ printf ("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n" , file , line , xs , x , ys , y );
45+ }
3346
3447#ifdef COLOR2_H
35- string tostring (color2 x ) { return format ("%g %g" , x .r , x .a ); }
48+ void failmsg (string file , int line , string xs , color2 x , string ys , color2 y )
49+ {
50+ printf ("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n" ,
51+ file , line , xs , x .r , x .a , ys , y .r , y .a );
52+ }
3653#endif
3754
3855#ifdef COLOR4_H
39- string tostring ( color4 x )
56+ void failmsg ( string file , int line , string xs , color4 x , string ys , color4 y )
4057{
41- return format ("%g %g %g %g" , x .rgb .r , x .rgb .g , x .rgb .b , x .a );
58+ printf ("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n" ,
59+ file , line , xs , x .rgb , x .a , ys , y .rgb , y .a );
4260}
4361#endif
4462
4563#ifdef VECTOR2_H
46- string tostring (vector2 x ) { return format ("%g %g" , x .x , x .y ); }
64+ void failmsg (string file , int line , string xs , vector2 x , string ys , vector2 y )
65+ {
66+ printf ("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n" ,
67+ file , line , xs , x .x , x .y , ys , y .x , y .y );
68+ }
4769#endif
4870
4971#ifdef VECTOR4_H
50- string tostring ( vector4 x )
72+ void failmsg ( string file , int line , string xs , vector4 x , string ys , vector4 y )
5173{
52- return format ("%g %g %g %g" , x .x , x .y , x .z , x .w );
74+ printf ("\nFAIL: %s:%d: %s (%g %g %g %g) == %s (%g %g %g %g)\n\n" ,
75+ file , line , xs , x .x , x .y , x .z , x .w , ys , y .x , y .y , y .z , y .w );
5376}
5477#endif
5578
5679
80+
5781// Macros to test conditions in shaders.
5882//
5983// A success by default will just silently move on, but if the symbol
@@ -80,15 +104,14 @@ string tostring(vector4 x)
80104
81105
82106// Check that two expressions are equal. For non-built-in types, this
83- // requires that a tostring () function is defined for that type.
107+ // requires that a failmsg () function is defined for that type.
84108#define OSL_CHECK_EQUAL (x ,y ) \
85109 do { \
86110 if ((x) == (y)) { \
87111 if (OSL_UNITTEST_VERBOSE) \
88112 printf("PASS: %s == %s\n", #x, #y); \
89113 } else { \
90- printf("\nFAIL: %s:%d: %s (%s) == %s (%s)\n\n", \
91- __FILE__, __LINE__, #x, tostring(x), #y, tostring(y)); \
114+ failmsg(__FILE__, __LINE__, #x, x, #y, y); \
92115 if (OSL_UNITTEST_EXIT_ON_FAILURE) \
93116 exit(); \
94117 } \
0 commit comments