forked from Exiv2/exiv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_DateValue.cpp
103 lines (88 loc) · 3.12 KB
/
test_DateValue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2004-2021 Exiv2 authors
* This program is part of the Exiv2 distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
*/
#include "value.hpp"
#include <gtest/gtest.h>
using namespace Exiv2;
TEST(ADateValue, isDefaultConstructed)
{
const DateValue dateValue;
ASSERT_EQ(0, dateValue.getDate().year);
ASSERT_EQ(0, dateValue.getDate().month);
ASSERT_EQ(0, dateValue.getDate().day);
}
TEST(ADateValue, isConstructedWithArgs)
{
const DateValue dateValue (2018, 4, 2);
ASSERT_EQ(2018, dateValue.getDate().year);
ASSERT_EQ(4, dateValue.getDate().month);
ASSERT_EQ(2, dateValue.getDate().day);
}
TEST(ADateValue, readFromByteBufferWithExpectedSize)
{
DateValue dateValue;
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x30, 0x32 }; // 20180402
ASSERT_EQ(0, dateValue.read(date, 8));
ASSERT_EQ(2018, dateValue.getDate().year);
ASSERT_EQ(4, dateValue.getDate().month);
ASSERT_EQ(2, dateValue.getDate().day);
}
TEST(ADateValue, doNotReadFromByteBufferWithoutExpectedSize)
{
DateValue dateValue;
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x30, 0x32 }; // 20180402
ASSERT_EQ(1, dateValue.read(date, 9));
}
TEST(ADateValue, doNotReadFromByteBufferWithExpectedSizeButNotCorrectContent)
{
DateValue dateValue;
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x23, 0x23 }; // 201804##
ASSERT_EQ(1, dateValue.read(date, 8));
}
TEST(ADateValue, readFromStringWithExpectedSize)
{
DateValue dateValue;
const std::string date ("2018-04-02");
ASSERT_EQ(0, dateValue.read(date));
ASSERT_EQ(2018, dateValue.getDate().year);
ASSERT_EQ(4, dateValue.getDate().month);
ASSERT_EQ(2, dateValue.getDate().day);
}
TEST(ADateValue, doNotReadFromStringWithoutExpectedSize)
{
DateValue dateValue;
const std::string date ("20180402");
ASSERT_EQ(1, dateValue.read(date));
}
TEST(ADateValue, doNotReadFromStringWithExpectedSizeButNotCorrectContent)
{
DateValue dateValue;
const std::string date ("2018-aa-bb");
ASSERT_EQ(1, dateValue.read(date));
}
TEST(ADateValue, copyToByteBuffer)
{
const DateValue dateValue (2018, 4, 2);
const byte expectedDate[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x30, 0x32 }; // 20180402
byte buffer[8];
ASSERT_EQ(8, dateValue.copy(buffer));
for (int i = 0; i < 8; ++i) {
ASSERT_EQ(expectedDate[i], buffer[i]);
}
}