diff --git a/CMakeLists.txt b/CMakeLists.txt index dd15d29..0e96ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities) set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static) # find c++utilities -find_package(c++utilities 4.0.0 REQUIRED) +find_package(c++utilities 4.8.0 REQUIRED) use_cpp_utilities() # find 3rd party libraries diff --git a/tests/passwordfiletests.cpp b/tests/passwordfiletests.cpp index ac9f542..8ee6f59 100644 --- a/tests/passwordfiletests.cpp +++ b/tests/passwordfiletests.cpp @@ -1,22 +1,22 @@ -#include "../io/passwordfile.h" #include "../io/cryptoexception.h" #include "../io/entry.h" +#include "../io/passwordfile.h" #include -#include #include +#include using namespace std; using namespace Io; +using namespace TestUtilities::Literals; using namespace CPPUNIT_NS; /*! * \brief The PasswordFileTests class tests the Io::PasswordFile class. */ -class PasswordFileTests : public TestFixture -{ +class PasswordFileTests : public TestFixture { CPPUNIT_TEST_SUITE(PasswordFileTests); CPPUNIT_TEST(testReading); #ifdef PLATFORM_UNIX @@ -29,7 +29,8 @@ public: void tearDown(); void testReading(); - void testReading(const string &testfile1path, const string &testfile1password, const string &testfile2, const string &testfile2password, bool testfile2Mod); + void testReading( + const string &testfile1path, const string &testfile1password, const string &testfile2, const string &testfile2password, bool testfile2Mod); #ifdef PLATFORM_UNIX void testWriting(); #endif @@ -38,21 +39,23 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION(PasswordFileTests); void PasswordFileTests::setUp() -{} +{ +} void PasswordFileTests::tearDown() -{} +{ +} /*! * \brief Tests reading the testfiles testfile{1,2}.pwmgr. */ void PasswordFileTests::testReading() { - testReading(TestUtilities::testFilePath("testfile1.pwmgr"), "123456", - TestUtilities::testFilePath("testfile2.pwmgr"), string(), false); + testReading(TestUtilities::testFilePath("testfile1.pwmgr"), "123456", TestUtilities::testFilePath("testfile2.pwmgr"), string(), false); } -void PasswordFileTests::testReading(const string &testfile1path, const string &testfile1password, const string &testfile2, const string &testfile2password, bool testfile2Mod) +void PasswordFileTests::testReading( + const string &testfile1path, const string &testfile1password, const string &testfile2, const string &testfile2password, bool testfile2Mod) { PasswordFile file; @@ -63,7 +66,7 @@ void PasswordFileTests::testReading(const string &testfile1path, const string &t CPPUNIT_ASSERT(file.isEncryptionUsed() == !testfile1password.empty()); // attempt to decrypt using a wrong password file.setPassword(testfile1password + "asdf"); - if(!testfile1password.empty()) { + if (!testfile1password.empty()) { CPPUNIT_ASSERT_THROW(file.load(), CryptoException); } // attempt to decrypt using the correct password @@ -72,7 +75,7 @@ void PasswordFileTests::testReading(const string &testfile1path, const string &t // test root entry const NodeEntry *rootEntry = file.rootEntry(); CPPUNIT_ASSERT_EQUAL("testfile1"s, rootEntry->label()); - CPPUNIT_ASSERT_EQUAL(4ul, rootEntry->children().size()); + CPPUNIT_ASSERT_EQUAL(4_st, rootEntry->children().size()); // test testaccount1 CPPUNIT_ASSERT_EQUAL("testaccount1"s, rootEntry->children()[0]->label()); @@ -80,7 +83,8 @@ void PasswordFileTests::testReading(const string &testfile1path, const string &t CPPUNIT_ASSERT_EQUAL("pin"s, static_cast(rootEntry->children()[0])->fields().at(0).name()); CPPUNIT_ASSERT_EQUAL("123456"s, static_cast(rootEntry->children()[0])->fields().at(0).value()); CPPUNIT_ASSERT(static_cast(rootEntry->children()[0])->fields().at(0).type() == FieldType::Password); - CPPUNIT_ASSERT(static_cast(rootEntry->children()[0])->fields().at(0).tiedAccount() == static_cast(rootEntry->children()[0])); + CPPUNIT_ASSERT( + static_cast(rootEntry->children()[0])->fields().at(0).tiedAccount() == static_cast(rootEntry->children()[0])); CPPUNIT_ASSERT(static_cast(rootEntry->children()[0])->fields().at(1).type() == FieldType::Normal); CPPUNIT_ASSERT_THROW(static_cast(rootEntry->children()[0])->fields().at(2), out_of_range); @@ -108,7 +112,7 @@ void PasswordFileTests::testReading(const string &testfile1path, const string &t file.setPassword(testfile2password); file.load(); rootEntry = file.rootEntry(); - if(testfile2Mod) { + if (testfile2Mod) { CPPUNIT_ASSERT(rootEntry->label() == "testfile2 - modified"); CPPUNIT_ASSERT(rootEntry->children().size() == 2); CPPUNIT_ASSERT(rootEntry->children()[1]->label() == "newAccount"); @@ -147,11 +151,9 @@ void PasswordFileTests::testWriting() file.save(true, false); // check results using the reading test - testReading(testfile1, string(), - testfile2, "654321", true); + testReading(testfile1, string(), testfile2, "654321", true); // check backup files - testReading(testfile1 + ".backup", "123456", - testfile2 + ".backup", string(), false); + testReading(testfile1 + ".backup", "123456", testfile2 + ".backup", string(), false); } #endif