Passwordfile library
5.0.0
C++ library to read/write passwords from/to encrypted files
tests
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
CppUtilities
;
8
9
#include <cppunit/TestFixture.h>
10
#include <cppunit/extensions/HelperMacros.h>
11
12
using namespace
std;
13
using namespace
Io
;
14
using namespace
CppUtilities::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()
override
;
29
void
tearDown()
override
;
30
31
void
testNewFieldCorrectlyInitialized();
32
void
testMutation();
33
};
34
35
CPPUNIT_TEST_SUITE_REGISTRATION
(
FieldTests
);
36
37
void
FieldTests::setUp
()
38
{
39
}
40
41
void
FieldTests::tearDown
()
42
{
43
}
44
48
void
FieldTests::testNewFieldCorrectlyInitialized
()
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
62
void
FieldTests::testMutation
()
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
}
FieldTests
The FieldTests class tests the Io::Field class.
Definition:
fieldtests.cpp:21
Io::Field::setValue
void setValue(const std::string &value)
Sets the value.
Definition:
field.h:83
FieldTests::tearDown
void tearDown() override
Definition:
fieldtests.cpp:41
Io::Field::value
const std::string & value() const
Returns the value.
Definition:
field.h:75
utils.h
Io::Field::isEmpty
bool isEmpty() const
Returns an indication whether the entry is empty.
Definition:
field.h:51
Io
Contains all IO related classes.
Definition:
cryptoexception.h:9
CppUtilities
Definition:
utils.h:12
Io::Field::setType
void setType(FieldType type)
Sets the type.
Definition:
field.h:99
Io::Field::type
FieldType type() const
Returns the type.
Definition:
field.h:91
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(FieldTests)
Io::Field
The Field class holds field information which consists of a name and a value and is able to serialize...
Definition:
field.h:15
FieldTests::setUp
void setUp() override
Definition:
fieldtests.cpp:37
FieldTests::testMutation
void testMutation()
Definition:
fieldtests.cpp:62
Io::AccountEntry
The exception that is thrown when a parsing error occurs.
Definition:
entry.h:170
Io::Field::name
const std::string & name() const
Returns the name.
Definition:
field.h:59
Io::Field::setName
void setName(const std::string &name)
Sets the name.
Definition:
field.h:67
FieldTests::testNewFieldCorrectlyInitialized
void testNewFieldCorrectlyInitialized()
Tests whether a new field is correctly initialized (default values set).
Definition:
fieldtests.cpp:48
Generated on Thu Aug 22 2019 13:42:02 for Passwordfile library by
1.8.16