Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2014 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/vfs.h>
     20 
     21 #include <sys/types.h>
     22 #include <sys/stat.h>
     23 #include <fcntl.h>
     24 
     25 #include <string>
     26 
     27 template <typename StatFsT> void Check(StatFsT& sb) {
     28   EXPECT_EQ(4096, static_cast<int>(sb.f_bsize));
     29   EXPECT_EQ(0U, sb.f_bfree);
     30   EXPECT_EQ(0U, sb.f_ffree);
     31   EXPECT_EQ(0, sb.f_fsid.__val[0]);
     32   EXPECT_EQ(0, sb.f_fsid.__val[1]);
     33   EXPECT_EQ(255, static_cast<int>(sb.f_namelen));
     34 }
     35 
     36 TEST(sys_vfs, statfs) {
     37   struct statfs sb;
     38   ASSERT_EQ(0, statfs("/proc", &sb));
     39   Check(sb);
     40 }
     41 
     42 TEST(sys_vfs, statfs64) {
     43   struct statfs64 sb;
     44   ASSERT_EQ(0, statfs64("/proc", &sb));
     45   Check(sb);
     46 }
     47 
     48 TEST(sys_vfs, fstatfs) {
     49   struct statfs sb;
     50   int fd = open("/proc", O_RDONLY);
     51   ASSERT_EQ(0, fstatfs(fd, &sb));
     52   close(fd);
     53   Check(sb);
     54 }
     55 TEST(sys_vfs, fstatfs64) {
     56   struct statfs64 sb;
     57   int fd = open("/proc", O_RDONLY);
     58   ASSERT_EQ(0, fstatfs64(fd, &sb));
     59   close(fd);
     60   Check(sb);
     61 }
     62