1
0
Fork 0
mutter-performance-source/tests/conform/test-version.c
Neil Roberts b6b9ac0b85 Add a cogl-version header
This adds a version header which contains macros to define which
version of Cogl the application is being compiled against. This helps
applications that want to support multiple incompatible versions of
Cogl at compile time.

The macros are called COGL_VERSION_{MAJOR,MINOR,MICRO}. This does not
match Clutter which names them CLUTTER_{MAJOR,MINOR,MICRO}_VERSION but
I think the former is nicer and it at least matches Cairo and Pango.

The values of the macro are defined to COGL_VERSION_*_INTERNAL which
is generated by the configure script into cogl-defines.h.

There is also a macro for the entire version as a string called
COGL_VERSION_STRING.

The internal utility macros for encoding a 3 part version number into
a single integer have been moved into the new header so they can be
used publicly as a convenient way to check if the version is within a
particular range. There is also a COGL_VERSION_CHECK macro for the
very common case that a feature will be used since a particular
version of Cogl. There is a macro called COGL_VERSION which contains
the pre-encoded version of Cogl being compiled against for
convenience.

Unlike in Clutter this patch does not add any runtime version
identification mechanism.

A test case is also added which just contains static asserts to sanity
check the macros.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3480cf140dc355fa87ab3fbcf0aeeb0124798a8f)
2012-08-06 14:27:40 +01:00

77 lines
3.5 KiB
C

#include <cogl/cogl.h>
/* These will be redefined in config.h */
#undef COGL_ENABLE_EXPERIMENTAL_2_0_API
#undef COGL_ENABLE_EXPERIMENTAL_API
#include "test-utils.h"
#include "config.h"
#include <cogl/cogl-util.h>
_COGL_STATIC_ASSERT (COGL_VERSION_ENCODE (COGL_VERSION_MAJOR,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO) ==
COGL_VERSION,
"The pre-encoded Cogl version does not match the version "
"encoding macro");
_COGL_STATIC_ASSERT (COGL_VERSION_GET_MAJOR (COGL_VERSION_ENCODE (100,
200,
300)) ==
100,
"Getting the major component out of a encoded version "
"does not work");
_COGL_STATIC_ASSERT (COGL_VERSION_GET_MINOR (COGL_VERSION_ENCODE (100,
200,
300)) ==
200,
"Getting the minor component out of a encoded version "
"does not work");
_COGL_STATIC_ASSERT (COGL_VERSION_GET_MICRO (COGL_VERSION_ENCODE (100,
200,
300)) ==
300,
"Getting the micro component out of a encoded version "
"does not work");
_COGL_STATIC_ASSERT (COGL_VERSION_CHECK (COGL_VERSION_MAJOR,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO),
"Checking the Cogl version against the current version "
"does not pass");
_COGL_STATIC_ASSERT (!COGL_VERSION_CHECK (COGL_VERSION_MAJOR,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO + 1),
"Checking the Cogl version against a later micro version "
"should not pass");
_COGL_STATIC_ASSERT (!COGL_VERSION_CHECK (COGL_VERSION_MAJOR,
COGL_VERSION_MINOR + 1,
COGL_VERSION_MICRO),
"Checking the Cogl version against a later minor version "
"should not pass");
_COGL_STATIC_ASSERT (!COGL_VERSION_CHECK (COGL_VERSION_MAJOR + 1,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO),
"Checking the Cogl version against a later major version "
"should not pass");
_COGL_STATIC_ASSERT (COGL_VERSION_CHECK (COGL_VERSION_MAJOR - 1,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO),
"Checking the Cogl version against a older major version "
"should pass");
void
test_version (void)
{
const char *version = g_strdup_printf ("version = %i.%i.%i",
COGL_VERSION_MAJOR,
COGL_VERSION_MINOR,
COGL_VERSION_MICRO);
g_assert_cmpstr (version, ==, "version = " COGL_VERSION_STRING);
if (cogl_test_verbose ())
g_print ("OK\n");
}