Release 981025.
[wine/gsoc-2012-control.git] / ipc / bit_array_test.c
blob14ecb344615b3fa5337bb5cd11b2cbe963e7a4fe
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "bit_array.h"
5 #define SIZE (8*sizeof(int)*3)
7 static bit_array array;
8 static int simple_array[SIZE];
9 static int bits;
11 int are_equal()
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;
20 return 1;
23 int is_same_vacant()
25 int vacant;
26 for (vacant =0 ; simple_array[vacant]!=0 ; vacant++)
27 if ( vacant >= SIZE) {
28 vacant=-1;
29 break;
33 if ( VacantBit(&array) == vacant )
34 return 1;
35 else
36 return 0;
38 void assign_both(int bit_nr, int bit_val)
40 int old_bit= simple_array[bit_nr];
42 simple_array[bit_nr]= bit_val;
44 bits+=bit_val - old_bit;
46 assert(AssignBit(&array, bit_nr, bit_val) == old_bit);
47 assert(are_equal());
48 assert(is_same_vacant());
52 int main()
54 unsigned int integers[SIZE >> 5];
55 int i,j;
57 assert( AssembleArray(&array, integers, SIZE)
58 == &array);
59 ResetArray(&array);
60 for (i=0 ; i<SIZE ; i++)
61 simple_array[i]=0;
63 for (j=5 ; j ; j--) {
64 printf("\rleft %d\r",j);
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);
72 assign_both(rand() % SIZE,
73 (rand()% SIZE > bits ) ? 0 : 1 );
76 assign_both(rand() % SIZE, 1);
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);
84 assign_both(rand() % SIZE,
85 (rand()% SIZE <= (SIZE-bits) ) ? 0 : 1 );
88 assign_both(rand() % SIZE, 0);
91 putchar('\n');
92 return 0;