Ticket #44473: kwallettest.patch

File kwallettest.patch, 4.5 KB (added by RJVB (René Bertin), 10 years ago)
  • kdelibs-4.12.5//kdeui/tests/

    old new  
    77# The alternative (which requires Qt>=4.6) is #include <QTestGui>
    88add_definitions(-DQT_GUI_LIB)
    99
     10option(MAC_USE_OSXKEYCHAIN "On OS X, use the keychain as backend for kwallet, instead of kwalletd.")
    1011
    1112MACRO(KDEUI_UNIT_TESTS)
    1213       FOREACH(_testname ${ARGN})
     
    154155  kpixmapsequenceoverlaypaintertest
    155156)
    156157
     158if (Q_WS_MAC AND MAC_USE_OSXKEYCHAIN)
     159  set_source_files_properties(kwallettest.cpp PROPERTIES
     160                               COMPILE_FLAGS -DMAC_USE_OSXKEYCHAIN)
     161endif(Q_WS_MAC AND MAC_USE_OSXKEYCHAIN)
     162
    157163if (NOT KDE_NO_DEPRECATED)
    158164KDEUI_EXECUTABLE_TESTS(
    159165  keditlistboxtest
  • kdelibs-4.12.5/kdeui/tests/

    old new  
    3232
    3333void KWalletTest::testWallet()
    3434{
    35   QString testWallet = "kdewallet";
     35  QString testWallet = "kwallettestWallet";
    3636  QString testFolder = "wallettestfolder";
    3737  QString testKeys[] = { "testKey", "account-302948", "\\", "/abc",
    3838                         "a@b.c" };
    3939  QByteArray testValues[] = { "test", "@(!§\"%&", "", ".test", "\\" };
     40  QMap<QString,QString> pwmap;
    4041  int numTests = 5;
    4142
    4243  // Start kdeinit4, so that the wallet damon is started in the background
     
    4950
    5051  // open
    5152  Wallet *wallet = Wallet::openWallet( testWallet, w->winId(), Wallet::Synchronous );
    52   if ( wallet == 0 )
    53     kDebug() << "Couldn't open the wallet. Maybe the wallet daemon is not running?";
     53  if ( wallet == 0 ){
     54    kWarning() << "Couldn't open the wallet. Maybe the wallet daemon is not running?";
     55  }
     56  else{
     57    kWarning() << "Opened wallet" << wallet->walletName();
     58  }
    5459  QVERIFY( wallet != 0 );
    5560  QVERIFY( Wallet::isOpen( testWallet ) );
     61  kWarning() << "Wallet list:" << Wallet::walletList();
     62
     63  // check on a couple of existing items, preferably at least 1 "internet account" and 1 "application password"
     64  // OSXKeychain::readEntry( "existing name", "existing account", &value, NULL, NULL )
    5665
    5766  // create folder
    5867  wallet->createFolder( testFolder );
    5968  QVERIFY( wallet->hasFolder( testFolder ) );
    6069  wallet->setFolder( testFolder );
     70  kWarning() << "Wallet's folder list:" << wallet->folderList();
    6171  QVERIFY( wallet->currentFolder() == testFolder );
    6272  QVERIFY( wallet->folderList().contains( testFolder ) );
    6373
     
    7080    QVERIFY( readEntry == testValues[i] );
    7181  }
    7282
     83  pwmap[QString("Bugzilla_login")] = QString("bugs@kde.org");
     84  pwmap[QString("Bugzilla_password")] = QString("buggyPassw0rd");
     85  kWarning() << "pwmap=" << pwmap;
     86
     87  QMap<QString,QString> v;
     88  QVERIFY( !wallet->writeMap( "https://bugs.kde.org/#", pwmap ) );
     89  QVERIFY( wallet->hasEntry("https://bugs.kde.org/#") );
     90  QVERIFY( !wallet->readMap( "https://bugs.kde.org/#", v ) );
     91  QVERIFY( v == pwmap );
     92  // do it again
     93  QVERIFY( !wallet->writeMap( "https://bugs.kde.org/#", pwmap ) );
     94  QVERIFY( wallet->hasEntry("https://bugs.kde.org/#") );
     95  QVERIFY( !wallet->readMap( "https://bugs.kde.org/#", v ) );
     96  QVERIFY( v == pwmap );
     97
     98  QVERIFY( wallet->entryType( testKeys[0] ) == Wallet::Stream );
     99  QVERIFY( wallet->entryType( "https://bugs.kde.org/#" ) == Wallet::Map );
     100
     101  QVERIFY( !wallet->renameEntry( "https://bugs.kde.org/#", "kdeBugs" ) );
     102  QVERIFY( wallet->hasEntry("kdeBugs") );
     103  QVERIFY( !wallet->readMap( "kdeBugs", v ) );
     104  QVERIFY( v == pwmap );
     105
    73106  // close
    74107  wallet->sync();
    75   Wallet::closeWallet( "kdewallet", true );
    76   QVERIFY( !Wallet::isOpen( "kdewallet" ) );
     108  QStringList l = wallet->entryList();
     109  kWarning() << "Entry list:" << l;
     110  QVERIFY( l.size() == 6 );
     111  Wallet::closeWallet( testWallet, true );
     112  QVERIFY( !Wallet::isOpen( testWallet ) );
    77113
    78114  // test for key - closed wallet
    79115  for ( int i = 0; i < 5; i++ ) {
     
    108144    QVERIFY( readEntry == testValues[i] );
    109145  }
    110146
     147  // remove those many test keys
     148  for ( int i = 0; i < numTests; i++ ) {
     149    QVERIFY( !wallet->removeEntry( testKeys[i] ) );
     150  }
     151
     152#ifndef MAC_USE_OSXKEYCHAIN
    111153  // delete folder
    112154  wallet->removeFolder( testFolder );
    113155  QVERIFY( !wallet->hasFolder( testFolder ) );
     156#endif
    114157
    115158  // close
    116   Wallet::closeWallet( "kdewallet", true );
    117   QVERIFY( !Wallet::isOpen( "kdewallet" ) );
     159  Wallet::closeWallet( testWallet, true );
     160  QVERIFY( !Wallet::isOpen( testWallet ) );
     161  QVERIFY( !Wallet::deleteWallet( testWallet ) );
    118162}
    119163
    120164QTEST_KDEMAIN(KWalletTest, GUI)