]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add default Stat constructor
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 20 Feb 2020 20:05:56 +0000 (21:05 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 23 Feb 2020 20:11:03 +0000 (21:11 +0100)
src/Stat.hpp
unittest/test_Stat.cpp

index 7eb0251018913a151cea48b620caf419621d886d..19550c20b85268438e5971015dc741899ae9790d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -38,6 +38,10 @@ public:
     throw_error,
   };
 
+  // Create an empty stat result. operator bool() will return false,
+  // error_number() will return -1 and other accessors will return false or 0.
+  Stat();
+
   // Run stat(2).
   //
   // Arguments:
@@ -83,6 +87,10 @@ private:
   int m_errno;
 };
 
+inline Stat::Stat() : m_stat{}, m_errno(-1)
+{
+}
+
 inline Stat
 Stat::stat(const std::string& path, OnError on_error)
 {
index 5345c5047ee82b31ea86cdb8c03d235f0f3efcd5..9f5c6ad16a30eb311111a74dcb4a9883e138e5dc 100644 (file)
 
 using Catch::Equals;
 
-TEST_CASE("Constructor")
+TEST_CASE("Default constructor")
+{
+  Stat stat;
+  CHECK(!stat);
+  CHECK(stat.error_number() == -1);
+  CHECK(stat.device() == 0);
+  CHECK(stat.inode() == 0);
+  CHECK(stat.mode() == 0);
+  CHECK(stat.ctime() == 0);
+  CHECK(stat.mtime() == 0);
+  CHECK(stat.size() == 0);
+  CHECK(stat.size_on_disk() == 0);
+  CHECK(!stat.is_directory());
+  CHECK(!stat.is_regular());
+  CHECK(!stat.is_symlink());
+}
+
+TEST_CASE("Named constructors")
 {
   CHECK(!Stat::stat("does_not_exist"));
   CHECK(!Stat::stat("does_not_exist", Stat::OnError::ignore));