[Openvpn-devel,v1] test_networking: use appropriate assert helpers

Message ID 20251103145842.22969-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v1] test_networking: use appropriate assert helpers | expand

Commit Message

Gert Doering Nov. 3, 2025, 2:58 p.m. UTC
From: Antonio Quartulli <antonio@mandelbit.com>

Inall unit tests we rely on CMocka's provided assert
helpers.
However, test_networking.c was still on the default
assert() call, which we try to avoid in favour of more
appropriate helpers.

Substitute them all with assert_*() from CMocka.

Change-Id: Ie153b3d5bf19200f225cd09131de8583645110be
Reported-by: Marc Heuse <marc@srlabs.de>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1342
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1342
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>

Comments

Gert Doering Nov. 3, 2025, 3:33 p.m. UTC | #1
Your patch has been applied to the master branch.

(As this is test code, and not a "real bug", I think it's fine to not
pull it up to release/2.6)

commit 21b943734f1911a158b7b465d11a04bb6de7f1a8
Author: Antonio Quartulli
Date:   Mon Nov 3 15:58:37 2025 +0100

     test_networking: use appropriate assert helpers

     Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1342
     Message-Id: <20251103145842.22969-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34155.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/tests/unit_tests/openvpn/test_networking.c b/tests/unit_tests/openvpn/test_networking.c
index 6a2d09f..1c9cac1 100644
--- a/tests/unit_tests/openvpn/test_networking.c
+++ b/tests/unit_tests/openvpn/test_networking.c
@@ -2,7 +2,8 @@ 
 #include "syshead.h"
 #include "networking.h"
 
-#include <assert.h>
+#include <setjmp.h>
+#include <cmocka.h>
 
 static char *iface = "ovpn-dummy0";
 
@@ -27,7 +28,7 @@ 
     int ret = net_iface_type(NULL, name, ret_type);
     if (ret == 0)
     {
-        assert(strcmp(type, ret_type) == 0);
+        assert_string_equal(type, ret_type);
     }
 
     return ret;
@@ -265,10 +266,10 @@ 
 
         /* following tests are standalone and do not print any CMD= */
         case 8:
-            assert(net__iface_new("dummy0815", "dummy") == 0);
-            assert(net__iface_type("dummy0815", "dummy") == 0);
-            assert(net__iface_del("dummy0815") == 0);
-            assert(net__iface_type("dummy0815", NULL) == -ENODEV);
+            assert_int_equal(net__iface_new("dummy0815", "dummy"), 0);
+            assert_int_equal(net__iface_type("dummy0815", "dummy"), 0);
+            assert_int_equal(net__iface_del("dummy0815"), 0);
+            assert_int_equal(net__iface_type("dummy0815", NULL), -ENODEV);
             return 0;
 
         default: