aboutsummaryrefslogtreecommitdiff
path: root/src/tests/itoheap.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/itoheap.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp
new file mode 100644
index 0000000..67169e7
--- /dev/null
+++ b/src/tests/itoheap.cpp
@@ -0,0 +1,64 @@
1#include <stdio.h>
2#include <stdlib.h>
3
4#include "bu/itoheap.h"
5#include "bu/ito.h"
6
7class Consumer : public Bu::Ito
8{
9public:
10 Consumer()
11 {
12 }
13
14 virtual ~Consumer()
15 {
16 }
17
18 void *run()
19 {
20 for( int j = 0; j < 10; j++ )
21 {
22 printf("Trying to read [%d].\n", j );
23
24 try
25 {
26 int iNum = hInt.dequeue( 0, 500000 );
27 printf("Read %d\n", iNum );
28 }
29 catch( Bu::HeapException &e )
30 {
31 printf("Nothing yet...\n");
32 }
33 }
34
35 return NULL;
36 }
37
38 Bu::ItoHeap<int> hInt;
39};
40
41
42int main()
43{
44 Consumer c;
45
46 for( int j = 0; j < 3; j++ )
47 {
48 int iNum = rand()%10;
49 printf("Enqueuing %d.\n", iNum );
50 c.hInt.enqueue( iNum );
51 }
52
53 printf("Sarting consumer.\n");
54 c.start();
55
56 for( int j = 0; j < 5; j++ )
57 {
58 sleep( 1 );
59 int iNum = rand()%10;
60 printf("Enqueuing %d.\n", iNum );
61 c.hInt.enqueue( iNum );
62 }
63}
64