FreeRDP
TestBufferPool.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/stream.h>
4 #include <winpr/collections.h>
5 
6 int TestBufferPool(int argc, char* argv[])
7 {
8  DWORD PoolSize = 0;
9  SSIZE_T BufferSize = 0;
10  wBufferPool* pool = NULL;
11  BYTE* Buffers[10] = { 0 };
12  int DefaultSize = 1234;
13 
14  WINPR_UNUSED(argc);
15  WINPR_UNUSED(argv);
16 
17  pool = BufferPool_New(TRUE, -1, 16);
18  if (!pool)
19  return -1;
20 
21  Buffers[0] = BufferPool_Take(pool, DefaultSize);
22  Buffers[1] = BufferPool_Take(pool, DefaultSize);
23  Buffers[2] = BufferPool_Take(pool, 2048);
24  if (!Buffers[0] || !Buffers[1] || !Buffers[2])
25  return -1;
26 
27  BufferSize = BufferPool_GetBufferSize(pool, Buffers[0]);
28 
29  if (BufferSize != DefaultSize)
30  {
31  printf("BufferPool_GetBufferSize failure: Actual: %d Expected: %" PRIu32 "\n", BufferSize,
32  DefaultSize);
33  return -1;
34  }
35 
36  BufferSize = BufferPool_GetBufferSize(pool, Buffers[1]);
37 
38  if (BufferSize != DefaultSize)
39  {
40  printf("BufferPool_GetBufferSize failure: Actual: %d Expected: %" PRIu32 "\n", BufferSize,
41  DefaultSize);
42  return -1;
43  }
44 
45  BufferSize = BufferPool_GetBufferSize(pool, Buffers[2]);
46 
47  if (BufferSize != 2048)
48  {
49  printf("BufferPool_GetBufferSize failure: Actual: %d Expected: 2048\n", BufferSize);
50  return -1;
51  }
52 
53  BufferPool_Return(pool, Buffers[1]);
54 
55  PoolSize = BufferPool_GetPoolSize(pool);
56 
57  if (PoolSize != 2)
58  {
59  printf("BufferPool_GetPoolSize failure: Actual: %" PRIu32 " Expected: 2\n", PoolSize);
60  return -1;
61  }
62 
63  BufferPool_Clear(pool);
64 
65  BufferPool_Free(pool);
66 
67  return 0;
68 }