diff options
author | Andrew Woloszyn <awoloszyn@google.com> | 2016-03-09 10:49:36 -0500 |
---|---|---|
committer | Andrew Woloszyn <awoloszyn@google.com> | 2016-03-09 12:33:55 -0500 |
commit | e89549fcabc9a9539f9f878f92e3fd73c33fc833 (patch) | |
tree | 1a87ed155f750ff1249882798ae3801eb136daca /libshaderc/src | |
parent | ea38626467aef060ae6afd0aaf42a869e908e4f5 (diff) | |
download | shaderc-e89549fcabc9a9539f9f878f92e3fd73c33fc833.tar.gz |
Added simple C smoke test to prevent future C breakages.
This C file just compiles a single shader, but is sufficient
to make sure that shaderc.h can always be included from C.
Diffstat (limited to 'libshaderc/src')
-rw-r--r-- | libshaderc/src/shaderc_c_smoke_test.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/libshaderc/src/shaderc_c_smoke_test.c b/libshaderc/src/shaderc_c_smoke_test.c new file mode 100644 index 0000000..80c4048 --- /dev/null +++ b/libshaderc/src/shaderc_c_smoke_test.c @@ -0,0 +1,54 @@ +// Copyright 2016 The Shaderc Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "shaderc/shaderc.h" +#include <assert.h> +#include <string.h> + +// Because we want to test this as a plain old C file, we cannot use +// gtest, so just run a simple smoke test. + +int main() { + const char* test_program = + "#version 310 es\n" + "layout(location = 0) in highp vec4 vtxColor;\n" + "layout(location = 0) out highp vec4 outColor;\n" + "void main() {\n" + " outColor = vtxColor;" + "}\n"; + shaderc_compiler_t compiler; + shaderc_compilation_result_t result; + shaderc_compile_options_t options; + + compiler = shaderc_compiler_initialize(); + options = shaderc_compile_options_initialize(); + shaderc_compile_options_add_macro_definition(options, "FOO", 3, "1", 1); + result = shaderc_compile_into_spv( + compiler, test_program, strlen(test_program), + shaderc_glsl_fragment_shader, "a.glsl", "main", options); + + assert(result); + + if (shaderc_result_get_compilation_status(result) != + shaderc_compilation_status_success) { + // Early exit on failure. + return -1; + } + shaderc_result_release(result); + shaderc_compile_options_release(options); + shaderc_compiler_release(compiler); + + return 0; +} + |