From f488d15b7aca552545f5a2e7fd400a351235c4d2 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 23 Oct 2024 15:23:07 +0200 Subject: [PATCH] [winpr,utils] update TestStream --- winpr/libwinpr/utils/test/TestStream.c | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/winpr/libwinpr/utils/test/TestStream.c b/winpr/libwinpr/utils/test/TestStream.c index 376297079..da54fa962 100644 --- a/winpr/libwinpr/utils/test/TestStream.c +++ b/winpr/libwinpr/utils/test/TestStream.c @@ -77,20 +77,20 @@ static BOOL TestStream_Verify(wStream* s, size_t mincap, size_t len, size_t pos) static BOOL TestStream_New(void) { - wStream* s = NULL; /* Test creation of a 0-size stream with no buffer */ - s = Stream_New(NULL, 0); + wStream* s = Stream_New(NULL, 0); if (s) return FALSE; + Stream_Free(s, TRUE); return TRUE; } static BOOL TestStream_Static(void) { - BYTE buffer[20]; - wStream staticStream; + BYTE buffer[20] = { 0 }; + wStream staticStream = { 0 }; wStream* s = &staticStream; UINT16 v = 0; /* Test creation of a static stream */ @@ -250,14 +250,18 @@ fail: #define Stream_Peek_UINT8_BE Stream_Peek_UINT8 #define Stream_Read_UINT8_BE Stream_Read_UINT8 +#define Stream_Peek_Get_UINT8_BE Stream_Peek_Get_UINT8 +#define Stream_Get_UINT8_BE Stream_Get_UINT8 #define Stream_Peek_INT8_BE Stream_Peek_INT8 +#define Stream_Peek_Get_INT8_BE Stream_Peek_Get_INT8 #define Stream_Read_INT8_BE Stream_Read_INT8 +#define Stream_Get_INT8_BE Stream_Get_INT8 #define TestStream_PeekAndRead(_s, _r, _t) \ do \ { \ - _t _a; \ - _t _b; \ + _t _a = 0; \ + _t _b = 0; \ BYTE* _p = Stream_Buffer(_s); \ Stream_SetPosition(_s, 0); \ Stream_Peek_##_t(_s, _a); \ @@ -267,6 +271,14 @@ fail: printf("%s: test1 " #_t "_LE failed\n", __func__); \ (_r) = FALSE; \ } \ + Stream_Rewind(_s, sizeof(_t)); \ + const _t _d = Stream_Peek_Get_##_t(_s); \ + const _t _c = Stream_Get_##_t(_s); \ + if (_c != _d) \ + { \ + printf("%s: test1 " #_t "_LE failed\n", __func__); \ + (_r) = FALSE; \ + } \ for (size_t _i = 0; _i < sizeof(_t); _i++) \ { \ if (((_a >> (_i * 8)) & 0xFF) != _p[_i]) \ @@ -285,6 +297,14 @@ fail: printf("%s: test1 " #_t "_BE failed\n", __func__); \ (_r) = FALSE; \ } \ + Stream_Rewind(_s, sizeof(_t)); \ + const _t _e = Stream_Peek_Get_##_t##_BE(_s); \ + const _t _f = Stream_Get_##_t##_BE(_s); \ + if (_e != _f) \ + { \ + printf("%s: test1 " #_t "_BE failed\n", __func__); \ + (_r) = FALSE; \ + } \ for (size_t _i = 0; _i < sizeof(_t); _i++) \ { \ if (((_a >> (_i * 8)) & 0xFF) != _p[sizeof(_t) - _i - 1]) \