summaryrefslogtreecommitdiff
path: root/tests/conform/test-conform-main.c
blob: 1dd9b68d79370e844a7e6fb8097940fb531f3137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "config.h"

#include <cogl/cogl.h>

#include <glib.h>
#include <locale.h>
#include <stdlib.h>

#include "test-utils.h"

#if 0
void
skip_init (TestUtilsGTestFixture *fixture,
           const void *data)
{
  /* void */
}

static void
skip_test (TestUtilsGTestFixture *fixture,
           const void *data)
{
  /* void */
}

void
skip_fini (TestUtilsGTestFixture *fixture,
           const void *data)
{
  /* void */
}
#endif

static void
run_todo_test (TestUtilsGTestFixture *fixture,
               void *data)
{
#ifdef G_OS_UNIX
  TestUtilsSharedState *state = data;

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
    {
      state->todo_func (fixture, data);
      exit (0);
    }

  g_test_trap_assert_failed ();
#endif
}

void
verify_failure (TestUtilsGTestFixture *fixture,
                void *data)
{
  g_assert (FALSE);
}

static TestUtilsSharedState *shared_state = NULL;

/* This is a bit of sugar for adding new conformance tests:
 *
 * - It adds an extern function definition just to save maintaining a header
 *   that lists test entry points.
 * - It sets up callbacks for a fixture, which lets us share initialization
 *   code between tests. (see test-utils.c)
 * - It passes in a shared data pointer that is initialised once in main(),
 *   that gets passed to the fixture setup and test functions. (See the
 *   definition in test-utils.h)
 */
#define ADD_TEST(NAMESPACE, FUNC)            G_STMT_START {             \
  extern void FUNC (TestUtilsGTestFixture *, void *);                   \
  g_test_add ("/conform" NAMESPACE "/" #FUNC,                           \
	      TestUtilsGTestFixture,                                    \
	      shared_state, /* data argument for test */                \
	      test_utils_init,                                          \
	      (void *)(FUNC),                                           \
	      test_utils_fini);    } G_STMT_END

/* this is a macro that conditionally executes a test if CONDITION
 * evaluates to TRUE; otherwise, it will put the test under the
 * "/skip" namespace and execute a dummy function that will always
 * pass.
 */
#define ADD_CONDITIONAL_TEST(CONDITION, NAMESPACE, FUNC)   G_STMT_START {   \
  if (!(CONDITION)) {                                                       \
    g_test_add ("/skipped" NAMESPACE "/" #FUNC,                             \
                TestUtilsGTestFixture,                                      \
                shared_state, /* data argument for test */                  \
                skip_init,                                                  \
                skip_test,                                                  \
                skip_fini);                                                 \
  } else { ADD_TEST (NAMESPACE, FUNC); }     } G_STMT_END

#define ADD_TODO_TEST(NAMESPACE, FUNC)              G_STMT_START {          \
   extern void FUNC (TestUtilsGTestFixture *, void *);                      \
   shared_state->todo_func = FUNC;                                          \
   g_test_add ("/todo" NAMESPACE "/" #FUNC,                                 \
              TestUtilsGTestFixture,                                        \
              shared_state,                                                 \
              test_utils_init,                                              \
              (void *)(run_todo_test),                                      \
              test_utils_fini);    } G_STMT_END

#define UNPORTED_TEST(NAMESPACE, FUNC)

gchar *
clutter_test_get_data_file (const gchar *filename)
{
  return g_build_filename (TESTS_DATADIR, filename, NULL);
}

int
main (int argc, char **argv)
{
  g_test_init (&argc, &argv, NULL);

  g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");

  /* Initialise the state you need to share with everything.
   */
  shared_state = g_new0 (TestUtilsSharedState, 1);
  shared_state->argc_addr = &argc;
  shared_state->argv_addr = &argv;

  /* This file is run through a sed script during the make step so the
   * lines containing the tests need to be formatted on a single line
   * each. To comment out a test use the SKIP or TODO macros. Using
   * #if 0 would break the script. */

  /* sanity check for the test suite itself */
  ADD_TODO_TEST ("/suite", verify_failure);

  UNPORTED_TEST ("/cogl", test_cogl_object);
  UNPORTED_TEST ("/cogl", test_cogl_fixed);
  UNPORTED_TEST ("/cogl", test_cogl_backface_culling);
  UNPORTED_TEST ("/cogl", test_cogl_materials);
  UNPORTED_TEST ("/cogl", test_cogl_pipeline_user_matrix);
  UNPORTED_TEST ("/cogl", test_cogl_blend_strings);
  UNPORTED_TEST ("/cogl", test_cogl_premult);
  UNPORTED_TEST ("/cogl", test_cogl_readpixels);
  UNPORTED_TEST ("/cogl", test_cogl_path);
  ADD_TEST ("/cogl", test_cogl_depth_test);

  UNPORTED_TEST ("/cogl/texture", test_cogl_npot_texture);
  UNPORTED_TEST ("/cogl/texture", test_cogl_multitexture);
  UNPORTED_TEST ("/cogl/texture", test_cogl_texture_mipmaps);
  UNPORTED_TEST ("/cogl/texture", test_cogl_sub_texture);
  UNPORTED_TEST ("/cogl/texture", test_cogl_pixel_array);
  UNPORTED_TEST ("/cogl/texture", test_cogl_texture_rectangle);
  UNPORTED_TEST ("/cogl/texture", test_cogl_texture_3d);
  UNPORTED_TEST ("/cogl/texture", test_cogl_wrap_modes);
  UNPORTED_TEST ("/cogl/texture", test_cogl_texture_pixmap_x11);
  UNPORTED_TEST ("/cogl/texture", test_cogl_texture_get_set_data);
  UNPORTED_TEST ("/cogl/texture", test_cogl_atlas_migration);

  UNPORTED_TEST ("/cogl/vertex-buffer", test_cogl_vertex_buffer_contiguous);
  UNPORTED_TEST ("/cogl/vertex-buffer", test_cogl_vertex_buffer_interleved);
  UNPORTED_TEST ("/cogl/vertex-buffer", test_cogl_vertex_buffer_mutability);

  UNPORTED_TEST ("/cogl/vertex-array", test_cogl_primitive);

  UNPORTED_TEST ("/cogl/shaders", test_cogl_just_vertex_shader);

  /* left to the end because they aren't currently very orthogonal and tend to
   * break subsequent tests! */
  UNPORTED_TEST ("/cogl", test_cogl_viewport);
  UNPORTED_TEST ("/cogl", test_cogl_offscreen);

  return g_test_run ();
}