Skip to contentSkip to conversation

test_tls_crypt: Improve mock() usage to be more portable

PATCH In review Frank Lichtenheld 3 participants 3 messages Jun 30, 2023 – Jul 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_tls_crypt: Improve mock() usage to be more portable

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
---
 tests/unit_tests/openvpn/test_tls_crypt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/unit_tests/openvpn/test_tls_crypt.c +2 -2
index 8bed042f..ed7c7948 100644
@@ -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);
 
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw

Am 30.06.23 um 15:39 schrieb Frank Lichtenheld:

Quoted 3 lines

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:

#2 lore raw
In reply to Frank Lichtenheld

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 <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26796.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering