Skip to content

Commit

Permalink
libcore|Tests: Completed update of libcore tests; additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 2509eaa commit 1fd2560
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 40 deletions.
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/LogEntry
@@ -0,0 +1 @@
#include "core/log.h"
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/core/log.h
Expand Up @@ -487,6 +487,7 @@ class DE_PUBLIC LogEntry : public Lockable, public ISerializable
void setValue(const char *s);
void setValue(const std::string &s);
void setValue(const String &s);
void setValue(const Time &t);
void setValue(const Base &arg);
void setValue(const std::array<char, 4> &typecode);

Expand Down
5 changes: 2 additions & 3 deletions doomsday/libs/core/include/de/data/date.h
Expand Up @@ -67,9 +67,8 @@ class DE_PUBLIC Date : public LogEntry::Arg::Base
Time asTime() const;

// Implements LogEntry::Arg::Base.
LogEntry::Arg::Type logEntryArgType() const {
return LogEntry::Arg::StringArgument;
}
LogEntry::Arg::Type logEntryArgType() const override { return LogEntry::Arg::StringArgument; }
String asText() const override { return format(); }

static Date currentDate();

Expand Down
5 changes: 5 additions & 0 deletions doomsday/libs/core/include/de/data/string.h
Expand Up @@ -32,6 +32,7 @@ namespace de {
template <typename T> struct Range;
class RegExp;
class CString;
class Path;

enum CaseSensitivity { CaseInsensitive, CaseSensitive };

Expand Down Expand Up @@ -341,6 +342,10 @@ class DE_PUBLIC String : public IByteArray

String operator/(const CString &path) const;

String operator/(const char *path) const;

String operator/(const Path &path) const;

/**
* Applies pattern formatting using the string as a format string.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/time.h
Expand Up @@ -179,7 +179,7 @@ class DE_PUBLIC Time : public ISerializable
*
* @param highPerformanceDelta Elapsed time since the high performance timer was started.
*/
Time(Span const &highPerformanceDelta);
static Time fromHighPerformanceDelta(const Span &highPerformanceDelta);

static Time invalidTime();

Expand Down
10 changes: 8 additions & 2 deletions doomsday/libs/core/src/core/log.cpp
Expand Up @@ -170,8 +170,14 @@ void LogEntry::Arg::setValue(const String &s)
{
clear();
_type = StringArgument;
// Ensure a deep copy of the string is taken.
_data.stringValue = new String(s);
_data.stringValue = new String(s); // make a copy
}

void LogEntry::Arg::setValue(const Time &t)
{
clear();
_type = StringArgument;
_data.stringValue = new String(t.asText());
}

void LogEntry::Arg::setValue(const std::array<char, 4> &typecode)
Expand Down
38 changes: 35 additions & 3 deletions doomsday/libs/core/src/core/monospacelogsinkformatter.cpp
Expand Up @@ -277,19 +277,50 @@ StringList MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &entry)
}

// Fill tabs with space.
wstring message =
TabFiller(entry.asText(entryFlags, cutSection)).filled(_minimumIndent).toWideString();
String message = TabFiller(entry.asText(entryFlags, cutSection)).filled(_minimumIndent);

// Remember for the next line.
_sectionOfPreviousLine = section;
_sectionDepthOfPreviousLine = entry.sectionDepth();

// The wrap indentation will be determined dynamically based on the content
// of the line.
dsize wrapIndent = wstring::npos;
dsize wrapIndent = wstring::npos;
dsize nextWrapIndent = wstring::npos;

const String minIndentStr{dsize(_minimumIndent), ' '};

using IndentedLine = std::pair<CString, dsize>;

// Print line by line.
List<IndentedLine> messageLines;
for (const auto &hardLine : message.splitRef('\n'))
{
messageLines << IndentedLine{hardLine, 0};
}

/// @todo Ensure lines don't exceed the configured maximum length.
/// Split messageLines; insert new entries with extra indent where needed.
/// (Carry over indentation from previous log entry?)

for (const auto &messageLine : messageLines)
{
String ln;
if (resultLines)
{
// Lines other than the first one always get the minimum indentation.
ln += minIndentStr;
}
if (messageLine.second > 0)
{
// Additional indentation.
ln += String(messageLine.second, ' ');
}
ln += messageLine.first;
resultLines << ln;
}

#if 0
dsize pos = 0;
while (pos != wstring::npos)
{
Expand Down Expand Up @@ -404,6 +435,7 @@ StringList MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &entry)
pos++; // Skip whitespace.
}
}
#endif

return resultLines;
}
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/core/src/core/textstreamlogsink.cpp
Expand Up @@ -23,7 +23,8 @@ namespace de {
TextStreamLogSink::TextStreamLogSink(std::ostream &ts)
: LogSink(_format), _ts(ts)
{
//_ts->setCodec("UTF-8");
// Keep lines unwrapped.
_format.setMaxLength(10000);
}

TextStreamLogSink::~TextStreamLogSink()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/data/date.cpp
Expand Up @@ -154,7 +154,7 @@ String Date::format(const char *format) const
return buf;
}

std::ostream &operator << (std::ostream &os, const Date &d)
std::ostream &operator<<(std::ostream &os, const Date &d)
{
os << d.asText().c_str();
return os;
Expand Down
11 changes: 11 additions & 0 deletions doomsday/libs/core/src/data/string.cpp
Expand Up @@ -21,6 +21,7 @@
#include "de/String"
#include "de/Block"
#include "de/RegExp"
#include "de/Path"
#include "de/charsymbols.h"

#include <c_plus/path.h>
Expand Down Expand Up @@ -426,6 +427,16 @@ String String::operator/(const CString &path) const
return concatenatePath(String(path));
}

String String::operator/(const char *path) const
{
return concatenatePath(String(path));
}

String String::operator/(const Path &path) const
{
return concatenatePath(path.toString());
}

String String::operator%(const PatternArgs &args) const
{
String result;
Expand Down
16 changes: 10 additions & 6 deletions doomsday/libs/core/src/data/time.cpp
Expand Up @@ -259,6 +259,14 @@ Time::Time(int year, int month, int day, int hour, int minute, int second)
d->flags |= Impl::SysTime;
}

Time Time::fromHighPerformanceDelta(const Span &highPerformanceDelta)
{
Time t = invalidTime();
t.d->flags |= Impl::HighPerformance;
t.d->highPerfElapsed = highPerformanceDelta;
return t;
}

Time::Time(const TimePoint &tp) : d(new Impl(tp))
{}

Expand All @@ -270,10 +278,6 @@ Time::Time(const iTime &time) : d(new Impl(0 /* init as invalid */))
duration_cast<system_clock::duration>(nanoseconds(time.ts.tv_nsec));
}

Time::Time(TimeSpan const &highPerformanceDelta)
: d(new Impl(highPerformanceDelta))
{}

Time Time::invalidTime()
{
return Time(TimePoint());
Expand Down Expand Up @@ -729,15 +733,15 @@ TimeSpan Time::highPerformanceTime() const

Time Time::currentHighPerformanceTime() // static
{
return currentHighPerfDelta;
return fromHighPerformanceDelta(currentHighPerfDelta);
}

void Time::updateCurrentHighPerformanceTime() // static
{
currentHighPerfDelta = highPerfTimer().elapsed();
}

std::ostream &operator << (std::ostream &os, Time const &t)
std::ostream &operator<<(std::ostream &os, Time const &t)
{
return os << t.asText();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/widgets/animation.cpp
Expand Up @@ -400,7 +400,7 @@ void Animation::setClock(Clock const *clock)

TimeSpan Animation::currentTime() // static
{
DE_ASSERT(_clock != 0);
DE_ASSERT(_clock != nullptr);
if (!_clock)
{
throw ClockMissingError("Animation::clock", "Animation has no clock");
Expand Down
10 changes: 4 additions & 6 deletions doomsday/tests/test_archive/main.cpp
Expand Up @@ -26,15 +26,13 @@
#include <de/Writer>
#include <de/FS>

#include <QDebug>

using namespace de;

int main(int argc, char **argv)
{
try
{
TextApp app(argc, argv);
TextApp app(makeList(argc, argv));
app.initSubsystems(App::DisablePlugins);

Block b;
Expand Down Expand Up @@ -86,7 +84,7 @@ int main(int argc, char **argv)
LOGDEV_MSG ("Developer description: %s") << zip2.description();

// Manual reinterpretation can be requested.
DE_ASSERT(zip2.parent() != 0);
DE_ASSERT(zip2.parent() != nullptr);
Folder &updated = zip2.reinterpret()->as<Folder>();
DE_ASSERT(!zip2.parent()); // became a source

Expand Down Expand Up @@ -138,9 +136,9 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
qWarning() << err.asText();
err.warnPlainText();
}

qDebug() << "Exiting main()...";
debug("Exiting main()...");
return 0;
}
4 changes: 2 additions & 2 deletions doomsday/tests/test_bitfield/main.cpp
Expand Up @@ -85,9 +85,9 @@ int main(int, char **)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

cout << "Exiting main()..." << endl;
debug("Exiting main()...");
return 0;
}
4 changes: 2 additions & 2 deletions doomsday/tests/test_commandline/main.cpp
Expand Up @@ -50,8 +50,8 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
std::cerr << err.asText();
err.warnPlainText();
}
std::cout << "Exiting main()...";
debug("Exiting main()...");
return 0;
}
4 changes: 1 addition & 3 deletions doomsday/tests/test_info/main.cpp
Expand Up @@ -37,9 +37,7 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
EscapeParser esc;
esc.parse(err.asText());
warning("%s", esc.plainText().c_str());
err.warnPlainText();
}

debug("Exiting main()...");
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tests/test_log/main.cpp
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
warning(err.asText().c_str());
err.warnPlainText();
}

debug("Exiting main()...");
Expand Down
4 changes: 2 additions & 2 deletions doomsday/tests/test_pointerset/main.cpp
Expand Up @@ -152,9 +152,9 @@ int main(int, char **)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

cout << "Exiting main()...\n";
debug("Exiting main()...");
return 0;
}
2 changes: 1 addition & 1 deletion doomsday/tests/test_record/main.cpp
Expand Up @@ -77,7 +77,7 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

debug("Exiting main()...");
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tests/test_string/main.cpp
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char **argv)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

debug("Exiting main()...");
Expand Down
4 changes: 2 additions & 2 deletions doomsday/tests/test_stringpool/main.cpp
Expand Up @@ -106,9 +106,9 @@ int main(int, char **)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

std::cout << "Exiting main()...\n";
debug("Exiting main()...");
return 0;
}
4 changes: 2 additions & 2 deletions doomsday/tests/test_vectors/main.cpp
Expand Up @@ -148,9 +148,9 @@ int main(int, char **)
}
catch (Error const &err)
{
warning("%s", err.asText().c_str());
err.warnPlainText();
}

cout << "Exiting main()...\n";
debug("Exiting main()...");
return 0;
}

0 comments on commit 1fd2560

Please sign in to comment.