19
19
#include <jose/jose.h>
20
20
#include <assert.h>
21
21
#include <string.h>
22
+ #include <stdlib.h>
22
23
23
24
const struct {
24
25
const char * alg ;
@@ -41,6 +42,53 @@ const struct {
41
42
{}
42
43
};
43
44
45
+ static uint8_t * get_random_string (uint32_t length )
46
+ {
47
+ assert (length );
48
+ uint8_t * c = (uint8_t * )malloc (length * sizeof (uint8_t ));
49
+ for (uint32_t i = 0 ; i < length ; i ++ ) {
50
+ c [i ] = 'A' + (random () % 26 );
51
+ }
52
+ return c ;
53
+ }
54
+
55
+ static void
56
+ test_long_string (size_t inputlen ) {
57
+ jose_io_auto_t * b = NULL ;
58
+ jose_io_auto_t * c = NULL ;
59
+ jose_io_auto_t * z = NULL ;
60
+ void * buf1 = NULL ;
61
+ void * buf2 = NULL ;
62
+ size_t blen = 0 ;
63
+ size_t clen = 0 ;
64
+ const jose_hook_alg_t * a = jose_hook_alg_find (JOSE_HOOK_ALG_KIND_COMP , "DEF" );
65
+ uint8_t * str = get_random_string (inputlen );
66
+
67
+
68
+ /* Test compression first. */
69
+ b = jose_io_malloc (NULL , & buf1 , & blen );
70
+ assert (b );
71
+ z = a -> comp .def (a , NULL , b );
72
+ assert (z );
73
+
74
+ assert (z -> feed (z , str , inputlen ));
75
+ assert (z -> done (z ));
76
+
77
+ /* Test decompression now. */
78
+ c = jose_io_malloc (NULL , & buf2 , & clen );
79
+ assert (b );
80
+ z = a -> comp .inf (a , NULL , c );
81
+ assert (z );
82
+ assert (z -> feed (z , buf1 , blen ));
83
+ assert (z -> done (z ));
84
+
85
+ /* Compare the final output with the original input. */
86
+ assert (clen == inputlen );
87
+ assert (memcmp (buf2 , str , inputlen ) == 0 );
88
+
89
+ free (str );
90
+ }
91
+
44
92
static void
45
93
test (const jose_hook_alg_t * a , bool iter ,
46
94
const uint8_t * i , size_t il )
@@ -119,5 +167,8 @@ main(int argc, char *argv[])
119
167
tst_inf , sizeof (tst_inf ));
120
168
}
121
169
170
+ test_long_string (200000 ); // inside limits
171
+ // test_long_string(300000); // outside limits
172
+
122
173
return EXIT_SUCCESS ;
123
174
}
0 commit comments