Add Console::hasText() so tests can check if there are errors in the console

This is useful in case that we want to test (e.g.) save/load document
operations that print errors in the console. So checking the console
output (this hasText flag) we can determine if the operation was
completely successful or failed.
This commit is contained in:
David Capello 2017-05-24 14:54:59 -03:00
parent 6f09a826fd
commit b4ea90a266
2 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -34,6 +34,7 @@ static Widget* wid_cancel = NULL;
static int console_counter = 0;
static bool console_locked;
static bool want_close_flag = false;
static bool has_text = false;
Console::Console(Context* ctx)
: m_withUI(false)
@ -42,13 +43,17 @@ Console::Console(Context* ctx)
m_withUI = (ctx->isUIAvailable());
else
m_withUI =
(App::instance()->isGui() &&
(App::instance() &&
App::instance()->isGui() &&
Manager::getDefault() &&
Manager::getDefault()->getDisplay());
if (!m_withUI)
return;
if (console_counter == 0)
has_text = false;
console_counter++;
if (wid_console || console_counter > 1)
return;
@ -104,8 +109,15 @@ Console::~Console()
}
}
bool Console::hasText() const
{
return has_text;
}
void Console::printf(const char* format, ...)
{
has_text = true;
std::va_list ap;
va_start(ap, format);
std::string msg = base::string_vprintf(format, ap);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -18,6 +18,8 @@ namespace app {
Console(Context* ctx = nullptr);
~Console();
bool hasText() const;
void printf(const char *format, ...);
static void showException(const std::exception& e);