]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Adapt to the ccache code style
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 31 Dec 2020 18:57:26 +0000 (19:57 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 6 Jan 2021 18:58:05 +0000 (19:58 +0100)
src/TemporaryFile.cpp
src/third_party/CMakeLists.txt
unittest/CMakeLists.txt
unittest/test_bsdmkstemp.cpp

index ca0c8374f1bdbf4f60761032663bc50ff5aefb83..feaa5f18236c1d0cb9c7cd1e57e01ac93e01a1bc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -50,11 +50,12 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
 {
   Util::ensure_dir_exists(Util::dir_name(path));
 #ifdef _WIN32
-  // MSVC lacks mkstemp() and [mingw-w64's implementation][1] is problematic, as
+  // MSVC lacks mkstemp() and Mingw-w64's implementation[1] is problematic, as
   // it can reuse the names of recently-deleted files unless the caller
   // remembers to call srand().
-  // [1]:
-  // https://github.com/Alexpux/mingw-w64/blob/d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-crt/misc/mkstemp.c
+
+  // [1]: <https://github.com/Alexpux/mingw-w64/blob/
+  // d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-crt/misc/mkstemp.c>
   fd = Fd(bsd_mkstemp(&path[0]));
 #else
   fd = Fd(mkstemp(&path[0]));
index 977cff60cc39524ad84839bea663832602675cb6..c361974a4496336a9663d91854f3110459c9e39a 100644 (file)
@@ -6,8 +6,8 @@ else()
   target_compile_definitions(third_party_lib PUBLIC -DSTATIC_GETOPT)
 endif()
 
-if (WIN32)
-    target_sources(third_party_lib PRIVATE win32/mktemp.c)
+if(WIN32)
+  target_sources(third_party_lib PRIVATE win32/mktemp.c)
 endif ()
 
 if(ENABLE_TRACING)
index b29fd653e58923fc54fcf0dcde860a5fd26532b7..65401041a4c0daf15df645a8592e26d25c558120 100644 (file)
@@ -27,9 +27,7 @@ if(INODE_CACHE_SUPPORTED)
 endif()
 
 if(WIN32)
-  list(APPEND source_files
-    test_bsdmkstemp.cpp
-    test_Win32Util.cpp)
+  list(APPEND source_files test_bsdmkstemp.cpp test_Win32Util.cpp)
 endif()
 
 add_executable(unittest ${source_files})
index 0237f5c80d622087226b24fee22f21441cf946d0..021c73d589099880c1f8ad2373250f17dd8ed94a 100644 (file)
@@ -1,4 +1,23 @@
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
 #include "../src/Fd.hpp"
+#include "../src/Finalizer.hpp"
 #include "TestUtil.hpp"
 
 #include "third_party/doctest.h"
@@ -19,7 +38,7 @@ class ScopedHANDLE
 public:
   ScopedHANDLE() = default;
 
-  explicit ScopedHANDLE(HANDLE h) : h_(h)
+  explicit ScopedHANDLE(HANDLE handle) : m_handle(handle)
   {
   }
 
@@ -29,74 +48,68 @@ public:
 
   ~ScopedHANDLE()
   {
-    if (h_ != INVALID_HANDLE_VALUE) {
-      CloseHandle(h_);
+    if (m_handle != INVALID_HANDLE_VALUE) {
+      CloseHandle(m_handle);
     }
   }
 
   ScopedHANDLE&
   operator=(ScopedHANDLE rhs)
   {
-    std::swap(h_, rhs.h_);
+    std::swap(m_handle, rhs.m_handle);
     return *this;
   }
 
   explicit operator bool() const
   {
-    return h_ != INVALID_HANDLE_VALUE;
+    return m_handle != INVALID_HANDLE_VALUE;
   }
 
   HANDLE
   get() const
   {
-    return h_;
+    return m_handle;
   }
 
   HANDLE
   release()
   {
-    HANDLE h = h_;
-    h_ = INVALID_HANDLE_VALUE;
-    return h;
+    HANDLE handle = m_handle;
+    m_handle = INVALID_HANDLE_VALUE;
+    return handle;
   }
 
 private:
-  HANDLE h_ = INVALID_HANDLE_VALUE;
+  HANDLE m_handle = INVALID_HANDLE_VALUE;
 };
 
 } // namespace
 
-TEST_SUITE_BEGIN("thirdparty");
+TEST_SUITE_BEGIN("bsd_mkstemp");
 
-TEST_CASE("thirdparty::bsd_mkstemp")
+TEST_CASE("bsd_mkstemp")
 {
   TestContext test_context;
 
-  static int rand_iter;
+  static uint16_t rand_iter;
   rand_iter = 0;
 
   bsd_mkstemp_set_random_source([](void* buf, size_t nbytes) {
     std::fill_n(
       static_cast<uint16_t*>(buf), nbytes / sizeof(uint16_t), rand_iter);
-    rand_iter++;
+    ++rand_iter;
   });
 
-  struct Cleanup
-  {
-    ~Cleanup()
-    {
-      bsd_mkstemp_set_random_source(nullptr);
-    }
-  } cleanup;
+  Finalizer reset_random_source([] { bsd_mkstemp_set_random_source(nullptr); });
 
   SUBCASE("successful")
   {
-    std::string path("XXXXXX");
+    std::string path = "XXXXXX";
     CHECK_MESSAGE(Fd(bsd_mkstemp(&path[0])), "errno=" << errno);
     CHECK(path == "AAAAAA");
   }
 
-  SUBCASE("existing_file")
+  SUBCASE("existing file")
   {
     CHECK_MESSAGE(ScopedHANDLE(CreateFileA("AAAAAA",
                                            GENERIC_READ | GENERIC_WRITE,
@@ -107,12 +120,12 @@ TEST_CASE("thirdparty::bsd_mkstemp")
                                            nullptr)),
                   "errno=" << errno);
 
-    std::string path("XXXXXX");
+    std::string path = "XXXXXX";
     CHECK_MESSAGE(Fd(bsd_mkstemp(&path[0])), "errno=" << errno);
     CHECK(path == "BBBBBB");
   }
 
-  SUBCASE("existing_file_pending_delete")
+  SUBCASE("existing file, pending delete")
   {
     ScopedHANDLE h;
     CHECK_MESSAGE(
@@ -133,34 +146,34 @@ TEST_CASE("thirdparty::bsd_mkstemp")
                     h.get(), FileDispositionInfo, &info, sizeof(info)),
                   "errno=" << errno);
 
-    std::string path("XXXXXX");
+    std::string path = "XXXXXX";
     CHECK_MESSAGE(Fd(bsd_mkstemp(&path[0])), "errno=" << errno);
     CHECK(path == "BBBBBB");
   }
 
-  SUBCASE("existing_dir")
+  SUBCASE("existing directory")
   {
     CHECK_MESSAGE(CreateDirectoryA("AAAAAA", nullptr), "errno=" << errno);
 
-    std::string path("XXXXXX");
+    std::string path = "XXXXXX";
     CHECK_MESSAGE(Fd(bsd_mkstemp(&path[0])), "errno=" << errno);
     CHECK(path == "BBBBBB");
   }
 
   SUBCASE("permission denied")
   {
-    auto makeACL = [](const char* aclString) {
+    auto make_ACL = [](const char* acl_string) {
       PSECURITY_DESCRIPTOR desc = nullptr;
       ConvertStringSecurityDescriptorToSecurityDescriptorA(
-        aclString, SDDL_REVISION_1, &desc, nullptr);
+        acl_string, SDDL_REVISION_1, &desc, nullptr);
       return std::shared_ptr<SECURITY_DESCRIPTOR>(
         static_cast<SECURITY_DESCRIPTOR*>(desc), &LocalFree);
     };
 
-    // Create a directory with a contrived ACL that denies creation of new
-    // files and directories to the "Everybody" (WD) group.
+    // Create a directory with a contrived ACL that denies creation of new files
+    // and directories to the "Everybody" (WD) group.
     std::shared_ptr<SECURITY_DESCRIPTOR> desc;
-    CHECK_MESSAGE((desc = makeACL("D:(D;;DCLCRPCR;;;WD)(A;;FA;;;WD)")),
+    CHECK_MESSAGE((desc = make_ACL("D:(D;;DCLCRPCR;;;WD)(A;;FA;;;WD)")),
                   "errno=" << errno);
 
     SECURITY_ATTRIBUTES attrs{};
@@ -169,8 +182,8 @@ TEST_CASE("thirdparty::bsd_mkstemp")
     CHECK_MESSAGE(CreateDirectoryA("my_readonly_dir", &attrs),
                   "errno=" << errno);
 
-    // Sanity check that we cannot write to this directory. (E.g. Wine
-    // doesn't appear to emulate Windows ACLs properly when run under root.)
+    // Sanity check that we cannot write to this directory. (E.g. Wine doesn't
+    // appear to emulate Windows ACLs properly when run under root.)
     bool broken_acls = static_cast<bool>(ScopedHANDLE(
       CreateFileA("my_readonly_dir/.writable",
                   GENERIC_WRITE,
@@ -181,7 +194,7 @@ TEST_CASE("thirdparty::bsd_mkstemp")
                   nullptr)));
 
     if (!broken_acls) {
-      std::string path("my_readonly_dir/XXXXXX");
+      std::string path = "my_readonly_dir/XXXXXX";
       CHECK(!Fd(bsd_mkstemp(&path[0])));
       CHECK(errno == EACCES);
     } else {