Passwordfile library 5.0.10
C++ library to read/write passwords from/to encrypted files
Loading...
Searching...
No Matches
fieldtests.cpp
Go to the documentation of this file.
1#include "../io/entry.h"
2#include "../io/field.h"
3
4#include "./utils.h"
5
6#include <c++utilities/tests/testutils.h>
7using namespace CppUtilities;
8
9#include <cppunit/TestFixture.h>
10#include <cppunit/extensions/HelperMacros.h>
11
12using namespace std;
13using namespace Io;
14using namespace CppUtilities::Literals;
15
16using namespace CPPUNIT_NS;
17
21class FieldTests : public TestFixture {
22 CPPUNIT_TEST_SUITE(FieldTests);
24 CPPUNIT_TEST(testMutation);
25 CPPUNIT_TEST_SUITE_END();
26
27public:
28 void setUp() override;
29 void tearDown() override;
30
32 void testMutation();
33};
34
36
38{
39}
40
42{
43}
44
49{
50 AccountEntry account("account");
51 const Field emptyField(&account);
52 CPPUNIT_ASSERT(emptyField.isEmpty());
53
54 const Field field(&account, "foo", "bar");
55 CPPUNIT_ASSERT(!field.isEmpty());
56 CPPUNIT_ASSERT_EQUAL(&account, field.tiedAccount());
57 CPPUNIT_ASSERT_EQUAL("foo"s, field.name());
58 CPPUNIT_ASSERT_EQUAL("bar"s, field.value());
59 CPPUNIT_ASSERT_EQUAL(FieldType::Normal, field.type());
60}
61
63{
64 AccountEntry account("account");
65 Field field(&account, "foo", "bar");
66 field.setName("bar");
67 field.setValue("foo");
68 field.setType(FieldType::Password);
69 CPPUNIT_ASSERT_EQUAL("bar"s, field.name());
70 CPPUNIT_ASSERT_EQUAL("foo"s, field.value());
71 CPPUNIT_ASSERT_EQUAL(FieldType::Password, field.type());
72}
The FieldTests class tests the Io::Field class.
void testMutation()
void testNewFieldCorrectlyInitialized()
Tests whether a new field is correctly initialized (default values set).
void setUp() override
void tearDown() override
The exception that is thrown when a parsing error occurs.
Definition entry.h:170
The Field class holds field information which consists of a name and a value and is able to serialize...
Definition field.h:15
void setName(const std::string &name)
Sets the name.
Definition field.h:67
void setValue(const std::string &value)
Sets the value.
Definition field.h:83
const std::string & name() const
Returns the name.
Definition field.h:59
const std::string & value() const
Returns the value.
Definition field.h:75
void setType(FieldType type)
Sets the type.
Definition field.h:99
bool isEmpty() const
Returns an indication whether the entry is empty.
Definition field.h:51
FieldType type() const
Returns the type.
Definition field.h:91
AccountEntry * tiedAccount() const
Returns the tied account.
Definition field.h:107
CPPUNIT_TEST_SUITE_REGISTRATION(FieldTests)
Contains all IO related classes.