File: test_TimeValue.cpp

package info (click to toggle)
exiv2 0.27.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 54,956 kB
  • sloc: cpp: 80,713; python: 4,360; sh: 1,497; makefile: 320; javascript: 237; awk: 92; ansic: 78; sed: 16
file content (103 lines) | stat: -rw-r--r-- 3,165 bytes parent folder | download
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
#include "value.hpp"

#include "gtestwrapper.h"

using namespace Exiv2;

TEST(ATimeValue, isDefaultConstructed)
{
    const TimeValue value;
    ASSERT_EQ(0, value.getTime().hour);
    ASSERT_EQ(0, value.getTime().minute);
    ASSERT_EQ(0, value.getTime().second);
    ASSERT_EQ(0, value.getTime().tzHour);
    ASSERT_EQ(0, value.getTime().tzMinute);
}

TEST(ATimeValue, isConstructedWithArgs)
{
    const TimeValue value (23, 55, 2);
    ASSERT_EQ(23, value.getTime().hour);
    ASSERT_EQ(55, value.getTime().minute);
    ASSERT_EQ(2,  value.getTime().second);
    ASSERT_EQ(0, value.getTime().tzHour);
    ASSERT_EQ(0, value.getTime().tzMinute);
}

/// \todo add tests to check what happen with values out of valid ranges

TEST(ATimeValue, canBeReadFromStringHMS)
{
    TimeValue value;
    const std::string hms("23:55:02");
    ASSERT_EQ(0, value.read(hms));
    ASSERT_EQ(23, value.getTime().hour);
    ASSERT_EQ(55, value.getTime().minute);
    ASSERT_EQ(2,  value.getTime().second);
    ASSERT_EQ(0, value.getTime().tzHour);
    ASSERT_EQ(0, value.getTime().tzMinute);
}

TEST(ATimeValue, canBeReadFromWideString)
{
    TimeValue value;
    const std::string hms("23:55:02+04:04");
    ASSERT_EQ(0, value.read(hms));
    ASSERT_EQ(23, value.getTime().hour);
    ASSERT_EQ(55, value.getTime().minute);
    ASSERT_EQ(2,  value.getTime().second);
    ASSERT_EQ(4, value.getTime().tzHour);
    ASSERT_EQ(4, value.getTime().tzMinute);
}

TEST(ATimeValue, canBeReadFromWideStringNegative)
{
    TimeValue value;
    const std::string hms("23:55:02-04:04");
    ASSERT_EQ(0, value.read(hms));
    ASSERT_EQ(23, value.getTime().hour);
    ASSERT_EQ(55, value.getTime().minute);
    ASSERT_EQ(2,  value.getTime().second);
    ASSERT_EQ(-4, value.getTime().tzHour);
    ASSERT_EQ(-4, value.getTime().tzMinute);
}

/// \todo check what we should do here.
TEST(ATimeValue, canBeReadFromWideStringOther)
{
    TimeValue value;
    const std::string hms("23:55:02?04:04");
    ASSERT_EQ(0, value.read(hms));
    ASSERT_EQ(23, value.getTime().hour);
    ASSERT_EQ(55, value.getTime().minute);
    ASSERT_EQ(2,  value.getTime().second);
    ASSERT_EQ(4, value.getTime().tzHour);
    ASSERT_EQ(4, value.getTime().tzMinute);
}

TEST(ATimeValue, cannotReadFromStringWithBadFormat)
{
    TimeValue value;
    ASSERT_EQ(1, value.read("aa:55:02")); // String with non-digit chars
    ASSERT_EQ(1, value.read("25:55:02")); // Hours >= 24
    ASSERT_EQ(1, value.read("23:65:02")); // Minutes >= 60
    ASSERT_EQ(1, value.read("23:55:62")); // Seconds >= 60
    ASSERT_EQ(1, value.read("23:55:02+25:04")); // tzHour >= 24
    ASSERT_EQ(1, value.read("23:55:02+04:66")); // tzMinutes >= 60

    /// \todo This one does not fail
    //ASSERT_EQ(1, value.read("23:55:02+04:06:06")); // More components than expected
}

TEST(ATimeValue, isCopiedToBuffer)
{
    const TimeValue value (23, 55, 2);
    byte buffer[11];
    ASSERT_EQ(11, value.copy(buffer));

    const byte expectedDate[11] = {'2', '3', '5', '5', '0', '2',
                                   '+', '0', '0', '0', '0'};
    for (int i = 0; i < 11; ++i) {
        ASSERT_EQ(expectedDate[i], buffer[i]) << "i: " << i;
    }
}