qt: Fix tofuinfo test when gpg is gpg2

* lang/qt/tests/t-support.cpp (QGpgMETest::copyKeyrings): New helper.
* lang/qt/tests/t-support.h: Declare.
* lang/qt/tests/t-encrypt.cpp: use it
* lang/qt/tests/t-tofuinbo.cpp: ditto.

--
New helper takes care of copying the correct files for either
keybox or keyring.
This commit is contained in:
Andre Heinecke 2016-08-25 15:20:02 +02:00
parent f08904b810
commit 053e6e0a7b
4 changed files with 30 additions and 10 deletions

View File

@ -242,11 +242,7 @@ public Q_SLOT:
Q_ASSERT(agentConf.open(QIODevice::WriteOnly)); Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry"); agentConf.write("allow-loopback-pinentry");
agentConf.close(); agentConf.close();
Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/pubring.gpg"), copyKeyrings(gpgHome, mDir.path());
mDir.path() + QStringLiteral("/pubring.gpg")));
Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/secring.gpg"),
mDir.path() + QStringLiteral("/secring.gpg")));
} }
private: private:

View File

@ -45,6 +45,31 @@ void QGpgMETest::cleanupTestCase()
killAgent(); killAgent();
} }
bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest)
{
bool is21dir = QFileInfo(src + QDir::separator() + QStringLiteral("pubring.kbx")).exists();
const QString name = is21dir ? QStringLiteral("pubring.kbx") :
QStringLiteral("pubring.gpg");
if (!QFile::copy(src + name, dest + QDir::separator() + name)) {
return false;
}
if (!is21dir) {
return (QFile::copy(src + QDir::separator() + QStringLiteral("secring.gpg"),
dest + QDir::separator() + QStringLiteral("secring.gpg")));
}
QDir dir (src + QDir::separator() + QStringLiteral("private-keys-v1.d"));
QDir target(dest);
if (!target.mkdir("private-keys-v1.d")) {
return false;
}
foreach (QString f, dir.entryList(QDir::Files)) {
if (!QFile::copy(src + QDir::separator() + f, dest + QDir::separator() + f)) {
return false;
}
}
return true;
}
void killAgent(const QString& dir) void killAgent(const QString& dir)
{ {
QProcess proc; QProcess proc;
@ -59,4 +84,5 @@ void killAgent(const QString& dir)
proc.waitForFinished(); proc.waitForFinished();
} }
#include "t-support.hmoc" #include "t-support.hmoc"

View File

@ -55,6 +55,8 @@ void killAgent(const QString &dir = qgetenv("GNUPGHOME"));
class QGpgMETest : public QObject class QGpgMETest : public QObject
{ {
Q_OBJECT Q_OBJECT
protected:
bool copyKeyrings(const QString &from, const QString& to);
public Q_SLOTS: public Q_SLOTS:
void initTestCase(); void initTestCase();

View File

@ -239,11 +239,7 @@ private Q_SLOTS:
Q_ASSERT(agentConf.open(QIODevice::WriteOnly)); Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry"); agentConf.write("allow-loopback-pinentry");
agentConf.close(); agentConf.close();
Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/pubring.gpg"), copyKeyrings(gpgHome, mDir.path());
mDir.path() + QStringLiteral("/pubring.gpg")));
Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/secring.gpg"),
mDir.path() + QStringLiteral("/secring.gpg")));
} }
private: private:
QTemporaryDir mDir; QTemporaryDir mDir;