FreeRDP
TestStream.c
1 #include <winpr/crt.h>
2 #include <winpr/print.h>
3 #include <winpr/crypto.h>
4 #include <winpr/stream.h>
5 
6 static BOOL TestStream_Verify(wStream* s, size_t mincap, size_t len, size_t pos)
7 {
8  if (Stream_Buffer(s) == NULL)
9  {
10  printf("stream buffer is null\n");
11  return FALSE;
12  }
13 
14  if (Stream_ConstPointer(s) == NULL)
15  {
16  printf("stream pointer is null\n");
17  return FALSE;
18  }
19 
20  if (Stream_PointerAs(s, BYTE) < Stream_Buffer(s))
21  {
22  printf("stream pointer (%p) or buffer (%p) is invalid\n", Stream_ConstPointer(s),
23  (void*)Stream_Buffer(s));
24  return FALSE;
25  }
26 
27  if (Stream_Capacity(s) < mincap)
28  {
29  printf("stream capacity is %" PRIuz " but minimum expected value is %" PRIuz "\n",
30  Stream_Capacity(s), mincap);
31  return FALSE;
32  }
33 
34  if (Stream_Length(s) != len)
35  {
36  printf("stream has unexpected length (%" PRIuz " instead of %" PRIuz ")\n",
37  Stream_Length(s), len);
38  return FALSE;
39  }
40 
41  if (Stream_GetPosition(s) != pos)
42  {
43  printf("stream has unexpected position (%" PRIuz " instead of %" PRIuz ")\n",
44  Stream_GetPosition(s), pos);
45  return FALSE;
46  }
47 
48  if (Stream_GetPosition(s) > Stream_Length(s))
49  {
50  printf("stream position (%" PRIuz ") exceeds length (%" PRIuz ")\n", Stream_GetPosition(s),
51  Stream_Length(s));
52  return FALSE;
53  }
54 
55  if (Stream_GetPosition(s) > Stream_Capacity(s))
56  {
57  printf("stream position (%" PRIuz ") exceeds capacity (%" PRIuz ")\n",
58  Stream_GetPosition(s), Stream_Capacity(s));
59  return FALSE;
60  }
61 
62  if (Stream_Length(s) > Stream_Capacity(s))
63  {
64  printf("stream length (%" PRIuz ") exceeds capacity (%" PRIuz ")\n", Stream_Length(s),
65  Stream_Capacity(s));
66  return FALSE;
67  }
68 
69  if (Stream_GetRemainingLength(s) != len - pos)
70  {
71  printf("stream remaining length (%" PRIuz " instead of %" PRIuz ")\n",
72  Stream_GetRemainingLength(s), len - pos);
73  return FALSE;
74  }
75 
76  return TRUE;
77 }
78 
79 static BOOL TestStream_New(void)
80 {
81  /* Test creation of a 0-size stream with no buffer */
82  wStream* s = Stream_New(NULL, 0);
83 
84  if (s)
85  return FALSE;
86  Stream_Free(s, TRUE);
87 
88  return TRUE;
89 }
90 
91 static BOOL TestStream_Static(void)
92 {
93  BYTE buffer[20] = { 0 };
94  wStream staticStream = { 0 };
95  wStream* s = &staticStream;
96  UINT16 v = 0;
97  /* Test creation of a static stream */
98  Stream_StaticInit(s, buffer, sizeof(buffer));
99  Stream_Write_UINT16(s, 0xcab1);
100  Stream_SetPosition(s, 0);
101  Stream_Read_UINT16(s, v);
102 
103  if (v != 0xcab1)
104  return FALSE;
105 
106  Stream_SetPosition(s, 0);
107  Stream_Write_UINT16(s, 1);
108 
109  if (!Stream_EnsureRemainingCapacity(s, 10)) /* we can ask for 10 bytes */
110  return FALSE;
111 
112  /* 30 is bigger than the buffer, it will be reallocated on the heap */
113  if (!Stream_EnsureRemainingCapacity(s, 30) || !s->isOwner)
114  return FALSE;
115 
116  Stream_Write_UINT16(s, 2);
117  Stream_SetPosition(s, 0);
118  Stream_Read_UINT16(s, v);
119 
120  if (v != 1)
121  return FALSE;
122 
123  Stream_Read_UINT16(s, v);
124 
125  if (v != 2)
126  return FALSE;
127 
128  // Intentional warning as the stream is not allocated.
129  // Still, Stream_Free should not release such memory, therefore this statement
130  // is required to test that.
131  WINPR_PRAGMA_DIAG_PUSH
132  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
133  Stream_Free(s, TRUE);
134  WINPR_PRAGMA_DIAG_POP
135  return TRUE;
136 }
137 
138 static BOOL TestStream_Create(size_t count, BOOL selfAlloc)
139 {
140  size_t len = 0;
141  size_t cap = 0;
142  wStream* s = NULL;
143  void* buffer = NULL;
144 
145  for (size_t i = 0; i < count; i++)
146  {
147  len = cap = i + 1;
148 
149  if (selfAlloc)
150  {
151  if (!(buffer = malloc(cap)))
152  {
153  printf("%s: failed to allocate buffer of size %" PRIuz "\n", __func__, cap);
154  goto fail;
155  }
156  }
157 
158  if (!(s = Stream_New(selfAlloc ? buffer : NULL, len)))
159  {
160  printf("%s: Stream_New failed for stream #%" PRIuz "\n", __func__, i);
161  goto fail;
162  }
163 
164  if (!TestStream_Verify(s, cap, len, 0))
165  {
166  goto fail;
167  }
168 
169  for (size_t pos = 0; pos < len; pos++)
170  {
171  Stream_SetPosition(s, pos);
172  Stream_SealLength(s);
173 
174  if (!TestStream_Verify(s, cap, pos, pos))
175  {
176  goto fail;
177  }
178  }
179 
180  if (selfAlloc)
181  {
182  memset(buffer, (BYTE)(i % 256), cap);
183 
184  if (memcmp(buffer, Stream_Buffer(s), cap) != 0)
185  {
186  printf("%s: buffer memory corruption\n", __func__);
187  goto fail;
188  }
189  }
190 
191  Stream_Free(s, buffer ? FALSE : TRUE);
192  free(buffer);
193  }
194 
195  return TRUE;
196 fail:
197  free(buffer);
198 
199  if (s)
200  {
201  Stream_Free(s, buffer ? FALSE : TRUE);
202  }
203 
204  return FALSE;
205 }
206 
207 static BOOL TestStream_Extent(UINT32 maxSize)
208 {
209  wStream* s = NULL;
210  BOOL result = FALSE;
211 
212  if (!(s = Stream_New(NULL, 1)))
213  {
214  printf("%s: Stream_New failed\n", __func__);
215  return FALSE;
216  }
217 
218  for (UINT32 i = 1; i < maxSize; i++)
219  {
220  if (i % 2)
221  {
222  if (!Stream_EnsureRemainingCapacity(s, i))
223  goto fail;
224  }
225  else
226  {
227  if (!Stream_EnsureCapacity(s, i))
228  goto fail;
229  }
230 
231  Stream_SetPosition(s, i);
232  Stream_SealLength(s);
233 
234  if (!TestStream_Verify(s, i, i, i))
235  {
236  printf("%s: failed to verify stream in iteration %" PRIu32 "\n", __func__, i);
237  goto fail;
238  }
239  }
240 
241  result = TRUE;
242 fail:
243 
244  if (s)
245  {
246  Stream_Free(s, TRUE);
247  }
248 
249  return result;
250 }
251 
252 #define Stream_Peek_UINT8_BE Stream_Peek_UINT8
253 #define Stream_Read_UINT8_BE Stream_Read_UINT8
254 #define Stream_Peek_Get_UINT8_BE Stream_Peek_Get_UINT8
255 #define Stream_Get_UINT8_BE Stream_Get_UINT8
256 #define Stream_Peek_INT8_BE Stream_Peek_INT8
257 #define Stream_Peek_Get_INT8_BE Stream_Peek_Get_INT8
258 #define Stream_Read_INT8_BE Stream_Read_INT8
259 #define Stream_Get_INT8_BE Stream_Get_INT8
260 
261 #define TestStream_PeekAndRead(_s, _r, _t) \
262  do \
263  { \
264  _t _a = 0; \
265  _t _b = 0; \
266  BYTE* _p = Stream_Buffer(_s); \
267  Stream_SetPosition(_s, 0); \
268  Stream_Peek_##_t(_s, _a); \
269  Stream_Read_##_t(_s, _b); \
270  if (_a != _b) \
271  { \
272  printf("%s: test1 " #_t "_LE failed\n", __func__); \
273  (_r) = FALSE; \
274  } \
275  Stream_Rewind(_s, sizeof(_t)); \
276  const _t _d = Stream_Peek_Get_##_t(_s); \
277  const _t _c = Stream_Get_##_t(_s); \
278  if (_c != _d) \
279  { \
280  printf("%s: test1 " #_t "_LE failed\n", __func__); \
281  (_r) = FALSE; \
282  } \
283  for (size_t _i = 0; _i < sizeof(_t); _i++) \
284  { \
285  if (((_a >> (_i * 8)) & 0xFF) != _p[_i]) \
286  { \
287  printf("%s: test2 " #_t "_LE failed\n", __func__); \
288  (_r) = FALSE; \
289  break; \
290  } \
291  } \
292  /* printf("a: 0x%016llX\n", a); */ \
293  Stream_SetPosition(_s, 0); \
294  Stream_Peek_##_t##_BE(_s, _a); \
295  Stream_Read_##_t##_BE(_s, _b); \
296  if (_a != _b) \
297  { \
298  printf("%s: test1 " #_t "_BE failed\n", __func__); \
299  (_r) = FALSE; \
300  } \
301  Stream_Rewind(_s, sizeof(_t)); \
302  const _t _e = Stream_Peek_Get_##_t##_BE(_s); \
303  const _t _f = Stream_Get_##_t##_BE(_s); \
304  if (_e != _f) \
305  { \
306  printf("%s: test1 " #_t "_BE failed\n", __func__); \
307  (_r) = FALSE; \
308  } \
309  for (size_t _i = 0; _i < sizeof(_t); _i++) \
310  { \
311  if (((_a >> (_i * 8)) & 0xFF) != _p[sizeof(_t) - _i - 1]) \
312  { \
313  printf("%s: test2 " #_t "_BE failed\n", __func__); \
314  (_r) = FALSE; \
315  break; \
316  } \
317  } \
318  /* printf("a: 0x%016llX\n", a); */ \
319  } while (0)
320 
321 static BOOL TestStream_WriteAndRead(UINT64 value)
322 {
323  union
324  {
325  UINT8 u8;
326  UINT16 u16;
327  UINT32 u32;
328  UINT64 u64;
329  INT8 i8;
330  INT16 i16;
331  INT32 i32;
332  INT64 i64;
333  } val;
334  val.u64 = value;
335 
336  wStream* s = Stream_New(NULL, 1024);
337  if (!s)
338  return FALSE;
339  BOOL rc = FALSE;
340 
341  {
342  Stream_Write_UINT8(s, val.u8);
343  Stream_Rewind_UINT8(s);
344  const UINT8 ru8 = Stream_Get_UINT8(s);
345  Stream_Rewind_UINT8(s);
346  if (val.u8 != ru8)
347  goto fail;
348  }
349  {
350  Stream_Write_UINT16(s, val.u16);
351  Stream_Rewind_UINT16(s);
352  const UINT16 ru = Stream_Get_UINT16(s);
353  Stream_Rewind_UINT16(s);
354  if (val.u16 != ru)
355  goto fail;
356  }
357  {
358  Stream_Write_UINT16_BE(s, val.u16);
359  Stream_Rewind_UINT16(s);
360  const UINT16 ru = Stream_Get_UINT16_BE(s);
361  Stream_Rewind_UINT16(s);
362  if (val.u16 != ru)
363  goto fail;
364  }
365  {
366  Stream_Write_UINT32(s, val.u32);
367  Stream_Rewind_UINT32(s);
368  const UINT32 ru = Stream_Get_UINT32(s);
369  Stream_Rewind_UINT32(s);
370  if (val.u32 != ru)
371  goto fail;
372  }
373  {
374  Stream_Write_UINT32_BE(s, val.u32);
375  Stream_Rewind_UINT32(s);
376  const UINT32 ru = Stream_Get_UINT32_BE(s);
377  Stream_Rewind_UINT32(s);
378  if (val.u32 != ru)
379  goto fail;
380  }
381  {
382  Stream_Write_UINT64(s, val.u64);
383  Stream_Rewind_UINT64(s);
384  const UINT64 ru = Stream_Get_UINT64(s);
385  Stream_Rewind_UINT64(s);
386  if (val.u64 != ru)
387  goto fail;
388  }
389  {
390  Stream_Write_UINT64_BE(s, val.u64);
391  Stream_Rewind_UINT64(s);
392  const UINT64 ru = Stream_Get_UINT64_BE(s);
393  Stream_Rewind_UINT64(s);
394  if (val.u64 != ru)
395  goto fail;
396  }
397  {
398  Stream_Write_INT8(s, val.i8);
399  Stream_Rewind(s, 1);
400  const INT8 ru8 = Stream_Get_INT8(s);
401  Stream_Rewind(s, 1);
402  if (val.i8 != ru8)
403  goto fail;
404  }
405  {
406  Stream_Write_INT16(s, val.i16);
407  Stream_Rewind(s, 2);
408  const INT16 ru = Stream_Get_INT16(s);
409  Stream_Rewind(s, 2);
410  if (val.i16 != ru)
411  goto fail;
412  }
413  {
414  Stream_Write_INT16_BE(s, val.i16);
415  Stream_Rewind(s, 2);
416  const INT16 ru = Stream_Get_INT16_BE(s);
417  Stream_Rewind(s, 2);
418  if (val.i16 != ru)
419  goto fail;
420  }
421  {
422  Stream_Write_INT32(s, val.i32);
423  Stream_Rewind(s, 4);
424  const INT32 ru = Stream_Get_INT32(s);
425  Stream_Rewind(s, 4);
426  if (val.i32 != ru)
427  goto fail;
428  }
429  {
430  Stream_Write_INT32_BE(s, val.i32);
431  Stream_Rewind(s, 4);
432  const INT32 ru = Stream_Get_INT32_BE(s);
433  Stream_Rewind(s, 4);
434  if (val.i32 != ru)
435  goto fail;
436  }
437  {
438  Stream_Write_INT64(s, val.i64);
439  Stream_Rewind(s, 8);
440  const INT64 ru = Stream_Get_INT64(s);
441  Stream_Rewind(s, 8);
442  if (val.i64 != ru)
443  goto fail;
444  }
445  {
446  Stream_Write_INT64_BE(s, val.i64);
447  Stream_Rewind(s, 8);
448  const INT64 ru = Stream_Get_INT64_BE(s);
449  Stream_Rewind(s, 8);
450  if (val.i64 != ru)
451  goto fail;
452  }
453 
454  rc = TRUE;
455 fail:
456  Stream_Free(s, TRUE);
457  return rc;
458 }
459 
460 static BOOL TestStream_Reading(void)
461 {
462  BYTE src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
463  wStream* s = NULL;
464  BOOL result = TRUE;
465 
466  if (!(s = Stream_New(src, sizeof(src))))
467  {
468  printf("%s: Stream_New failed\n", __func__);
469  return FALSE;
470  }
471 
472  TestStream_PeekAndRead(s, result, UINT8);
473  TestStream_PeekAndRead(s, result, INT8);
474  TestStream_PeekAndRead(s, result, UINT16);
475  TestStream_PeekAndRead(s, result, INT16);
476  TestStream_PeekAndRead(s, result, UINT32);
477  TestStream_PeekAndRead(s, result, INT32);
478  TestStream_PeekAndRead(s, result, UINT64);
479  TestStream_PeekAndRead(s, result, INT64);
480  Stream_Free(s, FALSE);
481  return result;
482 }
483 
484 static BOOL TestStream_Write(void)
485 {
486  BOOL rc = FALSE;
487  UINT8 u8 = 0;
488  UINT16 u16 = 0;
489  UINT32 u32 = 0;
490  UINT64 u64 = 0;
491  const BYTE data[] = "someteststreamdata";
492  wStream* s = Stream_New(NULL, 100);
493 
494  if (!s)
495  goto out;
496 
497  if (s->pointer != s->buffer)
498  goto out;
499 
500  Stream_Write(s, data, sizeof(data));
501 
502  if (memcmp(Stream_Buffer(s), data, sizeof(data)) == 0)
503  rc = TRUE;
504 
505  if (s->pointer != s->buffer + sizeof(data))
506  goto out;
507 
508  Stream_SetPosition(s, 0);
509 
510  if (s->pointer != s->buffer)
511  goto out;
512 
513  Stream_Write_UINT8(s, 42);
514 
515  if (s->pointer != s->buffer + 1)
516  goto out;
517 
518  Stream_SetPosition(s, 0);
519 
520  if (s->pointer != s->buffer)
521  goto out;
522 
523  Stream_Peek_UINT8(s, u8);
524 
525  if (u8 != 42)
526  goto out;
527 
528  Stream_Write_UINT16(s, 0x1234);
529 
530  if (s->pointer != s->buffer + 2)
531  goto out;
532 
533  Stream_SetPosition(s, 0);
534 
535  if (s->pointer != s->buffer)
536  goto out;
537 
538  Stream_Peek_UINT16(s, u16);
539 
540  if (u16 != 0x1234)
541  goto out;
542 
543  Stream_Write_UINT32(s, 0x12345678UL);
544 
545  if (s->pointer != s->buffer + 4)
546  goto out;
547 
548  Stream_SetPosition(s, 0);
549 
550  if (s->pointer != s->buffer)
551  goto out;
552 
553  Stream_Peek_UINT32(s, u32);
554 
555  if (u32 != 0x12345678UL)
556  goto out;
557 
558  Stream_Write_UINT64(s, 0x1234567890ABCDEFULL);
559 
560  if (s->pointer != s->buffer + 8)
561  goto out;
562 
563  Stream_SetPosition(s, 0);
564 
565  if (s->pointer != s->buffer)
566  goto out;
567 
568  Stream_Peek_UINT64(s, u64);
569 
570  if (u64 != 0x1234567890ABCDEFULL)
571  goto out;
572 
573 out:
574  Stream_Free(s, TRUE);
575  return rc;
576 }
577 
578 static BOOL TestStream_Seek(void)
579 {
580  BOOL rc = FALSE;
581  wStream* s = Stream_New(NULL, 100);
582 
583  if (!s)
584  goto out;
585 
586  if (s->pointer != s->buffer)
587  goto out;
588 
589  Stream_Seek(s, 5);
590 
591  if (s->pointer != s->buffer + 5)
592  goto out;
593 
594  Stream_Seek_UINT8(s);
595 
596  if (s->pointer != s->buffer + 6)
597  goto out;
598 
599  Stream_Seek_UINT16(s);
600 
601  if (s->pointer != s->buffer + 8)
602  goto out;
603 
604  Stream_Seek_UINT32(s);
605 
606  if (s->pointer != s->buffer + 12)
607  goto out;
608 
609  Stream_Seek_UINT64(s);
610 
611  if (s->pointer != s->buffer + 20)
612  goto out;
613 
614  rc = TRUE;
615 out:
616  Stream_Free(s, TRUE);
617  return rc;
618 }
619 
620 static BOOL TestStream_Rewind(void)
621 {
622  BOOL rc = FALSE;
623  wStream* s = Stream_New(NULL, 100);
624 
625  if (!s)
626  goto out;
627 
628  if (s->pointer != s->buffer)
629  goto out;
630 
631  Stream_Seek(s, 100);
632 
633  if (s->pointer != s->buffer + 100)
634  goto out;
635 
636  Stream_Rewind(s, 10);
637 
638  if (s->pointer != s->buffer + 90)
639  goto out;
640 
641  Stream_Rewind_UINT8(s);
642 
643  if (s->pointer != s->buffer + 89)
644  goto out;
645 
646  Stream_Rewind_UINT16(s);
647 
648  if (s->pointer != s->buffer + 87)
649  goto out;
650 
651  Stream_Rewind_UINT32(s);
652 
653  if (s->pointer != s->buffer + 83)
654  goto out;
655 
656  Stream_Rewind_UINT64(s);
657 
658  if (s->pointer != s->buffer + 75)
659  goto out;
660 
661  rc = TRUE;
662 out:
663  Stream_Free(s, TRUE);
664  return rc;
665 }
666 
667 static BOOL TestStream_Zero(void)
668 {
669  BOOL rc = FALSE;
670  const BYTE data[] = "someteststreamdata";
671  wStream* s = Stream_New(NULL, sizeof(data));
672 
673  if (!s)
674  goto out;
675 
676  Stream_Write(s, data, sizeof(data));
677 
678  if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
679  goto out;
680 
681  Stream_SetPosition(s, 0);
682 
683  if (s->pointer != s->buffer)
684  goto out;
685 
686  Stream_Zero(s, 5);
687 
688  if (s->pointer != s->buffer + 5)
689  goto out;
690 
691  if (memcmp(Stream_ConstPointer(s), data + 5, sizeof(data) - 5) != 0)
692  goto out;
693 
694  Stream_SetPosition(s, 0);
695 
696  if (s->pointer != s->buffer)
697  goto out;
698 
699  for (UINT32 x = 0; x < 5; x++)
700  {
701  UINT8 val = 0;
702  Stream_Read_UINT8(s, val);
703 
704  if (val != 0)
705  goto out;
706  }
707 
708  rc = TRUE;
709 out:
710  Stream_Free(s, TRUE);
711  return rc;
712 }
713 
714 static BOOL TestStream_Fill(void)
715 {
716  BOOL rc = FALSE;
717  const BYTE fill[7] = "XXXXXXX";
718  const BYTE data[] = "someteststreamdata";
719  wStream* s = Stream_New(NULL, sizeof(data));
720 
721  if (!s)
722  goto out;
723 
724  Stream_Write(s, data, sizeof(data));
725 
726  if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
727  goto out;
728 
729  Stream_SetPosition(s, 0);
730 
731  if (s->pointer != s->buffer)
732  goto out;
733 
734  Stream_Fill(s, fill[0], sizeof(fill));
735 
736  if (s->pointer != s->buffer + sizeof(fill))
737  goto out;
738 
739  if (memcmp(Stream_ConstPointer(s), data + sizeof(fill), sizeof(data) - sizeof(fill)) != 0)
740  goto out;
741 
742  Stream_SetPosition(s, 0);
743 
744  if (s->pointer != s->buffer)
745  goto out;
746 
747  if (memcmp(Stream_ConstPointer(s), fill, sizeof(fill)) != 0)
748  goto out;
749 
750  rc = TRUE;
751 out:
752  Stream_Free(s, TRUE);
753  return rc;
754 }
755 
756 static BOOL TestStream_Copy(void)
757 {
758  BOOL rc = FALSE;
759  const BYTE data[] = "someteststreamdata";
760  wStream* s = Stream_New(NULL, sizeof(data));
761  wStream* d = Stream_New(NULL, sizeof(data));
762 
763  if (!s || !d)
764  goto out;
765 
766  if (s->pointer != s->buffer)
767  goto out;
768 
769  Stream_Write(s, data, sizeof(data));
770 
771  if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
772  goto out;
773 
774  if (s->pointer != s->buffer + sizeof(data))
775  goto out;
776 
777  Stream_SetPosition(s, 0);
778 
779  if (s->pointer != s->buffer)
780  goto out;
781 
782  Stream_Copy(s, d, sizeof(data));
783 
784  if (s->pointer != s->buffer + sizeof(data))
785  goto out;
786 
787  if (d->pointer != d->buffer + sizeof(data))
788  goto out;
789 
790  if (Stream_GetPosition(s) != Stream_GetPosition(d))
791  goto out;
792 
793  if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
794  goto out;
795 
796  if (memcmp(Stream_Buffer(d), data, sizeof(data)) != 0)
797  goto out;
798 
799  rc = TRUE;
800 out:
801  Stream_Free(s, TRUE);
802  Stream_Free(d, TRUE);
803  return rc;
804 }
805 
806 int TestStream(int argc, char* argv[])
807 {
808  WINPR_UNUSED(argc);
809  WINPR_UNUSED(argv);
810 
811  if (!TestStream_Create(200, FALSE))
812  return 1;
813 
814  if (!TestStream_Create(200, TRUE))
815  return 2;
816 
817  if (!TestStream_Extent(4096))
818  return 3;
819 
820  if (!TestStream_Reading())
821  return 4;
822 
823  if (!TestStream_New())
824  return 5;
825 
826  if (!TestStream_Write())
827  return 6;
828 
829  if (!TestStream_Seek())
830  return 7;
831 
832  if (!TestStream_Rewind())
833  return 8;
834 
835  if (!TestStream_Zero())
836  return 9;
837 
838  if (!TestStream_Fill())
839  return 10;
840 
841  if (!TestStream_Copy())
842  return 11;
843 
844  if (!TestStream_Static())
845  return 12;
846 
847  if (!TestStream_WriteAndRead(0x1234567890abcdef))
848  return 13;
849 
850  for (size_t x = 0; x < 10; x++)
851  {
852  UINT64 val = 0;
853  winpr_RAND(&val, sizeof(val));
854  if (!TestStream_WriteAndRead(val))
855  return 14;
856  }
857  return 0;
858 }