This file is indexed.

/usr/share/doc/root/test/testbits.cxx is in root-system-doc 5.34.14-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * testbits.cxx -- unit tests for the new functionality in the TBits class
 * by Filip Pizlo, 2004
 */

#include "TROOT.h"
#include "TBits.h"

#include <stdlib.h>
#include <stdio.h>

static const char *current_test;
static unsigned test_count;

#define A(exp) do {\
    if (!(exp)) {\
        fprintf(stderr," FAILURE!\n\nIn %s:\n\n",current_test);\
        fprintf(stderr,"Assertion (%s) failed at %s:%d.\n\n",\
                       #exp,__FILE__,__LINE__);\
        exit(1);\
    }\
} while (0)

#define DO_TEST(exp) do {\
    current_test=#exp;\
    fprintf(stderr,".");\
    fflush(stderr);\
    exp;\
    ++test_count;\
} while (0)

static void test_set_bit() {
    TBits b;
    b.SetBitNumber(0);
    A(b.TestBitNumber(0));
}

static const Char_t char_bits[] = {
    0,
    1,
    3,
    7,
    15,
    31,
    63,
    127
};

static const Short_t short_bits[] = {
    0 + 1 * 256,
    3 + 7 * 256,
    15 + 31 * 256,
    63 + 127 * 256
};

static const Int_t int_bits[] = {
    0 + 1 * 256 + 3 * 65536 + 7 * 16777216,
    15 + 31 * 256 + 63 * 65536 + 127 * 16777216
};

static void set_bits_by_char(TBits &bits,
                             UInt_t nbits) {
    bits.Set(nbits, char_bits);
}

static void assert_bits_by_char(const TBits &bits,
                                UInt_t nbits) {
    Char_t buf[8];
    memset(buf,0,sizeof(buf));
    bits.Get(buf);
    for (UInt_t i=0;i<nbits;++i) {
        A((buf[i>>3]&(1<<(i&7))) == (char_bits[i>>3]&(1<<(i&7))));
    }
}

static void set_bits_by_short(TBits &bits,
                              UInt_t nbits) {
    bits.Set(nbits, short_bits);
}

static void assert_bits_by_short(const TBits &bits,
                                 UInt_t nbits) {
    Short_t buf[4];
    memset(buf,0,sizeof(buf));
    bits.Get(buf);
    for (UInt_t i=0;i<nbits;++i) {
        A((buf[i>>4]&(1<<(i&15))) == (short_bits[i>>4]&(1<<(i&15))));
    }
}

static void set_bits_by_int(TBits &bits,
                            UInt_t nbits) {
    bits.Set(nbits, int_bits);
}

static void assert_bits_by_int(const TBits &bits,
                               UInt_t nbits) {
    Int_t buf[2];
    memset(buf,0,sizeof(buf));
    bits.Get(buf);
    for (UInt_t i=0;i<nbits;++i) {
        A((buf[i>>5]&(1<<(i&31))) == (int_bits[i>>5]&(1<<(i&31))));
    }
}

static void set_bits(TBits &bits,
                     UInt_t nbits) {
    UInt_t i,j;
    for (i=0;
         i<8;
         ++i) {
        for (j=i*8;
             j<i*8+i && j<nbits;
             ++j) {
            bits.SetBitNumber(j);
        }
        for (j=i*8+i;
             j<i*8+8 && j<nbits;
             ++j) {
            bits.ResetBitNumber(j);
        }
    }
}

static void assert_bits(const TBits &bits,
                        UInt_t nbits) {
    UInt_t i,j;
    for (i=0;
         i<8;
         ++i) {
        for (j=i*8;
             j<i*8+i && j<nbits;
             ++j) {
            A(bits.TestBitNumber(j));
        }
        for (j=i*8+i;
             j<i*8+8 && j<nbits;
             ++j) {
            A(!bits.TestBitNumber(j));
        }
    }
}

static void test_set_from_char(UInt_t nbits) {
    TBits b;
    set_bits_by_char(b,nbits);
    assert_bits(b,nbits);
}

static void test_set_from_short(UInt_t nbits) {
    TBits b;
    set_bits_by_short(b,nbits);
    assert_bits(b,nbits);
}

static void test_set_from_int(UInt_t nbits) {
    TBits b;
    set_bits_by_int(b,nbits);
    assert_bits(b,nbits);
}

static void test_get_to_char(UInt_t nbits) {
    TBits b;
    set_bits(b,nbits);
    assert_bits_by_char(b,nbits);
}

static void test_get_to_short(UInt_t nbits) {
    TBits b;
    set_bits(b,nbits);
    assert_bits_by_short(b,nbits);
}

static void test_get_to_int(UInt_t nbits) {
    TBits b;
    set_bits(b,nbits);
    assert_bits_by_int(b,nbits);
}

// don't have access to a 64-bit machine at the moment so long test would be
// pointless...

int main(int /*c*/,char **v) {
    TROOT app("bits_test", "Tests the TBits class's new functionality");
    
    fprintf(stderr,"%s: ",v[0]);
    
    DO_TEST(test_set_bit());
    
    DO_TEST(test_set_from_char(64));
    DO_TEST(test_set_from_char(64-1));
    DO_TEST(test_set_from_char(64-7));
    DO_TEST(test_set_from_char(64-8));
    
    DO_TEST(test_set_from_short(64));
    DO_TEST(test_set_from_short(64-1));
    DO_TEST(test_set_from_short(64-7));
    DO_TEST(test_set_from_short(64-8));
    DO_TEST(test_set_from_short(64-15));
    DO_TEST(test_set_from_short(64-16));
    
    DO_TEST(test_set_from_int(64));
    DO_TEST(test_set_from_int(64-1));
    DO_TEST(test_set_from_int(64-7));
    DO_TEST(test_set_from_int(64-8));
    DO_TEST(test_set_from_int(64-15));
    DO_TEST(test_set_from_int(64-16));
    DO_TEST(test_set_from_int(64-23));
    DO_TEST(test_set_from_int(64-24));
    DO_TEST(test_set_from_int(64-31));
    DO_TEST(test_set_from_int(64-32));
    
    DO_TEST(test_get_to_char(64));
    DO_TEST(test_get_to_char(64-1));
    DO_TEST(test_get_to_char(64-7));
    DO_TEST(test_get_to_char(64-8));
    
    DO_TEST(test_get_to_short(64));
    DO_TEST(test_get_to_short(64-1));
    DO_TEST(test_get_to_short(64-7));
    DO_TEST(test_get_to_short(64-8));
    DO_TEST(test_get_to_short(64-15));
    DO_TEST(test_get_to_short(64-16));
    
    DO_TEST(test_get_to_int(64));
    DO_TEST(test_get_to_int(64-1));
    DO_TEST(test_get_to_int(64-7));
    DO_TEST(test_get_to_int(64-8));
    DO_TEST(test_get_to_int(64-15));
    DO_TEST(test_get_to_int(64-16));
    DO_TEST(test_get_to_int(64-23));
    DO_TEST(test_get_to_int(64-24));
    DO_TEST(test_get_to_int(64-31));
    DO_TEST(test_get_to_int(64-32));
    
    fprintf(stderr," OK! (%d tests)\n",test_count);
    
    return 0;
}