[glib/wip/pwithnall/backport-2578-clang-cxx-glib-2-72: 2/3] tests: Add C++ tests for typechecking with atomic compare and exchanges




commit 0e33f1110fa2abdbdf1c719b81e138009119ecaa
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Apr 1 13:44:45 2022 +0100

    tests: Add C++ tests for typechecking with atomic compare and exchanges
    
    The tests have to be conditional on C++11 being enabled, as the default
    C++ standard on macOS is (for some reason), C++97 (`__cplusplus` is
    defined as `199711L`).
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #2625

 glib/tests/cxx.cpp | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
---
diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp
index 18580cfc68..6426d43a71 100644
--- a/glib/tests/cxx.cpp
+++ b/glib/tests/cxx.cpp
@@ -53,6 +53,40 @@ test_typeof (void)
 #endif
 }
 
+static void
+test_atomic_pointer_compare_and_exchange (void)
+{
+#if __cplusplus >= 201103L
+  const gchar *str1 = "str1";
+  const gchar *str2 = "str2";
+  const gchar *atomic_string = str1;
+
+  g_test_message ("Test that g_atomic_pointer_compare_and_exchange() with a "
+                  "non-void* pointer doesn’t have any compiler warnings in C++ mode");
+
+  g_assert_true (g_atomic_pointer_compare_and_exchange (&atomic_string, str1, str2));
+  g_assert_true (atomic_string == str2);
+#else
+  g_test_skip ("This test requires a C++11 compiler");
+#endif
+}
+
+static void
+test_atomic_int_compare_and_exchange (void)
+{
+#if __cplusplus >= 201103L
+  gint atomic_int = 5;
+
+  g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
+                  "any compiler warnings in C++ mode");
+
+  g_assert_true (g_atomic_int_compare_and_exchange (&atomic_int, 5, 50));
+  g_assert_cmpint (atomic_int, ==, 50);
+#else
+  g_test_skip ("This test requires a C++11 compiler");
+#endif
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -63,6 +97,8 @@ main (int argc, char *argv[])
 #endif
 
   g_test_add_func ("/C++/typeof", test_typeof);
+  g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange);
+  g_test_add_func ("/C++/atomic-int-compare-and-exchange", test_atomic_int_compare_and_exchange);
 
   return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]