• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef SRC_UNITTEST_COMMON_H_
6 #define SRC_UNITTEST_COMMON_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "puffin/src/include/puffin/common.h"
12 #include "puffin/src/logging.h"
13 
14 namespace puffin {
15 
16 // Utility class to delete a file when it goes out of scope.
17 class ScopedPathUnlinker {
18  public:
ScopedPathUnlinker(const std::string & path)19   explicit ScopedPathUnlinker(const std::string& path) : path_(path) {}
~ScopedPathUnlinker()20   ~ScopedPathUnlinker() {
21     if (unlink(path_.c_str()) < 0) {
22       LOG(ERROR) << "Failed to unlink: " << path_;
23     }
24   }
25 
26  private:
27   const std::string path_;
28 
29   DISALLOW_COPY_AND_ASSIGN(ScopedPathUnlinker);
30 };
31 
32 // Makes a temporary file as /tmp/puffin-XXXXXX. Both |filename| and |fd| are
33 // optional, but if given, they will be populated with the new temporary file's
34 // values.
35 bool MakeTempFile(std::string* filename, int* fd);
36 
37 extern const Buffer kDeflatesSample1;
38 extern const Buffer kPuffsSample1;
39 extern const std::vector<ByteExtent> kDeflateExtentsSample1;
40 extern const std::vector<BitExtent> kSubblockDeflateExtentsSample1;
41 extern const std::vector<ByteExtent> kPuffExtentsSample1;
42 
43 extern const Buffer kDeflatesSample2;
44 extern const Buffer kPuffsSample2;
45 extern const std::vector<ByteExtent> kDeflateExtentsSample2;
46 extern const std::vector<BitExtent> kSubblockDeflateExtentsSample2;
47 extern const std::vector<ByteExtent> kPuffExtentsSample2;
48 
49 extern const Buffer kProblematicCache;
50 extern const std::vector<BitExtent> kProblematicCacheDeflateExtents;
51 extern const std::vector<BitExtent> kProblematicCachePuffExtents;
52 
53 }  // namespace puffin
54 
55 #endif  // SRC_UNITTEST_COMMON_H_
56