2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2015 Google LLC. All rights reserved.
|
2015-12-22 00:33:55 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef MEDIA_FILE_FILE_TEST_UTIL_H_
|
|
|
|
#define MEDIA_FILE_FILE_TEST_UTIL_H_
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
|
|
|
|
2016-09-06 22:13:42 +00:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/file.h>
|
2015-12-22 00:33:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2017-07-10 18:26:22 +00:00
|
|
|
|
|
|
|
#define ASSERT_FILE_EQ(file_name, array) \
|
|
|
|
do { \
|
|
|
|
std::string temp_data; \
|
|
|
|
ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
|
|
|
|
const char* array_ptr = reinterpret_cast<const char*>(array); \
|
2023-12-01 17:32:19 +00:00
|
|
|
ASSERT_EQ(std::string(array_ptr, std::size(array)), temp_data); \
|
2017-06-03 00:05:47 +00:00
|
|
|
} while (false)
|
|
|
|
|
2017-07-10 18:26:22 +00:00
|
|
|
#define ASSERT_FILE_STREQ(file_name, str) \
|
|
|
|
do { \
|
|
|
|
std::string temp_data; \
|
|
|
|
ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
|
|
|
|
ASSERT_EQ(str, temp_data); \
|
2015-12-22 00:33:55 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-09-06 22:13:42 +00:00
|
|
|
#define ASSERT_FILE_ENDS_WITH(file_name, array) \
|
|
|
|
do { \
|
|
|
|
std::string temp_data; \
|
2017-07-10 18:26:22 +00:00
|
|
|
ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \
|
2016-09-06 22:13:42 +00:00
|
|
|
EXPECT_THAT(temp_data, \
|
|
|
|
::testing::EndsWith(std::string( \
|
|
|
|
reinterpret_cast<const char*>(array), sizeof(array)))); \
|
|
|
|
} while (false)
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
// Generate a unique filename.
|
|
|
|
std::string generate_unique_temp_path();
|
|
|
|
void delete_file(const std::string& path);
|
|
|
|
|
|
|
|
// A temporary file that is removed from the filesystem when the object is
|
|
|
|
// destroyed. Useful in tests that use ASSERT to avoid leaving behind temp
|
|
|
|
// files.
|
|
|
|
class TempFile {
|
|
|
|
public:
|
|
|
|
TempFile();
|
|
|
|
~TempFile();
|
|
|
|
|
|
|
|
const std::string& path() const { return path_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string path_;
|
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-12-22 00:33:55 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FILE_FILE_TEST_UTIL_H_
|