blob: 36f01b386e5dfcf3fa4a57d46851d5556525d725 [file] [log] [blame]
Elliott Hughes5b9310e2013-10-02 16:59:05 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <errno.h>
20#include <stdlib.h>
21#include <sys/select.h>
22
23TEST(sys_select, fd_set_smoke) {
24 fd_set fds;
25 FD_ZERO(&fds);
26
27 for (size_t i = 0; i < 1024; ++i) {
28 EXPECT_FALSE(FD_ISSET(i, &fds));
29 }
30
31 FD_SET(0, &fds);
32 EXPECT_TRUE(FD_ISSET(0, &fds));
33 EXPECT_FALSE(FD_ISSET(1, &fds));
34 FD_SET(1, &fds);
35 EXPECT_TRUE(FD_ISSET(0, &fds));
36 EXPECT_TRUE(FD_ISSET(1, &fds));
37 FD_CLR(0, &fds);
38 EXPECT_FALSE(FD_ISSET(0, &fds));
39 EXPECT_TRUE(FD_ISSET(1, &fds));
40 FD_CLR(1, &fds);
41 EXPECT_FALSE(FD_ISSET(0, &fds));
42 EXPECT_FALSE(FD_ISSET(1, &fds));
43}