public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
macournoyer (author)
Mon Apr 07 20:03:33 -0700 2008
commit  05fc8d27d9f6edc6d03c1ba841a2aa04dbbe5205
tree    33acf9ef86577b92451f057c9236bcaef9bb6f1e
parent  993e78f402183c0e58a5f2c9442d8565eaa53268
thin / test / buffer_test.c
100644 85 lines (62 sloc) 1.457 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "test.h"
#include "buffer.h"
 
test_init();
 
void test_buffer_init(void)
{
  pool_t *p = pool_create(10, 512);
  buffer_t b;
  
  buffer_init(&b, p);
  
  assert_equal(p, b.pool);
  assert_equal(1, b.nalloc);
  assert_equal(512, b.salloc);
  
  pool_destroy(p);
}
 
void test_buffer_append(void)
{
  pool_t *p = pool_create(10, 1024);
  buffer_t b;
  
  buffer_init(&b, p);
  
  buffer_append(&b, "hi", 2);
  assert_str_equal("hi", b.ptr);
  
  buffer_append(&b, " you", 4);
  assert_str_equal("hi you", b.ptr);
  assert_equal(6, b.len);
  assert_equal(1, b.nalloc);
  
  pool_destroy(p);
}
 
void test_buffer_grow_and_append(void)
{
  pool_t *p = pool_create(10, 2);
  buffer_t b;
  
  buffer_init(&b, p);
  
  buffer_append(&b, "hi", 2);
  assert_equal(1, b.nalloc);
  assert_equal(2, b.salloc);
  
  buffer_append(&b, " you", 4);
  assert_equal(6, b.len);
  assert_equal(3, b.nalloc);
  assert_equal(6, b.salloc);
 
  buffer_append(&b, " ! ", 3); /* odd num */
  assert_equal(9, b.len);
  assert_equal(4, b.nalloc);
  assert_equal(8, b.salloc);
 
  assert_str_equal("hi you ! ", b.ptr);
  
  pool_destroy(p);
}
 
void test_buffer_free(void)
{
  pool_t *p = pool_create(10, 2);
  buffer_t b;
  
  buffer_init(&b, p);
  buffer_free(&b);
  
  pool_destroy(p);
}
 
int main(int argc, char const *argv[])
{
  test_start();
  
  test_buffer_init();
  test_buffer_append();
  test_buffer_grow_and_append();
  test_buffer_free();
  
  test_end();
}