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