diff options
author | Amin Hassani <ahassani@google.com> | 2018-02-22 18:29:36 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-02-22 18:29:36 +0000 |
commit | 434d4560ad8c50a300e5808c9f6a1e3f28e6fa57 (patch) | |
tree | 7fc875b15da5d0b186fec83266314fbccd1e29e4 | |
parent | 2e07496cdf666a8265fbaa4eec33623dc5fffd3d (diff) | |
parent | ea96268b4f6f14f151809e21bcc66f2bf2d8cc16 (diff) | |
download | puffin-434d4560ad8c50a300e5808c9f6a1e3f28e6fa57.tar.gz |
Add MakeTempFile function am: bbcceef51d
am: ea96268b4f
Change-Id: If27565bedcf8f27b707fc2c4976277adbcd1b5a2
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | puffin.gyp | 1 | ||||
-rw-r--r-- | src/patching_unittest.cc | 3 | ||||
-rw-r--r-- | src/unittest_common.cc | 26 | ||||
-rw-r--r-- | src/unittest_common.h | 5 |
5 files changed, 35 insertions, 1 deletions
@@ -98,6 +98,7 @@ cc_test { "src/sample_generator.cc", "src/stream_unittest.cc", "src/testrunner.cc", + "src/unittest_common.cc", "src/utils_unittest.cc", ], shared_libs: [ @@ -171,6 +171,7 @@ 'src/puff_io_unittest.cc', 'src/puffin_unittest.cc', 'src/stream_unittest.cc', + 'src/unittest_common.cc', 'src/utils_unittest.cc', ], }, diff --git a/src/patching_unittest.cc b/src/patching_unittest.cc index d478262..d6327cf 100644 --- a/src/patching_unittest.cc +++ b/src/patching_unittest.cc @@ -30,7 +30,8 @@ void TestPatching(const Buffer& src_buf, const vector<BitExtent>& dst_deflates, const Buffer patch) { Buffer patch_out; - string patch_path = "/tmp/patch.tmp"; + string patch_path; + ASSERT_TRUE(MakeTempFile(&patch_path, nullptr)); ScopedPathUnlinker scoped_unlinker(patch_path); ASSERT_TRUE(PuffDiff(src_buf, dst_buf, src_deflates, dst_deflates, patch_path, &patch_out)); diff --git a/src/unittest_common.cc b/src/unittest_common.cc new file mode 100644 index 0000000..b542740 --- /dev/null +++ b/src/unittest_common.cc @@ -0,0 +1,26 @@ +// Copyright 2018 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "puffin/src/unittest_common.h" + +namespace puffin { + +using std::string; + +bool MakeTempFile(string* filename, int* fd) { + char tmp_template[] = "/tmp/puffin-XXXXXX"; + int mkstemp_fd = mkstemp(tmp_template); + TEST_AND_RETURN_FALSE(mkstemp_fd >= 0); + if (filename) { + *filename = tmp_template; + } + if (fd) { + *fd = mkstemp_fd; + } else { + close(mkstemp_fd); + } + return true; +} + +} // namespace puffin diff --git a/src/unittest_common.h b/src/unittest_common.h index ac1e71c..d0bbb02 100644 --- a/src/unittest_common.h +++ b/src/unittest_common.h @@ -29,6 +29,11 @@ class ScopedPathUnlinker { DISALLOW_COPY_AND_ASSIGN(ScopedPathUnlinker); }; +// Makes a temporary file as /tmp/puffin-XXXXXX. Both |filename| and |fd| are +// optional, but if given, they will be populated with the new temporary file's +// values. +bool MakeTempFile(std::string* filename, int* fd); + // clang-format off // Uncompressed deflate block. const Buffer kRaw1 = {0x01, 0x02, 0x03, 0x04, 0x05}; |