Passwordfile library  3.2.0
C++ library to read/write passwords from/to encrypted files
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>
7 using namespace TestUtilities;
8 
9 #include <cppunit/TestFixture.h>
10 #include <cppunit/extensions/HelperMacros.h>
11 
12 using namespace std;
13 using namespace Io;
14 using namespace TestUtilities::Literals;
15 
16 using namespace CPPUNIT_NS;
17 
21 class FieldTests : public TestFixture {
22  CPPUNIT_TEST_SUITE(FieldTests);
23  CPPUNIT_TEST(testNewFieldCorrectlyInitialized);
24  CPPUNIT_TEST(testMutation);
25  CPPUNIT_TEST_SUITE_END();
26 
27 public:
28  void setUp();
29  void tearDown();
30 
31  void testNewFieldCorrectlyInitialized();
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 }
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
STL namespace.
bool isEmpty() const
Returns an indication whether the entry is empty.
Definition: field.h:51
void setUp()
Definition: fieldtests.cpp:37
void testMutation()
Definition: fieldtests.cpp:62
const std::string & value() const
Returns the value.
Definition: field.h:75
The FieldTests class tests the Io::Field class.
Definition: fieldtests.cpp:21
Contains all IO related classes.
FieldType type() const
Returns the type.
Definition: field.h:91
The Field class holds field information which consists of a name and a value and is able to serialize...
Definition: field.h:15
The exception that is thrown when a parsing error occurs.
Definition: entry.h:151
void testNewFieldCorrectlyInitialized()
Tests whether a new field is correctly initialized (default values set).
Definition: fieldtests.cpp:48
void setType(FieldType type)
Sets the type.
Definition: field.h:99
void tearDown()
Definition: fieldtests.cpp:41
const std::string & name() const
Returns the name.
Definition: field.h:59
CPPUNIT_TEST_SUITE_REGISTRATION(FieldTests)