blob: 6b19e13b8b5627f51a2235e178e0eabf1b51c23a [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 Hughesdb1ea342014-01-17 18:42:49 -080027template <typename StatVfsT> void Check(StatVfsT& sb) {
Elliott Hughes3d305f12013-10-21 19:27:19 -070028 EXPECT_EQ(4096U, sb.f_bsize);
29 EXPECT_EQ(0U, sb.f_bfree);
30 EXPECT_EQ(0U, sb.f_ffree);
31 EXPECT_EQ(0U, sb.f_fsid);
32 EXPECT_EQ(255U, sb.f_namemax);
Elliott Hughes06040fd2013-07-09 13:25:03 -070033}
34
Elliott Hughesdb1ea342014-01-17 18:42:49 -080035TEST(sys_statvfs, statvfs) {
Elliott Hughes06040fd2013-07-09 13:25:03 -070036 struct statvfs sb;
Elliott Hughesdb1ea342014-01-17 18:42:49 -080037 ASSERT_EQ(0, statvfs("/proc", &sb));
38 Check(sb);
39}
Elliott Hughes06040fd2013-07-09 13:25:03 -070040
Elliott Hughesdb1ea342014-01-17 18:42:49 -080041TEST(sys_statvfs, statvfs64) {
42 struct statvfs64 sb;
43 ASSERT_EQ(0, statvfs64("/proc", &sb));
44 Check(sb);
45}
46
47TEST(sys_statvfs, fstatvfs) {
48 struct statvfs sb;
Elliott Hughes3d305f12013-10-21 19:27:19 -070049 int fd = open("/proc", O_RDONLY);
Elliott Hughes06040fd2013-07-09 13:25:03 -070050 ASSERT_EQ(0, fstatvfs(fd, &sb));
51 close(fd);
Elliott Hughesdb1ea342014-01-17 18:42:49 -080052 Check(sb);
53}
54TEST(sys_statvfs, fstatvfs64) {
55 struct statvfs64 sb;
56 int fd = open("/proc", O_RDONLY);
57 ASSERT_EQ(0, fstatvfs64(fd, &sb));
58 close(fd);
59 Check(sb);
Elliott Hughes06040fd2013-07-09 13:25:03 -070060}