cpp,tests: Verify that requested keylist mode is used

* lang/cpp/tests/run-getkey.cpp, lang/cpp/tests/run-keylist.cpp (main):
Check used keylist mode.
--

Since Context::setKeyListMode() does not return the error returned by
gpgme, we need to verify explicitly that the keylist mode was set
successfully.

GnuPG-bug-id: 5951
This commit is contained in:
Ingo Klöcker 2022-04-28 10:33:23 +02:00
parent dea872f21f
commit 359906c8bc
2 changed files with 12 additions and 0 deletions

View File

@ -140,6 +140,12 @@ main (int argc, char **argv)
return -1;
}
ctx->setKeyListMode (mode);
if (ctx->keyListMode() != mode) {
// unfortunately, Context::setKeyListMode() does not return the error
// returned by gpgme
std::cerr << "Failed to set keylist mode. You may have used an invalid combination of options.";
return -1;
}
Error err;
const GpgME::Key key = ctx->key (*argv, err, only_secret);
std::stringstream ss;

View File

@ -141,6 +141,12 @@ main (int argc, char **argv)
return -1;
}
ctx->setKeyListMode (mode);
if (ctx->keyListMode() != mode) {
// unfortunately, Context::setKeyListMode() does not return the error
// returned by gpgme
std::cerr << "Failed to set keylist mode. You may have used an invalid combination of options.\n";
return -1;
}
Error err = ctx->startKeyListing (*argv, only_secret);
if (err) {
std::cout << "Error: " << err.asString() << "\n";