Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: tests/GrGLSLPrettyPrintTest.cpp

Issue 437593004: Pretty print of shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: removing unused variable Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/GrGLSLPrettyPrintTest.cpp
diff --git a/tests/GrGLSLPrettyPrintTest.cpp b/tests/GrGLSLPrettyPrintTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9977488d58f759a9f7b2c5f925d784fe81b8d278
--- /dev/null
+++ b/tests/GrGLSLPrettyPrintTest.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#if SK_SUPPORT_GPU
+#include "Test.h"
+#include "gl/GrGLSLPrettyPrint.h"
+
+#define ASSERT(x) REPORTER_ASSERT(r, x)
+
+const SkString input1("#this is not a realshader\nvec4 some stuff;outside of a function;"
+ "int i(int b, int c) { { some stuff;} fake block; //comments\n return i;}"
+ "void main()"
+ "{nowin a function;{indenting;{abit more;dreadedfor((;;)(;)((;;);)){doingstuff"
+ ";for(;;;){and more stufff;mixed garbage\n\n\t\t\t\t\n/*using this"
+ " comment\n is"
+ " dangerous\ndo so at your own\n risk*/;\n\n\t\t\t\n"
+ "//a comment\n}}a; little ; love; for ; leading; spaces;} "
+ "an struct = { int a; int b; };"
+ "int[5] arr = int[5](1,2,3,4,5);} some code at the bottom; for(;;) {} }");
+
+const SkString output1(
+ " 1\t#this is not a realshader\n"
+ " 2\tvec4 some stuff;\n"
+ " 3\toutside of a function;\n"
+ " 4\tint i(int b, int c) \n"
+ " 5\t{\n"
+ " 6\t\t{\n"
+ " 7\t\t\tsome stuff;\n"
+ " 8\t\t}\n"
+ " 9\t\tfake block;\n"
+ " 10\t\t//comments\n"
+ " 11\t\treturn i;\n"
+ " 12\t}\n"
+ " 13\tvoid main()\n"
+ " 14\t{\n"
+ " 15\t\tnowin a function;\n"
+ " 16\t\t{\n"
+ " 17\t\t\tindenting;\n"
+ " 18\t\t\t{\n"
+ " 19\t\t\t\tabit more;\n"
+ " 20\t\t\t\tdreadedfor((;;)(;)((;;);))\n"
+ " 21\t\t\t\t{\n"
+ " 22\t\t\t\t\tdoingstuff;\n"
+ " 23\t\t\t\t\tfor(;;;)\n"
+ " 24\t\t\t\t\t{\n"
+ " 25\t\t\t\t\t\tand more stufff;\n"
+ " 26\t\t\t\t\t\tmixed garbage/*using this comment\n"
+ " 27\t\t\t\t\t\t is dangerous\n"
+ " 28\t\t\t\t\t\tdo so at your own\n"
+ " 29\t\t\t\t\t\t risk*/;\n"
+ " 30\t\t\t\t\t\t//a comment\n"
+ " 31\t\t\t\t\t}\n"
+ " 32\t\t\t\t}\n"
+ " 33\t\t\t\ta;\n"
+ " 34\t\t\t\tlittle ;\n"
+ " 35\t\t\t\tlove;\n"
+ " 36\t\t\t\tfor ;\n"
+ " 37\t\t\t\tleading;\n"
+ " 38\t\t\t\tspaces;\n"
+ " 39\t\t\t}\n"
+ " 40\t\t\tan struct = \n"
+ " 41\t\t\t{\n"
+ " 42\t\t\t\tint a;\n"
+ " 43\t\t\t\tint b;\n"
+ " 44\t\t\t}\n"
+ " 45\t\t\t;\n"
+ " 46\t\t\tint[5] arr = int[5](1,2,3,4,5);\n"
+ " 47\t\t}\n"
+ " 48\t\tsome code at the bottom;\n"
+ " 49\t\tfor(;;) \n"
+ " 50\t\t{\n"
+ " 51\t\t}\n"
+ " 52\t}\n"
+ " 53\t");
+
+const SkString input2("{;;{{{{;;;{{{{{{{{{{{###\n##\n#####(((((((((((((unbalanced verything;;;"
+ "}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}"
+ ";;;;;;/////");
+
+DEF_TEST(GrGLSLPrettyPrint, r) {
+ SkString test = GrGLSLPrettyPrint::PrettyPrintGLSL(input1, true);
+ ASSERT(output1 == test);
+
+ // Just test we don't crash with garbage input
+ ASSERT(GrGLSLPrettyPrint::PrettyPrintGLSL(input2, true).c_str() != NULL);
+}
+
+#endif
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698