diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2012-05-27 20:56:38 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2012-05-30 17:42:29 -0700 |
commit | e2f214de622987e1dd1ca493769990a1739d76cd (patch) | |
tree | a4f31ce088034e6041d5f29ec222ef386b6ff49c /tests | |
parent | 2b3bc76fe0eee50298fbd20b18ef2df90763e521 (diff) |
tests/gl_basic: Add tests for CGL
Add tests:
gl_basic.cgl_init
gl_basic.cgl_gl
The tests were verified to pass on MacOS 10.7.
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/CMakeLists.txt | 23 | ||||
-rw-r--r-- | tests/functional/gl_basic_cocoa.h | 21 | ||||
-rw-r--r-- | tests/functional/gl_basic_cocoa.m | 48 | ||||
-rw-r--r-- | tests/functional/gl_basic_test.c | 39 |
4 files changed, 130 insertions, 1 deletions
diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index 2527202..7b38cb4 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -3,4 +3,25 @@ link_libraries( waffle_test ) -add_executable(gl_basic_test gl_basic_test.c) +set(gl_basic_test_sources + gl_basic_test.c + ) + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + list(APPEND gl_basic_test_sources + gl_basic_cocoa.m + ) +endif() + +# CMake will pass to the C compiler only C sources. CMake does not recognize the +# .m extension and ignores any such files in the source lists. To coerce CMake +# to pass .m files to the compiler, we must lie and claim that they are +# C sources. +set_source_files_properties( + ${gl_basic_test_sources} + PROPERTIES LANGUAGE C + ) + +add_executable(gl_basic_test + ${gl_basic_test_sources} + ) diff --git a/tests/functional/gl_basic_cocoa.h b/tests/functional/gl_basic_cocoa.h new file mode 100644 index 0000000..7d6b705 --- /dev/null +++ b/tests/functional/gl_basic_cocoa.h @@ -0,0 +1,21 @@ +// Copyright 2012 Intel Corporation +// +// 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. + +#pragma once + +void +gl_basic_cocoa_init(void); + +void +gl_basic_cocoa_finish(void); diff --git a/tests/functional/gl_basic_cocoa.m b/tests/functional/gl_basic_cocoa.m new file mode 100644 index 0000000..33b5c3c --- /dev/null +++ b/tests/functional/gl_basic_cocoa.m @@ -0,0 +1,48 @@ +// Copyright 2012 Intel Corporation +// +// 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 "gl_basic_cocoa.h" + +#include <stdio.h> +#include <Cocoa/Cocoa.h> + +static NSAutoreleasePool* pool; + +void +gl_basic_cocoa_init(void) +{ + // From the NSApplication Class Reference: + // [...] if you do need to use Cocoa classes within the main() + // function itself (other than to load nib files or to instantiate + // NSApplication), you should create an autorelease pool before using + // the classes and then release the pool when you’re done. + pool = [[NSAutoreleasePool alloc] init]; + + // From the NSApplication Class Reference: + // The sharedApplication class method initializes the display + // environment and connects your program to the window server and the + // display server. + // + // It also creates the singleton NSApp if it does not yet exist. + [NSApplication sharedApplication]; +} + +void +gl_basic_cocoa_finish(void) +{ + // stdout must be flushed before invoking the garbage collector. + // Otherwise, the content of stdout does not appear over ssh. Weird. + fflush(stdout); + [pool drain]; +} diff --git a/tests/functional/gl_basic_test.c b/tests/functional/gl_basic_test.c index 78919a2..b6c5617 100644 --- a/tests/functional/gl_basic_test.c +++ b/tests/functional/gl_basic_test.c @@ -34,6 +34,8 @@ #include <waffle/waffle.h> #include <waffle_test/waffle_test.h> +#include "gl_basic_cocoa.h" + enum { // Choosing a smaller window would shorten the execution time of pixel // validation, but Windows 7 enforces a minimum size. @@ -240,6 +242,31 @@ gl_basic_draw(int32_t waffle_context_api, int32_t alpha) ASSERT_TRUE(waffle_display_disconnect(dpy)); } +#ifdef WAFFLE_HAS_CGL +TEST(gl_basic, cgl_init) +{ + gl_basic_init(WAFFLE_PLATFORM_CGL); +} + +TEST(gl_basic, cgl_gl_rgb) +{ + gl_basic_draw(WAFFLE_CONTEXT_OPENGL, 0); +} + +TEST(gl_basic, cgl_gl_rgba) +{ + gl_basic_draw(WAFFLE_CONTEXT_OPENGL, 1); +} + +static void +testsuite_cgl(void) +{ + TEST_RUN(gl_basic, cgl_init); + TEST_RUN(gl_basic, cgl_gl_rgb); + TEST_RUN(gl_basic, cgl_gl_rgba); +} +#endif // WAFFLE_HAS_CGL + #ifdef WAFFLE_HAS_GLX TEST(gl_basic, glx_init) { @@ -421,9 +448,18 @@ run_testsuite(void (*testsuite)(void)) } } else if (pid == 0) { + #ifdef __APPLE__ + gl_basic_cocoa_init(); + #endif + void (*testsuites[])(void) = {testsuite, 0}; int argc = 0; int num_failures = wt_main(&argc, NULL, testsuites); + + #ifdef __APPLE__ + gl_basic_cocoa_finish(); + #endif + exit(num_failures); } else { @@ -438,6 +474,9 @@ main(int argc, char *argv[]) if (argc != 1) usage_error(); +#ifdef WAFFLE_HAS_CGL + run_testsuite(testsuite_cgl); +#endif #ifdef WAFFLE_HAS_GLX run_testsuite(testsuite_glx); #endif |