blob: 1afb9c673f578e331cb2de9cdb8b55a654934c09 [file] [log] [blame]
Elliott Hughes06040fd2013-07-09 13:25:03 -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 <sys/statvfs.h>
20
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24
Elliott Hughes3d305f12013-10-21 19:27:19 -070025#include <string>
26
Elliott Hughes06040fd2013-07-09 13:25:03 -070027TEST(statvfs, statvfs) {
28 struct statvfs sb;
29 memset(&sb, 0, sizeof(sb));
30
Elliott Hughes3d305f12013-10-21 19:27:19 -070031 ASSERT_EQ(0, statvfs("/proc", &sb));
Elliott Hughes06040fd2013-07-09 13:25:03 -070032
Elliott Hughes3d305f12013-10-21 19:27:19 -070033 EXPECT_EQ(4096U, sb.f_bsize);
34 EXPECT_EQ(0U, sb.f_bfree);
35 EXPECT_EQ(0U, sb.f_ffree);
36 EXPECT_EQ(0U, sb.f_fsid);
37 EXPECT_EQ(255U, sb.f_namemax);
Elliott Hughes06040fd2013-07-09 13:25:03 -070038}
39
40TEST(statvfs, fstatvfs) {
41 struct statvfs sb;
42 memset(&sb, 0, sizeof(sb));
43
Elliott Hughes3d305f12013-10-21 19:27:19 -070044 int fd = open("/proc", O_RDONLY);
Elliott Hughes06040fd2013-07-09 13:25:03 -070045 ASSERT_EQ(0, fstatvfs(fd, &sb));
46 close(fd);
Elliott Hughes06040fd2013-07-09 13:25:03 -070047
Elliott Hughes3d305f12013-10-21 19:27:19 -070048 EXPECT_EQ(4096U, sb.f_bsize);
49 EXPECT_EQ(0U, sb.f_bfree);
50 EXPECT_EQ(0U, sb.f_ffree);
51 EXPECT_EQ(0U, sb.f_fsid);
52 EXPECT_EQ(255U, sb.f_namemax);
Elliott Hughes06040fd2013-07-09 13:25:03 -070053}