File indexing completed on 2024-04-14 04:43:08
0001 /*************************************************************************** 0002 * Copyright (c) 2009 Sven Krohlas <sven@asbest-online.de> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0018 ***************************************************************************/ 0019 0020 #include "TestQStringx.h" 0021 0022 #include "core/support/Debug.h" 0023 0024 #include <QTest> 0025 #include <QString> 0026 #include <QMap> 0027 0028 QTEST_GUILESS_MAIN( TestQStringx ) 0029 0030 //required for Debug.h 0031 QMutex Debug::mutex; 0032 0033 TestQStringx::TestQStringx() 0034 { 0035 } 0036 0037 void TestQStringx::testArgs() 0038 { 0039 QStringList testArgs; 0040 0041 m_testString = Amarok::QStringx(""); 0042 QCOMPARE( m_testString.args( testArgs ) , QString( "" ) ); 0043 0044 m_testString = Amarok::QStringx("test"); 0045 QCOMPARE( m_testString.args( testArgs ), QString( "test" ) ); 0046 0047 m_testString = Amarok::QStringx(""); 0048 testArgs.append( "test" ); 0049 QCOMPARE( m_testString.args( testArgs ), QString( "" ) ); 0050 0051 m_testString = Amarok::QStringx("test%12abc"); 0052 QCOMPARE( m_testString.args( testArgs ) , QString( "testtestabc" ) ); 0053 0054 m_testString = Amarok::QStringx("%12test abc"); 0055 QCOMPARE( m_testString.args( testArgs ) , QString( "testtest abc" ) ); 0056 0057 m_testString = Amarok::QStringx("te%st%12abc"); 0058 QCOMPARE( m_testString.args( testArgs ) , QString( "te%sttestabc" ) ); 0059 0060 testArgs.clear(); 0061 testArgs.append( "test" ); 0062 testArgs.append( "abc" ); 0063 m_testString = Amarok::QStringx("test%12abc%2xyz"); 0064 QCOMPARE( m_testString.args( testArgs ) , QString( "testtestabcabcxyz" ) ); 0065 0066 m_testString = Amarok::QStringx("%12test%23abc"); 0067 QCOMPARE( m_testString.args( testArgs ) , QString( "testtestabcabc" ) ); 0068 } 0069 0070 void TestQStringx::testNamedArgs() 0071 { 0072 QMap<QString, QString> testArgs; 0073 0074 m_testString = Amarok::QStringx(""); 0075 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "" ) ); 0076 0077 m_testString = Amarok::QStringx("test"); 0078 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "test" ) ); 0079 0080 testArgs[ "artist" ] = "Pornophonique"; 0081 m_testString = Amarok::QStringx("test"); 0082 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "test" ) ); 0083 0084 m_testString = Amarok::QStringx("artist: %artist%"); 0085 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "artist: Pornophonique" ) ); 0086 0087 m_testString = Amarok::QStringx("artist: %artist% - %album%"); 0088 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "artist: Pornophonique - " ) ); 0089 0090 testArgs[ "album" ] = "8-Bit Lagerfeuer"; 0091 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "artist: Pornophonique - 8-Bit Lagerfeuer" ) ); 0092 0093 m_testString = Amarok::QStringx("%artist%: %artist% - %album%"); 0094 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "Pornophonique: Pornophonique - 8-Bit Lagerfeuer" ) ); 0095 0096 testArgs[ "year" ] = "2007"; 0097 QCOMPARE( m_testString.namedArgs( testArgs ) , QString( "Pornophonique: Pornophonique - 8-Bit Lagerfeuer" ) ); 0098 } 0099 0100 void TestQStringx::testNamedOptArgs() 0101 { 0102 QMap<QString, QString> testArgs; 0103 0104 m_testString = Amarok::QStringx(""); 0105 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0106 0107 m_testString = Amarok::QStringx("test"); 0108 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "test" ) ); 0109 0110 m_testString = Amarok::QStringx("%test%"); 0111 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0112 0113 m_testString = Amarok::QStringx("{ %test% }"); 0114 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0115 0116 m_testString = Amarok::QStringx("test{%test%}"); 0117 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "test" ) ); 0118 0119 m_testString = Amarok::QStringx("{test{%test%}}"); 0120 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "test" ) ); 0121 0122 m_testString = Amarok::QStringx("%test%{%test%}"); 0123 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0124 0125 m_testString = Amarok::QStringx("test%test% "); 0126 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "test " ) ); 0127 0128 testArgs[ "artist" ] = "All:My:Faults"; 0129 m_testString = Amarok::QStringx("%artist%"); 0130 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults" ) ); 0131 0132 m_testString = Amarok::QStringx("{%test% }{%artist%}"); 0133 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults" ) ); 0134 0135 m_testString = Amarok::QStringx("{%test% {%artist%}}"); 0136 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0137 0138 m_testString = Amarok::QStringx("{%artist% {%test%}}"); 0139 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults " ) ); 0140 0141 testArgs[ "track" ] = "Some track"; 0142 m_testString = Amarok::QStringx("{%test% {%artist%}}%track%"); 0143 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "Some track" ) ); 0144 0145 m_testString = Amarok::QStringx("{%artist% {%track%}} %test%"); 0146 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults Some track " ) ); 0147 0148 testArgs[ "test" ] = ""; 0149 m_testString = Amarok::QStringx("{%test%}"); 0150 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0151 0152 m_testString = Amarok::QStringx("before{%test%}"); 0153 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "before" ) ); 0154 0155 m_testString = Amarok::QStringx("{%test%}after"); 0156 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "after" ) ); 0157 0158 m_testString = Amarok::QStringx("before{%test%}after"); 0159 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "beforeafter" ) ); 0160 0161 m_testString = Amarok::QStringx("{%test% }{%artist%}"); 0162 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults" ) ); 0163 0164 m_testString = Amarok::QStringx("{%test% {%artist%}}"); 0165 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "" ) ); 0166 0167 m_testString = Amarok::QStringx("{%artist% {%test%}}"); 0168 QCOMPARE( m_testString.namedOptArgs( testArgs ) , QString( "All:My:Faults " ) ); 0169 0170 m_testString = Amarok::QStringx("[%test2%:test {%artist%}%test%{ [%test%]}]"); 0171 QCOMPARE( m_testString.namedOptArgs( testArgs ), QString( "test All:My:Faults Unknown test" ) ); 0172 }