TestCli.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 or (at your option)
  7. * version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef KEEPASSXC_TESTCLI_H
  18. #define KEEPASSXC_TESTCLI_H
  19. #include <QBuffer>
  20. #include <QScopedPointer>
  21. #include <QSharedPointer>
  22. #include <QStringList>
  23. #include <QTest>
  24. #include "util/TemporaryFile.h"
  25. class Command;
  26. class Database;
  27. class TestCli : public QObject
  28. {
  29. Q_OBJECT
  30. private:
  31. QSharedPointer<Database>
  32. readDatabase(const QString& filename = {}, const QString& pw = {}, const QString& keyfile = {});
  33. int execCmd(Command& cmd, const QStringList& args) const;
  34. bool isTotp(const QString& value);
  35. void setInput(const QString& input);
  36. void setInput(const QStringList& input);
  37. private slots:
  38. void initTestCase();
  39. void init();
  40. void cleanup();
  41. void cleanupTestCase();
  42. void testBatchCommands();
  43. void testAdd();
  44. void testAddGroup();
  45. void testAnalyze();
  46. void testClip();
  47. void testCommandParsing_data();
  48. void testCommandParsing();
  49. void testCreate();
  50. void testDiceware();
  51. void testEdit();
  52. void testEstimate_data();
  53. void testEstimate();
  54. void testExport();
  55. void testGenerate_data();
  56. void testGenerate();
  57. void testImport();
  58. void testInfo();
  59. void testKeyFileOption();
  60. void testNoPasswordOption();
  61. void testHelp();
  62. void testInteractiveCommands();
  63. void testList();
  64. void testLocate();
  65. void testMerge();
  66. void testMergeWithKeys();
  67. void testMove();
  68. void testOpen();
  69. void testRemove();
  70. void testRemoveGroup();
  71. void testRemoveQuiet();
  72. void testShow();
  73. void testInvalidDbFiles();
  74. void testYubiKeyOption();
  75. private:
  76. QScopedPointer<QFile> m_devNull;
  77. QScopedPointer<TemporaryFile> m_dbFile;
  78. QScopedPointer<TemporaryFile> m_dbFile2;
  79. QScopedPointer<TemporaryFile> m_dbFileMulti;
  80. QScopedPointer<TemporaryFile> m_xmlFile;
  81. QScopedPointer<TemporaryFile> m_keyFileProtectedDbFile;
  82. QScopedPointer<TemporaryFile> m_keyFileProtectedNoPasswordDbFile;
  83. QScopedPointer<TemporaryFile> m_yubiKeyProtectedDbFile;
  84. QScopedPointer<QBuffer> m_stdout;
  85. QScopedPointer<QBuffer> m_stderr;
  86. QScopedPointer<QBuffer> m_stdin;
  87. };
  88. #endif // KEEPASSXC_TESTCLI_H