Shaka Packager SDK
Loading...
Searching...
No Matches
file_test_util.h
1// Copyright 2015 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef MEDIA_FILE_FILE_TEST_UTIL_H_
8#define MEDIA_FILE_FILE_TEST_UTIL_H_
9
10#include <iterator>
11#include <string>
12
13#include <gmock/gmock.h>
14#include <gtest/gtest.h>
15
16#include <packager/file.h>
17
18namespace shaka {
19
20#define ASSERT_FILE_EQ(file_name, array) \
21 do { \
22 std::string temp_data; \
23 ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
24 const char* array_ptr = reinterpret_cast<const char*>(array); \
25 ASSERT_EQ(std::string(array_ptr, std::size(array)), temp_data); \
26 } while (false)
27
28#define ASSERT_FILE_STREQ(file_name, str) \
29 do { \
30 std::string temp_data; \
31 ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
32 ASSERT_EQ(str, temp_data); \
33 } while (false)
34
35#define ASSERT_FILE_ENDS_WITH(file_name, array) \
36 do { \
37 std::string temp_data; \
38 ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
39 EXPECT_THAT(temp_data, \
40 ::testing::EndsWith(std::string( \
41 reinterpret_cast<const char*>(array), sizeof(array)))); \
42 } while (false)
43
44// Generate a unique filename.
45std::string generate_unique_temp_path();
46void delete_file(const std::string& path);
47
48// A temporary file that is removed from the filesystem when the object is
49// destroyed. Useful in tests that use ASSERT to avoid leaving behind temp
50// files.
51class TempFile {
52 public:
53 TempFile();
54 ~TempFile();
55
56 const std::string& path() const { return path_; }
57
58 private:
59 std::string path_;
60};
61
62} // namespace shaka
63
64#endif // MEDIA_FILE_FILE_TEST_UTIL_H_
All the methods that are virtual are virtual for mocking.