Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #include <grpc/support/useful.h>
35 : #include <grpc/support/port_platform.h>
36 : #include <grpc/support/log.h>
37 : #include "test/core/util/test_config.h"
38 :
39 1 : int main(int argc, char **argv) {
40 : int four[4];
41 : int five[5];
42 1 : gpr_uint32 bitset = 0;
43 1 : grpc_test_init(argc, argv);
44 :
45 : GPR_ASSERT(GPR_MIN(1, 2) == 1);
46 : GPR_ASSERT(GPR_MAX(1, 2) == 2);
47 : GPR_ASSERT(GPR_MIN(2, 1) == 1);
48 : GPR_ASSERT(GPR_MAX(2, 1) == 2);
49 : GPR_ASSERT(GPR_CLAMP(1, 0, 2) == 1);
50 : GPR_ASSERT(GPR_CLAMP(0, 0, 2) == 0);
51 : GPR_ASSERT(GPR_CLAMP(2, 0, 2) == 2);
52 : GPR_ASSERT(GPR_CLAMP(-1, 0, 2) == 0);
53 : GPR_ASSERT(GPR_CLAMP(3, 0, 2) == 2);
54 : GPR_ASSERT(GPR_ROTL((gpr_uint32)0x80000001, 1) == 3);
55 : GPR_ASSERT(GPR_ROTR((gpr_uint32)0x80000001, 1) == 0xc0000000);
56 : GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4);
57 : GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5);
58 :
59 : GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31);
60 : GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1);
61 : GPR_ASSERT(GPR_BITCOUNT(0) == 0);
62 :
63 1 : GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8);
64 1 : GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
65 1 : GPR_ASSERT(GPR_BITGET(bitset, 3) == 1);
66 1 : GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10);
67 1 : GPR_ASSERT(GPR_BITCOUNT(bitset) == 2);
68 1 : GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2);
69 1 : GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
70 1 : GPR_ASSERT(GPR_BITGET(bitset, 3) == 0);
71 :
72 1 : return 0;
73 : }
|