@ -1,6 +1,6 @@
/*
Copyright 2008 by Robert Knight < robertknight @ gmail . com >
Copyright 2013 by Kurt Hindenburg < kurt . hindenburg @ gmail . com >
Copyright 2013 , 2018 by Kurt Hindenburg < kurt . hindenburg @ gmail . com >
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
@ -33,47 +33,92 @@
using namespace Konsole ;
void TerminalCharacterDecoderTest : : init ( )
Character * TerminalCharacterDecoderTest : : convertToCharacter ( QString text , QVector < RenditionFlags > renditions )
{
auto charResult = new Character [ text . size ( ) ] ;
// Force renditions size to match that of text; default will be DEFAULT_RENDITION.
if ( renditions . size ( ) < text . size ( ) ) {
renditions . resize ( text . size ( ) ) ;
}
for ( int i = 0 ; i < text . size ( ) ; + + i ) {
charResult [ i ] = Character ( text . at ( i ) . unicode ( ) ) ;
charResult [ i ] . rendition = renditions . at ( i ) ;
}
return charResult ;
}
void TerminalCharacterDecoderTest : : cleanup ( )
void TerminalCharacterDecoderTest : : testPlainTextDecoder_data ( )
{
QTest : : addColumn < QString > ( " text " ) ;
QTest : : addColumn < QVector < RenditionFlags > > ( " renditions " ) ;
QTest : : addColumn < QString > ( " result " ) ;
/* Notes:
* - rendition has no effect on plain decoded text
*
* TODO : need to add foregroundColor , backgroundColor , and isRealCharacter
*/
QTest : : newRow ( " simple text with default rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( DEFAULT_RENDITION ) < < " hello " ;
QTest : : newRow ( " simple text with bold rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( RE_BOLD ) < < " hello " ;
QTest : : newRow ( " simple text with underline and italic rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( RE_UNDERLINE | RE_ITALIC ) < < " hello " ;
QTest : : newRow ( " simple text with default rendition (shorten) " ) < < " hello " < < QVector < RenditionFlags > ( 4 ) . fill ( DEFAULT_RENDITION ) < < " hello " ;
QTest : : newRow ( " simple text with underline rendition (shorten) " ) < < " hello " < < QVector < RenditionFlags > ( 4 ) . fill ( RE_UNDERLINE ) < < " hello " ;
}
void TerminalCharacterDecoderTest : : testPlainTextDecoder ( )
{
QFETCH ( QString , text ) ;
QFETCH ( QVector < RenditionFlags > , renditions ) ;
QFETCH ( QString , result ) ;
TerminalCharacterDecoder * decoder = new PlainTextDecoder ( ) ;
Character characters [ 6 ] ;
characters [ 0 ] = Character ( ' h ' ) ;
characters [ 1 ] = Character ( ' e ' ) ;
characters [ 2 ] = Character ( ' l ' ) ;
characters [ 3 ] = Character ( ' l ' ) ;
characters [ 4 ] = Character ( ' o ' ) ;
characters [ 5 ] = Character ( ' ' ) ;
characters [ 5 ] . isRealCharacter = false ;
auto testCharacters = convertToCharacter ( text , renditions ) ;
QString outputString ;
QTextStream outputStream ( & outputString ) ;
decoder - > begin ( & outputStream ) ;
decoder - > decodeLine ( characters , 6 , LINE_DEFAULT ) ;
decoder - > decodeLine ( testCharacters , text . size ( ) , /* ignored */ LINE_DEFAULT ) ;
decoder - > end ( ) ;
QCOMPARE ( outputString , QStringLiteral ( " hello " ) ) ;
QCOMPARE ( outputString , result ) ;
delete testCharacters ;
delete decoder ;
}
void TerminalCharacterDecoderTest : : testHTMLFileForValidity ( )
void TerminalCharacterDecoderTest : : testHTMLDecoder_data ( )
{
QString fileName = QStringLiteral ( " konsole.html " ) ;
QFile fi ( fileName ) ;
if ( ! fi . exists ( ) ) {
QSKIP ( " Test html file not found. " ) ;
}
QTest : : addColumn < QString > ( " text " ) ;
QTest : : addColumn < QVector < RenditionFlags > > ( " renditions " ) ;
QTest : : addColumn < QString > ( " result " ) ;
/* Notes:
* TODO : need to add foregroundColor , backgroundColor , and isRealCharacter
*/
QTest : : newRow ( " simple text with default rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( DEFAULT_RENDITION ) < < " <span style= \" font-family:monospace \" ><span style= \" color:#000000;background-color:#ffffff; \" >hello</span><br></span> " ;
QTest : : newRow ( " simple text with bold rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( RE_BOLD ) < < " <span style= \" font-family:monospace \" ><span style= \" font-weight:bold;color:#000000;background-color:#ffffff; \" >hello</span><br></span> " ;
// The below is wrong; only the first rendition is used (eg ignores the |)
QTest : : newRow ( " simple text with underline and italic rendition " ) < < " hello " < < QVector < RenditionFlags > ( 6 ) . fill ( RE_UNDERLINE | RE_ITALIC ) < < " <span style= \" font-family:monospace \" ><span style= \" font-decoration:underline;color:#000000;background-color:#ffffff; \" >hello</span><br></span> " ;
// The below should likely have & replaced by &
QTest : : newRow ( " text with & " ) < < " hello &there " < < QVector < RenditionFlags > ( 6 ) . fill ( DEFAULT_RENDITION ) < < " <span style= \" font-family:monospace \" ><span style= \" color:#000000;background-color:#ffffff; \" >hello &there</span><br></span> " ;
}
QXmlSimpleReader xmlReader ;
QXmlInputSource source ( & fi ) ;
void TerminalCharacterDecoderTest : : testHTMLDecoder ( )
{
QFETCH ( QString , text ) ;
QFETCH ( QVector < RenditionFlags > , renditions ) ;
QFETCH ( QString , result ) ;
QVERIFY ( xmlReader . parse ( & source ) ) ;
TerminalCharacterDecoder * decoder = new HTMLDecoder ( ) ;
auto testCharacters = convertToCharacter ( text , renditions ) ;
QString outputString ;
QTextStream outputStream ( & outputString ) ;
decoder - > begin ( & outputStream ) ;
decoder - > decodeLine ( testCharacters , text . size ( ) , /* ignored */ LINE_DEFAULT ) ;
decoder - > end ( ) ;
QCOMPARE ( outputString , result ) ;
delete testCharacters ;
delete decoder ;
}
QTEST_GUILESS_MAIN ( TerminalCharacterDecoderTest )