mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-25 16:46:52 +02:00
glib/tests/cxx: Enable the c++ tests for all the C++ versions
We should support these macros everywhere, if not, we should fix them again.
This commit is contained in:
parent
a0f200593c
commit
c19904d6e8
@ -27,9 +27,6 @@ typedef struct
|
|||||||
static void
|
static void
|
||||||
test_typeof (void)
|
test_typeof (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
// Test that with C++11 we don't get those kind of errors:
|
|
||||||
// error: invalid conversion from ‘gpointer’ {aka ‘void*’} to ‘MyObject*’ [-fpermissive]
|
|
||||||
MyObject *obj = g_rc_box_new0 (MyObject);
|
MyObject *obj = g_rc_box_new0 (MyObject);
|
||||||
MyObject *obj2 = g_rc_box_acquire (obj);
|
MyObject *obj2 = g_rc_box_acquire (obj);
|
||||||
g_assert_true (obj2 == obj);
|
g_assert_true (obj2 == obj);
|
||||||
@ -37,12 +34,21 @@ test_typeof (void)
|
|||||||
MyObject *obj3 = g_atomic_pointer_get (&obj2);
|
MyObject *obj3 = g_atomic_pointer_get (&obj2);
|
||||||
g_assert_true (obj3 == obj);
|
g_assert_true (obj3 == obj);
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
MyObject *obj4 = nullptr;
|
MyObject *obj4 = nullptr;
|
||||||
|
#else
|
||||||
|
MyObject *obj4 = NULL;
|
||||||
|
#endif
|
||||||
g_atomic_pointer_set (&obj4, obj3);
|
g_atomic_pointer_set (&obj4, obj3);
|
||||||
g_assert_true (obj4 == obj);
|
g_assert_true (obj4 == obj);
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
MyObject *obj5 = nullptr;
|
MyObject *obj5 = nullptr;
|
||||||
g_atomic_pointer_compare_and_exchange (&obj5, nullptr, obj4);
|
g_atomic_pointer_compare_and_exchange (&obj5, nullptr, obj4);
|
||||||
|
#else
|
||||||
|
MyObject *obj5 = NULL;
|
||||||
|
g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4);
|
||||||
|
#endif
|
||||||
g_assert_true (obj5 == obj);
|
g_assert_true (obj5 == obj);
|
||||||
|
|
||||||
MyObject *obj6 = g_steal_pointer (&obj5);
|
MyObject *obj6 = g_steal_pointer (&obj5);
|
||||||
@ -50,15 +56,11 @@ test_typeof (void)
|
|||||||
|
|
||||||
g_clear_pointer (&obj6, g_rc_box_release);
|
g_clear_pointer (&obj6, g_rc_box_release);
|
||||||
g_rc_box_release (obj);
|
g_rc_box_release (obj);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_pointer_compare_and_exchange (void)
|
test_atomic_pointer_compare_and_exchange (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
const gchar *str1 = "str1";
|
const gchar *str1 = "str1";
|
||||||
const gchar *str2 = "str2";
|
const gchar *str2 = "str2";
|
||||||
const gchar *atomic_string = str1;
|
const gchar *atomic_string = str1;
|
||||||
@ -68,15 +70,11 @@ test_atomic_pointer_compare_and_exchange (void)
|
|||||||
|
|
||||||
g_assert_true (g_atomic_pointer_compare_and_exchange (&atomic_string, str1, str2));
|
g_assert_true (g_atomic_pointer_compare_and_exchange (&atomic_string, str1, str2));
|
||||||
g_assert_true (atomic_string == str2);
|
g_assert_true (atomic_string == str2);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_pointer_compare_and_exchange_full (void)
|
test_atomic_pointer_compare_and_exchange_full (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
const gchar *str1 = "str1";
|
const gchar *str1 = "str1";
|
||||||
const gchar *str2 = "str2";
|
const gchar *str2 = "str2";
|
||||||
const gchar *atomic_string = str1;
|
const gchar *atomic_string = str1;
|
||||||
@ -88,15 +86,11 @@ test_atomic_pointer_compare_and_exchange_full (void)
|
|||||||
g_assert_true (g_atomic_pointer_compare_and_exchange_full (&atomic_string, str1, str2, &old));
|
g_assert_true (g_atomic_pointer_compare_and_exchange_full (&atomic_string, str1, str2, &old));
|
||||||
g_assert_true (atomic_string == str2);
|
g_assert_true (atomic_string == str2);
|
||||||
g_assert_true (old == str1);
|
g_assert_true (old == str1);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_int_compare_and_exchange (void)
|
test_atomic_int_compare_and_exchange (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
gint atomic_int = 5;
|
gint atomic_int = 5;
|
||||||
|
|
||||||
g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
|
g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
|
||||||
@ -104,15 +98,11 @@ test_atomic_int_compare_and_exchange (void)
|
|||||||
|
|
||||||
g_assert_true (g_atomic_int_compare_and_exchange (&atomic_int, 5, 50));
|
g_assert_true (g_atomic_int_compare_and_exchange (&atomic_int, 5, 50));
|
||||||
g_assert_cmpint (atomic_int, ==, 50);
|
g_assert_cmpint (atomic_int, ==, 50);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_int_compare_and_exchange_full (void)
|
test_atomic_int_compare_and_exchange_full (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
gint atomic_int = 5;
|
gint atomic_int = 5;
|
||||||
gint old_value;
|
gint old_value;
|
||||||
|
|
||||||
@ -122,15 +112,11 @@ test_atomic_int_compare_and_exchange_full (void)
|
|||||||
g_assert_true (g_atomic_int_compare_and_exchange_full (&atomic_int, 5, 50, &old_value));
|
g_assert_true (g_atomic_int_compare_and_exchange_full (&atomic_int, 5, 50, &old_value));
|
||||||
g_assert_cmpint (atomic_int, ==, 50);
|
g_assert_cmpint (atomic_int, ==, 50);
|
||||||
g_assert_cmpint (old_value, ==, 5);
|
g_assert_cmpint (old_value, ==, 5);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_pointer_exchange (void)
|
test_atomic_pointer_exchange (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
const gchar *str1 = "str1";
|
const gchar *str1 = "str1";
|
||||||
const gchar *str2 = "str2";
|
const gchar *str2 = "str2";
|
||||||
const gchar *atomic_string = str1;
|
const gchar *atomic_string = str1;
|
||||||
@ -140,24 +126,17 @@ test_atomic_pointer_exchange (void)
|
|||||||
|
|
||||||
g_assert_true (g_atomic_pointer_exchange (&atomic_string, str2) == str1);
|
g_assert_true (g_atomic_pointer_exchange (&atomic_string, str2) == str1);
|
||||||
g_assert_true (atomic_string == str2);
|
g_assert_true (atomic_string == str2);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_atomic_int_exchange (void)
|
test_atomic_int_exchange (void)
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
gint atomic_int = 5;
|
gint atomic_int = 5;
|
||||||
|
|
||||||
g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
|
g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
|
||||||
"any compiler warnings in C++ mode");
|
"any compiler warnings in C++ mode");
|
||||||
|
|
||||||
g_assert_cmpint (g_atomic_int_exchange (&atomic_int, 50), ==, 5);
|
g_assert_cmpint (g_atomic_int_exchange (&atomic_int, 50), ==, 5);
|
||||||
#else
|
|
||||||
g_test_skip ("This test requires a C++11 compiler");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_NO_INLINE
|
G_NO_INLINE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user