Passwordfile library 5.0.11
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 <cppunit/TestFixture.h>
7#include <cppunit/extensions/HelperMacros.h>
8
9using namespace std;
10using namespace Io;
11using namespace CppUtilities::Literals;
12
13using namespace CPPUNIT_NS;
14
18class FieldTests : public TestFixture {
19 CPPUNIT_TEST_SUITE(FieldTests);
21 CPPUNIT_TEST(testMutation);
22 CPPUNIT_TEST_SUITE_END();
23
24public:
25 void setUp() override;
26 void tearDown() override;
27
29 void testMutation();
30};
31
33
35{
36}
37
39{
40}
41
46{
47 AccountEntry account("account");
48 const Field emptyField(&account);
49 CPPUNIT_ASSERT(emptyField.isEmpty());
50
51 const Field field(&account, "foo", "bar");
52 CPPUNIT_ASSERT(!field.isEmpty());
53 CPPUNIT_ASSERT_EQUAL(&account, field.tiedAccount());
54 CPPUNIT_ASSERT_EQUAL("foo"s, field.name());
55 CPPUNIT_ASSERT_EQUAL("bar"s, field.value());
56 CPPUNIT_ASSERT_EQUAL(FieldType::Normal, field.type());
57}
58
60{
61 AccountEntry account("account");
62 Field field(&account, "foo", "bar");
63 field.setName("bar");
64 field.setValue("foo");
65 field.setType(FieldType::Password);
66 CPPUNIT_ASSERT_EQUAL("bar"s, field.name());
67 CPPUNIT_ASSERT_EQUAL("foo"s, field.value());
68 CPPUNIT_ASSERT_EQUAL(FieldType::Password, field.type());
69}
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.