Save txt unittest snapshots in own folder to declutter.

Change-Id: Id51b88ced443c58c5cccdc666fa1d412845a5469
This commit is contained in:
Gary Qian 2017-08-07 10:38:16 -07:00
parent 39f8a13f4d
commit 1046161c3e

View File

@ -15,6 +15,10 @@
*/
#include "render_test.h"
#include <string>
#include "lib/ftl/logging.h"
#include "third_party/skia/include/core/SkImageEncoder.h"
#include "third_party/skia/include/core/SkStream.h"
@ -31,7 +35,8 @@ std::string RenderTest::GetNextSnapshotName() {
::testing::UnitTest::GetInstance()->current_test_info();
std::stringstream stream;
stream << test_info->test_case_name() << "_" << test_info->name();
stream << "snapshots/" << test_info->test_case_name() << "_"
<< test_info->name();
stream << "_" << ++snapshots_ << ".png";
return stream.str();
@ -41,6 +46,22 @@ bool RenderTest::Snapshot() {
if (!canvas_ || !bitmap_) {
return false;
}
std::string snapshot_dir = "snapshots";
int error = 0;
// _WIN32 defined by Windows Visual compiler.
#if defined(_WIN32)
// Handle windows path creation.
error = _mkdir(snapshot_dir.c_str());
#else
// Handle non-windows path creation with Unix permissions.
mode_t permissions = 0733;
error = mkdir(snapshot_dir.c_str(), permissions);
#endif
if (error > 0) {
FTL_LOG(ERROR) << "'snapshot/' Directory not available and could not be "
"created. Please create manually to save snapshot.";
return false;
}
auto file_name = GetNextSnapshotName();
SkFILEWStream file(file_name.c_str());
return SkEncodeImage(&file, *bitmap_, SkEncodedImageFormat::kPNG, 100);