Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 1 | From 44b4bcd56d7ac2bd8ebf00e9fa433ad897d68216 Mon Sep 17 00:00:00 2001 |
| 2 | From: Philip Withnall <pwithnall@endlessos.org> |
| 3 | Date: Fri, 1 Apr 2022 13:44:45 +0100 |
| 4 | Subject: [PATCH 1/2] tests: Add C++ tests for typechecking with atomic compare |
| 5 | and exchanges |
| 6 | |
| 7 | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> |
| 8 | |
| 9 | Helps: #2625 |
| 10 | Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2578] |
| 11 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 12 | --- |
| 13 | glib/tests/cxx.cpp | 28 ++++++++++++++++++++++++++++ |
| 14 | 1 file changed, 28 insertions(+) |
| 15 | |
| 16 | diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp |
| 17 | index be0a6bfa1..7d7f27c91 100644 |
| 18 | --- a/glib/tests/cxx.cpp |
| 19 | +++ b/glib/tests/cxx.cpp |
| 20 | @@ -53,6 +53,32 @@ test_typeof (void) |
| 21 | #endif |
| 22 | } |
| 23 | |
| 24 | +static void |
| 25 | +test_atomic_pointer_compare_and_exchange (void) |
| 26 | +{ |
| 27 | + const gchar *str1 = "str1"; |
| 28 | + const gchar *str2 = "str2"; |
| 29 | + const gchar *atomic_string = str1; |
| 30 | + |
| 31 | + g_test_message ("Test that g_atomic_pointer_compare_and_exchange() with a " |
| 32 | + "non-void* pointer doesn’t have any compiler warnings in C++ mode"); |
| 33 | + |
| 34 | + g_assert_true (g_atomic_pointer_compare_and_exchange (&atomic_string, str1, str2)); |
| 35 | + g_assert_true (atomic_string == str2); |
| 36 | +} |
| 37 | + |
| 38 | +static void |
| 39 | +test_atomic_int_compare_and_exchange (void) |
| 40 | +{ |
| 41 | + gint atomic_int = 5; |
| 42 | + |
| 43 | + g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have " |
| 44 | + "any compiler warnings in C++ mode"); |
| 45 | + |
| 46 | + g_assert_true (g_atomic_int_compare_and_exchange (&atomic_int, 5, 50)); |
| 47 | + g_assert_cmpint (atomic_int, ==, 50); |
| 48 | +} |
| 49 | + |
| 50 | int |
| 51 | main (int argc, char *argv[]) |
| 52 | { |
| 53 | @@ -63,6 +89,8 @@ main (int argc, char *argv[]) |
| 54 | #endif |
| 55 | |
| 56 | g_test_add_func ("/C++/typeof", test_typeof); |
| 57 | + g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange); |
| 58 | + g_test_add_func ("/C++/atomic-int-compare-and-exchange", test_atomic_int_compare_and_exchange); |
| 59 | |
| 60 | return g_test_run (); |
| 61 | } |
| 62 | -- |
| 63 | 2.35.1 |
| 64 | |