45 lines
932 B
C++
45 lines
932 B
C++
#include "dps/fs_utils.hpp"
|
|
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace {
|
|
|
|
std::string utf8_text() {
|
|
return "2_\xE5\x87\x8C\xE4\xBC\x97";
|
|
}
|
|
|
|
int run_test() {
|
|
const fs::path root = fs::temp_directory_path() / "dps-fs-utils-smoke";
|
|
const fs::path nested = root / dps::path_from_utf8(utf8_text());
|
|
const fs::path file = nested / "img.png";
|
|
|
|
fs::remove_all(root);
|
|
fs::create_directories(nested);
|
|
|
|
{
|
|
std::ofstream output(file, std::ios::binary);
|
|
output << "png-data";
|
|
}
|
|
|
|
const std::vector<unsigned char> bytes = dps::read_binary_file(file);
|
|
if (bytes.size() != 8) {
|
|
std::cerr << "unexpected file size: " << bytes.size() << "\n";
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
fs::remove_all(root);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
return run_test();
|
|
}
|