[Openvpn-devel] test_tls_crypt: Improve mock() usage to be more portable

Message ID 20230630123908.82588-1-frank@lichtenheld.com
State Accepted
Headers show
Series [Openvpn-devel] test_tls_crypt: Improve mock() usage to be more portable | expand

Commit Message

Frank Lichtenheld June 30, 2023, 12:39 p.m. UTC
Use the casting variants of mock(). Using the mock_ptr_type
fixes an existing bug where test_tls_crypt.c couldn't
build in MinGW 32bit:

test_tls_crypt.c:127:27: error:
cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
  127 |     const char *pem_str = (const char *) mock();

Change-Id: I6c03313b8677fa07c07e718b1f85f7efd3c4dea8
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
---
 tests/unit_tests/openvpn/test_tls_crypt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Arne Schwabe July 1, 2023, 11:30 a.m. UTC | #1
Am 30.06.23 um 15:39 schrieb Frank Lichtenheld:
> Use the casting variants of mock(). Using the mock_ptr_type
> fixes an existing bug where test_tls_crypt.c couldn't
> build in MinGW 32bit:

Acked-By: Arne Schwabe <arne@rfc2549.org>
Gert Doering July 1, 2023, 8:15 p.m. UTC | #2
I tried to read up what mock() and the rest of these functions do,
and it seems the necessary amount of coffee has worn out... but
anyway, you and Arne understand that stuff, it's testing code, and
it passes (Linux) "make check", so good enough.

Your patch has been applied to the master and release/2.6 branch.

commit e87e44f7bcdffc208292cce9d314e2e52a175026 (master)
commit 4f24f71f6a1f491fe404370707cc6a4f549fcab3 (release/2.6)
Author: Frank Lichtenheld
Date:   Fri Jun 30 14:39:08 2023 +0200

     test_tls_crypt: Improve mock() usage to be more portable

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Arne Schwabe <arne@rfc2549.org>
     Message-Id: <20230630123908.82588-1-frank@lichtenheld.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26796.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c
index 8bed042f..ed7c7948 100644
--- a/tests/unit_tests/openvpn/test_tls_crypt.c
+++ b/tests/unit_tests/openvpn/test_tls_crypt.c
@@ -116,7 +116,7 @@  __wrap_buffer_write_file(const char *filename, const struct buffer *buf)
     check_expected(filename);
     check_expected(pem);
 
-    return mock();
+    return mock_type(bool);
 }
 
 struct buffer
@@ -124,7 +124,7 @@  __wrap_buffer_read_from_file(const char *filename, struct gc_arena *gc)
 {
     check_expected(filename);
 
-    const char *pem_str = (const char *) mock();
+    const char *pem_str = mock_ptr_type(const char *);
     struct buffer ret = alloc_buf_gc(strlen(pem_str) + 1, gc);
     buf_write(&ret, pem_str, strlen(pem_str) + 1);