joshualitt | bab82ed | 2014-08-08 09:41:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #if SK_SUPPORT_GPU |
| 9 | #include "Test.h" |
| 10 | #include "gl/GrGLSLPrettyPrint.h" |
| 11 | |
| 12 | #define ASSERT(x) REPORTER_ASSERT(r, x) |
| 13 | |
| 14 | const SkString input1("#this is not a realshader\nvec4 some stuff;outside of a function;" |
| 15 | "int i(int b, int c) { { some stuff;} fake block; //comments\n return i;}" |
| 16 | "void main()" |
| 17 | "{nowin a function;{indenting;{abit more;dreadedfor((;;)(;)((;;);)){doingstuff" |
| 18 | ";for(;;;){and more stufff;mixed garbage\n\n\t\t\t\t\n/*using this" |
| 19 | " comment\n is" |
| 20 | " dangerous\ndo so at your own\n risk*/;\n\n\t\t\t\n" |
| 21 | "//a comment\n}}a; little ; love; for ; leading; spaces;} " |
| 22 | "an struct = { int a; int b; };" |
| 23 | "int[5] arr = int[5](1,2,3,4,5);} some code at the bottom; for(;;) {} }"); |
| 24 | |
| 25 | const SkString output1( |
| 26 | " 1\t#this is not a realshader\n" |
| 27 | " 2\tvec4 some stuff;\n" |
| 28 | " 3\toutside of a function;\n" |
| 29 | " 4\tint i(int b, int c) \n" |
| 30 | " 5\t{\n" |
| 31 | " 6\t\t{\n" |
| 32 | " 7\t\t\tsome stuff;\n" |
| 33 | " 8\t\t}\n" |
| 34 | " 9\t\tfake block;\n" |
| 35 | " 10\t\t//comments\n" |
| 36 | " 11\t\treturn i;\n" |
| 37 | " 12\t}\n" |
| 38 | " 13\tvoid main()\n" |
| 39 | " 14\t{\n" |
| 40 | " 15\t\tnowin a function;\n" |
| 41 | " 16\t\t{\n" |
| 42 | " 17\t\t\tindenting;\n" |
| 43 | " 18\t\t\t{\n" |
| 44 | " 19\t\t\t\tabit more;\n" |
| 45 | " 20\t\t\t\tdreadedfor((;;)(;)((;;);))\n" |
| 46 | " 21\t\t\t\t{\n" |
| 47 | " 22\t\t\t\t\tdoingstuff;\n" |
| 48 | " 23\t\t\t\t\tfor(;;;)\n" |
| 49 | " 24\t\t\t\t\t{\n" |
| 50 | " 25\t\t\t\t\t\tand more stufff;\n" |
| 51 | " 26\t\t\t\t\t\tmixed garbage/*using this comment\n" |
| 52 | " 27\t\t\t\t\t\t is dangerous\n" |
| 53 | " 28\t\t\t\t\t\tdo so at your own\n" |
| 54 | " 29\t\t\t\t\t\t risk*/;\n" |
| 55 | " 30\t\t\t\t\t\t//a comment\n" |
| 56 | " 31\t\t\t\t\t}\n" |
| 57 | " 32\t\t\t\t}\n" |
| 58 | " 33\t\t\t\ta;\n" |
| 59 | " 34\t\t\t\tlittle ;\n" |
| 60 | " 35\t\t\t\tlove;\n" |
| 61 | " 36\t\t\t\tfor ;\n" |
| 62 | " 37\t\t\t\tleading;\n" |
| 63 | " 38\t\t\t\tspaces;\n" |
| 64 | " 39\t\t\t}\n" |
| 65 | " 40\t\t\tan struct = \n" |
| 66 | " 41\t\t\t{\n" |
| 67 | " 42\t\t\t\tint a;\n" |
| 68 | " 43\t\t\t\tint b;\n" |
| 69 | " 44\t\t\t}\n" |
| 70 | " 45\t\t\t;\n" |
| 71 | " 46\t\t\tint[5] arr = int[5](1,2,3,4,5);\n" |
| 72 | " 47\t\t}\n" |
| 73 | " 48\t\tsome code at the bottom;\n" |
| 74 | " 49\t\tfor(;;) \n" |
| 75 | " 50\t\t{\n" |
| 76 | " 51\t\t}\n" |
| 77 | " 52\t}\n" |
| 78 | " 53\t"); |
| 79 | |
| 80 | const SkString input2("{;;{{{{;;;{{{{{{{{{{{###\n##\n#####(((((((((((((unbalanced verything;;;" |
| 81 | "}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}" |
| 82 | ";;;;;;/////"); |
| 83 | |
| 84 | DEF_TEST(GrGLSLPrettyPrint, r) { |
| 85 | SkString test = GrGLSLPrettyPrint::PrettyPrintGLSL(input1, true); |
| 86 | ASSERT(output1 == test); |
| 87 | |
| 88 | // Just test we don't crash with garbage input |
| 89 | ASSERT(GrGLSLPrettyPrint::PrettyPrintGLSL(input2, true).c_str() != NULL); |
| 90 | } |
| 91 | |
| 92 | #endif |