File indexing completed on 2024-05-05 12:12:26

0001 /*
0002     Copyright 2004  Frerich Raabe <raabe@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU General Public License as
0006     published by the Free Software Foundation; either version 2 of
0007     the License, or (at your option) version 3.
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, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #include "kaccelgen.h"
0019 
0020 #include <QStringList>
0021 
0022 #include <iostream>
0023 
0024 using std::cout;
0025 using std::endl;
0026 
0027 void check(const QString &what, const QStringList &expected, const QStringList &received)
0028 {
0029     cout << "Testing " << qPrintable(what) << ": ";
0030     if (expected == received) {
0031         cout << "ok" << endl;
0032     } else {
0033         cout << "ERROR!" << endl;
0034         cout << "Expected: " << qPrintable(expected.join(",")) << endl;
0035         cout << "Received: " << qPrintable(received.join(",")) << endl;
0036     }
0037 }
0038 
0039 int main()
0040 {
0041     QStringList input;
0042     input << "foo" << "bar item" << "&baz" << "bif" << "boz" << "boz 2"
0043           << "yoyo && dyne";
0044 
0045     QStringList expected;
0046     expected << "&foo" << "bar &item" << "&baz" << "bif" << "b&oz" << "boz &2"
0047              << "&yoyo && dyne";
0048 
0049     QStringList output;
0050     KAccelGen::generate(input, output);
0051     check("QStringList value generation", expected, output);
0052 
0053     QMap<QString, QString> map;
0054     for (QStringList::ConstIterator it = input.constBegin(); it != input.constEnd(); ++it) {
0055         map.insert(*it, *it);
0056     }
0057     input.sort();
0058     expected.clear();
0059     KAccelGen::generate(input, expected);
0060 
0061     output.clear();
0062     KAccelGen::generateFromValues(map, output);
0063     check("map value generation", expected, output);
0064 
0065     output.clear();
0066     KAccelGen::generateFromKeys(map, output);
0067     check("map key generation", expected, output);
0068 }