]> git.cworth.org Git - fips/commitdiff
test: Rename handle-events.c to common.c
authorCarl Worth <cworth@cworth.org>
Mon, 1 Jul 2013 18:29:40 +0000 (11:29 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 2 Jul 2013 21:19:39 +0000 (14:19 -0700)
Previously, this C file defined one function
(handle_events). Recently, it acquired a second function
(create_context).

In order to provide a common namespace, these functions are here
renamed to:

common_handle_events
and
common_create_context

so the filename is renamed to match.

Similarly, the HANDLE_EVENTS_GL_PREFIX macro is also renamed to
COMMON_GL_PREFIX.

test/common.c [new file with mode: 0644]
test/glx-dlopen-dlsym.c
test/glx-dlopen-gpa.c
test/glx-link-call.c
test/glx-link-gpa.c
test/glx-link-gpaa.c
test/handle-events.c [deleted file]

diff --git a/test/common.c b/test/common.c
new file mode 100644 (file)
index 0000000..01ce383
--- /dev/null
@@ -0,0 +1,145 @@
+/* Copyright © 2013, Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/* This is C code intended to be included (yes, included) by test
+ * programs in the fips test suite.
+ *
+ * It defines two functions for use by the test:
+ *
+ *     static void
+ *     common_create_context (Display *dpy, GLXContext *ctx, XVisualInfo **vi);
+ * and:
+ *     static void
+ *     common_handle_events (Display *dpy, Window window);
+ *
+ * Before including this file, the test program must define a macro
+ * COMMON_GL_PREFIX to some prefix. This macro can be empty (to
+ * directly call functions in an OpenGL-library directly linked) or
+ * can be some custom prefix to call through symbols defined in the
+ * test program.
+ */
+
+#ifndef COMMON_GL_PREFIX
+#error Code including common.c must define COMMON_GL_PREFIX
+#endif
+
+#define concat_(a,b) a ## b
+#define concat(a,b) concat_(a,b)
+#define _(func) concat(COMMON_GL_PREFIX, func)
+
+static void
+set_2d_projection (int width, int height)
+{
+       _(glMatrixMode) (GL_PROJECTION);
+       _(glLoadIdentity) ();
+       _(glOrtho) (0, width, height, 0, 0, 1);
+       _(glMatrixMode) (GL_MODELVIEW);
+}
+
+static void
+paint_rgb_using_clear (double r, double g, double b)
+{
+        _(glClearColor) (r, g, b, 1.0);
+        _(glClear) (GL_COLOR_BUFFER_BIT);
+}
+
+static void
+common_create_context (Display *dpy,
+                      GLXContext *ctx_ret, XVisualInfo **visual_info_ret)
+{
+        int visual_attr[] = {
+                GLX_RGBA,
+                GLX_RED_SIZE,          8,
+                GLX_GREEN_SIZE,        8,
+                GLX_BLUE_SIZE,         8,
+                GLX_ALPHA_SIZE,        8,
+                GLX_DOUBLEBUFFER,
+                GLX_DEPTH_SIZE,                24,
+                GLX_STENCIL_SIZE,      8,
+                GLX_X_VISUAL_TYPE,     GLX_DIRECT_COLOR,
+                None
+        };
+
+       /* Window and context setup. */
+        *visual_info_ret = _(glXChooseVisual) (dpy, 0, visual_attr);
+        *ctx_ret = _(glXCreateContext) (dpy, *visual_info_ret, NULL, True);
+}
+
+static void
+draw (Display *dpy, GLXContext ctx, Window window, int width, int height)
+{
+       int i;
+        _(glXMakeCurrent) (dpy, window, ctx);
+
+        _(glViewport) (0, 0, width, height);
+
+       set_2d_projection (width, height);
+
+/* Simply count through some colors, frame by frame. */
+#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
+
+       int frame = 0;
+       for (i = 0; i < 2; i++) {
+               /* Frame: Draw a solid (magenta) frame */
+               paint_rgb_using_clear (RGB(frame));
+               _(glXSwapBuffers) (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (yellow) frame */
+               paint_rgb_using_clear (RGB(frame));
+               _(glXSwapBuffers) (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (cyan) frame */
+               paint_rgb_using_clear (RGB(frame));
+               _(glXSwapBuffers) (dpy, window);
+               frame++;
+       }
+
+       /* Cleanup */
+        _(glXDestroyContext) (dpy, ctx);
+}
+
+static void
+common_handle_events(Display *dpy, GLXContext ctx, Window window)
+{
+        XEvent xev;
+       int width = 0;
+       int height = 0;
+
+        XNextEvent (dpy, &xev);
+
+        while (1) {
+                XNextEvent (dpy, &xev);
+                switch (xev.type) {
+                case ConfigureNotify:
+                        width = xev.xconfigure.width;
+                        height = xev.xconfigure.height;
+                        break;
+                case Expose:
+                        if (xev.xexpose.count == 0) {
+                                draw (dpy, ctx, window, width, height);
+                                return;
+                        }
+                        break;
+                }
+        }
+}
index a9677987a4ed0e2f8a4904b4f54228966ece4b75..76749155d5755d4d3663bd56f57138dd9c07461a 100644 (file)
@@ -48,8 +48,8 @@ void (*my_glXDestroyContext) (Display *, GLXContext);
 Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
 void (*my_glXSwapBuffers) (Display *, GLXDrawable);
 
-#define HANDLE_EVENTS_GL_PREFIX my_
-#include "handle-events.c"
+#define COMMON_GL_PREFIX my_
+#include "common.c"
 
 static void
 resolve_symbols (void)
@@ -156,11 +156,11 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+        common_handle_events (dpy, ctx, window);
 
        util_x11_fini_window (dpy, window);
 
index 49717944c8553d23606482c95900b899640d1a8a..b9d1b1af82125f2762e7799af48640fd0ba883a3 100644 (file)
@@ -49,8 +49,8 @@ void (*my_glXDestroyContext) (Display *, GLXContext);
 Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
 void (*my_glXSwapBuffers) (Display *, GLXDrawable);
 
-#define HANDLE_EVENTS_GL_PREFIX my_
-#include "handle-events.c"
+#define COMMON_GL_PREFIX my_
+#include "common.c"
 
 static void
 resolve_symbols (void)
@@ -153,11 +153,11 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+        common_handle_events (dpy, ctx, window);
 
        util_x11_fini_window (dpy, window);
 
index 46cb563ce47ad681d40eb2d26da0e34186ad0d84..468411140d37537fc8fb3ba8bc0fada22dfd7cf2 100644 (file)
@@ -32,8 +32,8 @@
 
 #include "util-x11.h"
 
-#define HANDLE_EVENTS_GL_PREFIX
-#include "handle-events.c"
+#define COMMON_GL_PREFIX
+#include "common.c"
 
 int
 main (void)
@@ -45,11 +45,11 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+        common_handle_events (dpy, ctx, window);
 
        util_x11_fini_window (dpy, window);
 
index 8db80093300f8a024b1a9783e95d51e05f7bfec5..840a648695f058d772fb935fb5658060af8eef0c 100644 (file)
@@ -72,8 +72,8 @@ FIPS_GLXMAKECURRENT_FN my_glXMakeCurrent;
 typedef void (*FIPS_GLXSWAPBUFFERS_FN)(Display *, GLXDrawable);
 FIPS_GLXSWAPBUFFERS_FN my_glXSwapBuffers;
 
-#define HANDLE_EVENTS_GL_PREFIX my_
-#include "handle-events.c"
+#define COMMON_GL_PREFIX my_
+#include "common.c"
 
 static void
 resolve_symbols (void)
@@ -157,11 +157,11 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+        common_handle_events (dpy, ctx, window);
 
        util_x11_fini_window (dpy, window);
 
index 682ee9304817dc170f39c38c087e4185209b3b67..d25d295800443653ddf440ad36d884a362e553a8 100644 (file)
@@ -72,8 +72,8 @@ FIPS_GLXMAKECURRENT_FN my_glXMakeCurrent;
 typedef void (*FIPS_GLXSWAPBUFFERS_FN)(Display *, GLXDrawable);
 FIPS_GLXSWAPBUFFERS_FN my_glXSwapBuffers;
 
-#define HANDLE_EVENTS_GL_PREFIX my_
-#include "handle-events.c"
+#define COMMON_GL_PREFIX my_
+#include "common.c"
 
 static void
 resolve_symbols (void)
@@ -157,11 +157,11 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+        common_handle_events (dpy, ctx, window);
 
        util_x11_fini_window (dpy, window);
 
diff --git a/test/handle-events.c b/test/handle-events.c
deleted file mode 100644 (file)
index a28e1e6..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/* Copyright © 2013, Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/* This is C code intended to be included (yes, included) by test
- * programs in the fips test suite.
- *
- * It defines a function:
- *
- *     static void
- *     handle_events(Display *dpy, Window window);
- *
- * which handles X events, responding by drawing a few frames using
- * OpenGL.
- *
- * Before including this file, the test program must define a macro
- * HANDLE_EVENTS_GL_PREFIX to some prefix. This macro can be empty (to
- * directly call functions in an OpenGL-library directly linked) or
- * can be some custom prefix to call through symbols defined in the
- * test program.
- */
-
-#ifndef HANDLE_EVENTS_GL_PREFIX
-#error Code including handle-events.c must define HANDLE_EVENTS_GL_PREFIX
-#endif
-
-#define concat_(a,b) a ## b
-#define concat(a,b) concat_(a,b)
-#define _(func) concat(HANDLE_EVENTS_GL_PREFIX, func)
-
-static void
-set_2d_projection (int width, int height)
-{
-       _(glMatrixMode) (GL_PROJECTION);
-       _(glLoadIdentity) ();
-       _(glOrtho) (0, width, height, 0, 0, 1);
-       _(glMatrixMode) (GL_MODELVIEW);
-}
-
-static void
-paint_rgb_using_clear (double r, double g, double b)
-{
-        _(glClearColor) (r, g, b, 1.0);
-        _(glClear) (GL_COLOR_BUFFER_BIT);
-}
-
-static void
-create_context (Display *dpy, GLXContext *ctx_ret, XVisualInfo **visual_info_ret)
-{
-        int visual_attr[] = {
-                GLX_RGBA,
-                GLX_RED_SIZE,          8,
-                GLX_GREEN_SIZE,        8,
-                GLX_BLUE_SIZE,         8,
-                GLX_ALPHA_SIZE,        8,
-                GLX_DOUBLEBUFFER,
-                GLX_DEPTH_SIZE,                24,
-                GLX_STENCIL_SIZE,      8,
-                GLX_X_VISUAL_TYPE,     GLX_DIRECT_COLOR,
-                None
-        };
-
-       /* Window and context setup. */
-        *visual_info_ret = _(glXChooseVisual) (dpy, 0, visual_attr);
-        *ctx_ret = _(glXCreateContext) (dpy, *visual_info_ret, NULL, True);
-}
-
-static void
-draw (Display *dpy, GLXContext ctx, Window window, int width, int height)
-{
-       int i;
-        _(glXMakeCurrent) (dpy, window, ctx);
-
-        _(glViewport) (0, 0, width, height);
-
-       set_2d_projection (width, height);
-
-/* Simply count through some colors, frame by frame. */
-#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
-
-       int frame = 0;
-       for (i = 0; i < 2; i++) {
-               /* Frame: Draw a solid (magenta) frame */
-               paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
-               frame++;
-
-               /* Frame: Draw a solid (yellow) frame */
-               paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
-               frame++;
-
-               /* Frame: Draw a solid (cyan) frame */
-               paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
-               frame++;
-       }
-
-       /* Cleanup */
-        _(glXDestroyContext) (dpy, ctx);
-}
-
-static void
-handle_events(Display *dpy, GLXContext ctx, Window window)
-{
-        XEvent xev;
-       int width = 0;
-       int height = 0;
-
-        XNextEvent (dpy, &xev);
-
-        while (1) {
-                XNextEvent (dpy, &xev);
-                switch (xev.type) {
-                case ConfigureNotify:
-                        width = xev.xconfigure.width;
-                        height = xev.xconfigure.height;
-                        break;
-                case Expose:
-                        if (xev.xexpose.count == 0) {
-                                draw (dpy, ctx, window, width, height);
-                                return;
-                        }
-                        break;
-                }
-        }
-}