Skip to content

Commit

Permalink
Tests: Added a test for string pattern format
Browse files Browse the repository at this point in the history
Demonstrates all the format features of String::patternFormat()
(and therefore String::operator %()).
  • Loading branch information
skyjake committed Mar 22, 2013
1 parent ce33ba0 commit ae5bf84
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
66 changes: 66 additions & 0 deletions doomsday/tests/string/main.cpp
@@ -0,0 +1,66 @@
/*
* The Doomsday Engine Project
*
* Copyright (c) 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <de/TextApp>
#include <de/math.h>
#include <QDebug>

using namespace de;

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

LOG_MSG("Escaped %%: arg %i") << 1;
LOG_MSG("Escaped %%: arg %%%i%%") << 1;
//LOG_MSG("Error: %") << 1; // incomplete formatting
//LOG_MSG("Error: %i %i") << 1; // ran out of arguments

LOG_MSG("String: '%s'") << "Hello World";
LOG_MSG(" Min width 8: '%8s'") << "Hello World";
LOG_MSG(" Max width .8: '%.8s'") << "Hello World";
LOG_MSG(" Left align: '%-.8s'") << "Hello World";
LOG_MSG("String: '%s'") << "Hello";
LOG_MSG(" Min width 8: '%8s'") << "Hello";
LOG_MSG(" Max width .8: '%.8s'") << "Hello";
LOG_MSG(" Left align: '%-8s'") << "Hello";

LOG_MSG("Integer (64-bit signed): %i") << 0x1000000000;
LOG_MSG("Integer (64-bit signed): %d") << 0x1000000000;
LOG_MSG("Integer (64-bit unsigned): %u") << 0x123456789abc;
LOG_MSG("Boolean: %b %b") << true << false;
LOG_MSG("16-bit Unicode character: %c") << 0x44;
LOG_MSG("Hexadecimal (64-bit): %x") << 0x123456789abc;
LOG_MSG("Hexadecimal (64-bit): %X") << 0x123456789abc;
LOG_MSG("Pointer: %p") << &app;
LOG_MSG("Double precision floating point: %f") << PI;
LOG_MSG("Decimal places .4: %.4f") << PI;
LOG_MSG("Decimal places .10: %.10f") << PI;
}
catch(Error const &err)
{
qWarning() << err.asText() << "\n";
}

qDebug() << "Exiting main()...\n";
return 0;
}
8 changes: 8 additions & 0 deletions doomsday/tests/string/string.pro
@@ -0,0 +1,8 @@
include(../config_test.pri)

TEMPLATE = app
TARGET = test_string

SOURCES += main.cpp

deployTest($$TARGET)
1 change: 1 addition & 0 deletions doomsday/tests/tests.pro
Expand Up @@ -10,6 +10,7 @@ deng_tests: SUBDIRS += \
log \
record \
script \
string \
stringpool \
vectors
#basiclink

0 comments on commit ae5bf84

Please sign in to comment.