1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/support/log.h>
20 #include <grpc/support/port_platform.h>
21
22 #include "src/core/lib/gpr/useful.h"
23 #include "test/core/util/test_config.h"
24
main(int argc,char ** argv)25 int main(int argc, char** argv) {
26 int four[4];
27 int five[5];
28 uint32_t bitset = 0;
29 grpc::testing::TestEnvironment env(argc, argv);
30
31 GPR_ASSERT(GPR_MIN(1, 2) == 1);
32 GPR_ASSERT(GPR_MAX(1, 2) == 2);
33 GPR_ASSERT(GPR_MIN(2, 1) == 1);
34 GPR_ASSERT(GPR_MAX(2, 1) == 2);
35 GPR_ASSERT(GPR_CLAMP(1, 0, 2) == 1);
36 GPR_ASSERT(GPR_CLAMP(0, 0, 2) == 0);
37 GPR_ASSERT(GPR_CLAMP(2, 0, 2) == 2);
38 GPR_ASSERT(GPR_CLAMP(-1, 0, 2) == 0);
39 GPR_ASSERT(GPR_CLAMP(3, 0, 2) == 2);
40 GPR_ASSERT(GPR_ROTL((uint32_t)0x80000001, 1) == 3);
41 GPR_ASSERT(GPR_ROTR((uint32_t)0x80000001, 1) == 0xc0000000);
42 GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4);
43 GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5);
44
45 GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31);
46 GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1);
47 GPR_ASSERT(GPR_BITCOUNT(0) == 0);
48
49 GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8);
50 GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
51 GPR_ASSERT(GPR_BITGET(bitset, 3) == 1);
52 GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10);
53 GPR_ASSERT(GPR_BITCOUNT(bitset) == 2);
54 GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2);
55 GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
56 GPR_ASSERT(GPR_BITGET(bitset, 3) == 0);
57
58 return 0;
59 }
60