Add preprocessor "defined" operator corner cases
authorOlli Etuaho <oetuaho@nvidia.com>
Mon, 28 Sep 2015 08:08:52 +0000 (11:08 +0300)
committerPyry Haulos <phaulos@google.com>
Tue, 29 Sep 2015 22:28:21 +0000 (15:28 -0700)
The GLES3 shader tests have already required "defined" operator generated
by macro replacement to work. This is not specified by the C++ standard,
and has some corner cases where implementations might differ. Test the
corner cases to ensure fully compatible implementations.

These cases were already tested against some existing implementations on
Nexus devices, and the implementations mostly passed.

Change-Id: Ic54afc9436bb2ad2d7bfc7dc1e1833f700d3ca49

data/gles3/shaders/preprocessor.test

index 12e0d8c..f8fe6eb 100644 (file)
@@ -1666,6 +1666,115 @@ group conditional_inclusion "Conditional Inclusion Tests"
                ""
        end
 
+       case defined_macro_defined_test
+               version 300 es
+               values { output float out0 = 1.0; }
+               both ""
+                       #version 300 es
+                       precision mediump float;
+                       ${DECLARATIONS}
+                       void main()
+                       {
+       #define AAA defined
+
+       #if AAA AAA
+                               out0 = 1.0;
+       #else
+                               out0 = 0.0;
+       #endif
+                               ${OUTPUT}
+                       }
+               ""
+       end
+
+       case defined_macro_undef
+               version 300 es
+               values { output float out0 = 1.0; }
+               both ""
+                       #version 300 es
+                       precision mediump float;
+                       ${DECLARATIONS}
+                       void main()
+                       {
+       #define BBB 1
+       #define AAA defined(BBB)
+       #undef BBB
+
+       #if !AAA
+                               out0 = 1.0;
+       #else
+                               out0 = 0.0;
+       #endif
+                               ${OUTPUT}
+                       }
+               ""
+       end
+
+       case define_defined
+               version 300 es
+               values { output float out0 = 1.0; }
+               both ""
+                       #version 300 es
+                       precision mediump float;
+                       ${DECLARATIONS}
+                       void main()
+                       {
+       #define CCC 1
+       #define defined BBB
+       #define AAA defined
+
+       #if AAA CCC
+                               out0 = 1.0;
+       #else
+                               out0 = 0.0;
+       #endif
+                               ${OUTPUT}
+                       }
+               ""
+       end
+
+       case define_defined_outside_if
+               version 300 es
+               values { output float out0 = 1.0; }
+               both ""
+                       #version 300 es
+                       precision mediump float;
+                       ${DECLARATIONS}
+                       void main()
+                       {
+       #define CCC - 0.5
+       #define defined 0.5
+       #define AAA defined
+                               out0 = 1.0 - (AAA CCC);
+                               ${OUTPUT}
+                       }
+               ""
+       end
+
+       case defined_invalid_before_all_macros_replaced
+               version 300 es
+               expect compile_fail
+               values { output float out0 = 1.0; }
+               both ""
+                       #version 300 es
+                       precision mediump float;
+                       ${DECLARATIONS}
+                       void main()
+                       {
+       #define FOO 1
+       #define OPEN defined(
+       #define CLOSE FOO)
+
+       #if OPEN CLOSE
+                               out0 = 1.0;
+       #else
+                               out0 = 0.0;
+       #endif
+                               ${OUTPUT}
+                       }
+               ""
+       end
+
        case basic_3
                version 300 es
                values { output float out0 = 1.0; }