2021-12-25 00:16:06 +08:00
|
|
|
#include "SystemUtil.hpp"
|
|
|
|
|
2018-08-19 07:30:53 +08:00
|
|
|
#include <SFML/System/String.hpp>
|
|
|
|
#include <SFML/System/Time.hpp>
|
2021-12-25 00:16:06 +08:00
|
|
|
|
|
|
|
// Work around GCC 8.x bug with `<filesystem>`.
|
|
|
|
#if !defined(__GNUC__) || (__GNUC__ >= 9)
|
|
|
|
#include <filesystem>
|
|
|
|
#endif // !defined(__GNUC__) || (__GNUC__ >= 9)
|
|
|
|
|
|
|
|
#include <fstream>
|
2018-08-19 07:30:53 +08:00
|
|
|
#include <sstream>
|
2021-12-25 00:16:06 +08:00
|
|
|
#include <cassert>
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
#include <doctest.h>
|
|
|
|
|
|
|
|
namespace sf
|
2018-08-19 07:30:53 +08:00
|
|
|
{
|
2021-12-24 21:31:27 +08:00
|
|
|
doctest::String toString(const sf::String& string)
|
2018-08-19 07:30:53 +08:00
|
|
|
{
|
2021-12-24 21:31:27 +08:00
|
|
|
return string.toAnsiString().c_str();
|
2018-08-19 07:30:53 +08:00
|
|
|
}
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
doctest::String toString(sf::Time time)
|
2018-08-19 07:30:53 +08:00
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << time.asMicroseconds() << "us";
|
2021-12-24 21:31:27 +08:00
|
|
|
return stream.str().c_str();
|
2018-08-19 07:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 00:16:06 +08:00
|
|
|
|
|
|
|
// Work around GCC 8.x bug with `<filesystem>`.
|
|
|
|
#if !defined(__GNUC__) || (__GNUC__ >= 9)
|
|
|
|
namespace sf::Testing
|
|
|
|
{
|
|
|
|
static std::string getTemporaryFilePath()
|
|
|
|
{
|
|
|
|
static int counter = 0;
|
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "sfmltemp" << counter << ".tmp";
|
|
|
|
++counter;
|
|
|
|
|
|
|
|
std::filesystem::path result;
|
|
|
|
result /= std::filesystem::temp_directory_path();
|
|
|
|
result /= oss.str();
|
|
|
|
|
|
|
|
return result.string();
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryFile::TemporaryFile(const std::string& contents)
|
|
|
|
: m_path(getTemporaryFilePath())
|
|
|
|
{
|
|
|
|
std::ofstream ofs(m_path);
|
|
|
|
assert(ofs);
|
|
|
|
|
|
|
|
ofs << contents;
|
|
|
|
assert(ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryFile::~TemporaryFile()
|
|
|
|
{
|
|
|
|
[[maybe_unused]] const bool removed = std::filesystem::remove(m_path);
|
|
|
|
assert(removed);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& TemporaryFile::getPath() const
|
|
|
|
{
|
|
|
|
return m_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !defined(__GNUC__) || (__GNUC__ >= 9)
|