Added DebugBreak.
[wine] / ipc / bit_array_test.c
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "bit_array.h"
5 #define SIZE (8*sizeof(int)*3)
6
7 static bit_array array;
8 static int simple_array[SIZE];
9 static int bits;
10
11 int are_equal()
12 {
13   int i;
14   for (i=0 ; i < SIZE ; i++)
15      if (SampleBit(&array,i) != simple_array[i]){
16         printf("failed bit %d (packed=%d, simple=%d)\n", i,
17                SampleBit(&array,i), simple_array[i]);
18         return 0;
19      }
20   return 1;
21 }
22
23 int is_same_vacant()
24 {
25   int vacant;
26   for (vacant =0 ; simple_array[vacant]!=0  ; vacant++)
27      if ( vacant >= SIZE) {
28         vacant=-1;
29         break;
30      }
31
32
33   if ( VacantBit(&array) == vacant )
34      return 1;
35   else
36      return 0;
37 }
38 void assign_both(int bit_nr, int bit_val)
39 {
40   int old_bit= simple_array[bit_nr];
41
42   simple_array[bit_nr]= bit_val;
43
44   bits+=bit_val - old_bit;
45
46   assert(AssignBit(&array, bit_nr, bit_val) == old_bit);
47   assert(are_equal());
48   assert(is_same_vacant());
49 }
50
51
52 int main()
53 {
54   unsigned int integers[SIZE >> 5];
55   int i,j;
56
57   assert( AssembleArray(&array, integers, SIZE)
58           == &array);
59   ResetArray(&array);
60   for (i=0 ; i<SIZE ; i++)
61      simple_array[i]=0;
62
63   for (j=5 ; j ; j--) {
64      printf("\rleft %d\r",j);
65
66      for (i=0 ; VacantBit(&array) != -1 ; i++ ) {
67         if (i % 256 == 0) {
68            printf("left %d ",j);
69            printf("%3d up  \r", bits);
70            fflush(stdout);
71         }
72         assign_both(rand() % SIZE,
73                     (rand()% SIZE > bits ) ? 0 : 1 );
74      }
75
76      assign_both(rand() % SIZE, 1);
77
78      for (i=0 ; bits ; i++ ) {
79         if (i % 256 == 0) {
80            printf("left %d ",j);
81            printf("%3d down\r", bits);
82            fflush(stdout);
83         }
84         assign_both(rand() % SIZE,
85                     (rand()% SIZE <= (SIZE-bits) ) ? 0 : 1 );
86      }
87
88      assign_both(rand() % SIZE, 0);
89   }
90
91   putchar('\n');
92   return 0;
93 }