~ubuntu-branches/ubuntu/wily/aegisub/wily-proposed

« back to all changes in this revision

Viewing changes to tests/tests/time.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel, Pascal De Vuyst, Juan Picca, Sebastian Reichel
  • Date: 2015-08-04 21:40:50 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150804214050-y2aghm9vdksoc8t7
Tags: 3.2.2+dfsg-1
[ Pascal De Vuyst ]
* Fix Typo in package description (Closes: #739219)

[ Juan Picca ]
* Add patch to fix reproducible build (Closes: #789728)

[ Sebastian Reichel ]
* New upstream release
 - remove vendor directory from orig tarball
* Update Debian Standards Version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
 
2
//
 
3
// Permission to use, copy, modify, and distribute this software for any
 
4
// purpose with or without fee is hereby granted, provided that the above
 
5
// copyright notice and this permission notice appear in all copies.
 
6
//
 
7
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
8
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
9
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
10
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
11
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
12
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
13
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
14
//
 
15
// Aegisub Project http://www.aegisub.org/
 
16
 
 
17
#include <main.h>
 
18
 
 
19
#include <libaegisub/ass/smpte.h>
 
20
#include <libaegisub/ass/time.h>
 
21
 
 
22
using agi::Time;
 
23
 
 
24
TEST(lagi_time, out_of_range_times) {
 
25
        EXPECT_EQ(0, (int)Time(-1));
 
26
        EXPECT_EQ(10 * 60 * 60 * 1000 - 10, (int)Time(10 * 60 * 60 * 1000));
 
27
}
 
28
 
 
29
TEST(lagi_time, rounds_to_cs) {
 
30
        EXPECT_EQ(10, (int)Time(14));
 
31
}
 
32
 
 
33
TEST(lagi_time, cs_formatting) {
 
34
        EXPECT_STREQ("1:23:45.67", Time((((1 * 60) + 23) * 60 + 45) * 1000 + 670).GetAssFormatted().c_str());
 
35
}
 
36
 
 
37
TEST(lagi_time, ms_formatting) {
 
38
        EXPECT_STREQ("1:23:45.678", Time((((1 * 60) + 23) * 60 + 45) * 1000 + 678).GetAssFormatted(true).c_str());
 
39
}
 
40
 
 
41
TEST(lagi_time, well_formed_ass_time_parse) {
 
42
        EXPECT_STREQ("1:23:45.67", Time("1:23:45.67").GetAssFormatted().c_str());
 
43
}
 
44
 
 
45
TEST(lagi_time, missing_components) {
 
46
        EXPECT_STREQ("0:23:45.67", Time("23:45.67").GetAssFormatted().c_str());
 
47
        EXPECT_STREQ("0:00:45.67", Time("45.67").GetAssFormatted().c_str());
 
48
        EXPECT_STREQ("0:00:45.60", Time("45.6").GetAssFormatted().c_str());
 
49
        EXPECT_STREQ("0:00:45.00", Time("45").GetAssFormatted().c_str());
 
50
}
 
51
 
 
52
TEST(lagi_time, out_of_range_compontents) {
 
53
        EXPECT_STREQ("1:23:45.67", Time("0:83:45.67").GetAssFormatted().c_str());
 
54
        EXPECT_STREQ("0:01:40.00", Time("100").GetAssFormatted().c_str());
 
55
}
 
56
 
 
57
TEST(lagi_time, comma_decimal) {
 
58
        EXPECT_STREQ("1:23:45.67", Time("1:23:45,67").GetAssFormatted().c_str());
 
59
}
 
60
 
 
61
TEST(lagi_time, component_getters) {
 
62
        Time t("1:23:45.67");
 
63
        EXPECT_EQ(1, t.GetTimeHours());
 
64
        EXPECT_EQ(23, t.GetTimeMinutes());
 
65
        EXPECT_EQ(45, t.GetTimeSeconds());
 
66
        EXPECT_EQ(67, t.GetTimeCentiseconds());
 
67
        EXPECT_EQ(670, t.GetTimeMiliseconds());
 
68
}
 
69
 
 
70
TEST(lagi_time, srt_time) {
 
71
        EXPECT_STREQ("1:23:45.678", Time("1:23:45,678").GetAssFormatted(true).c_str());
 
72
}
 
73
 
 
74
TEST(lagi_time, smpte_parse_valid) {
 
75
        EXPECT_STREQ("1:23:45.44", agi::SmpteFormatter(25).FromSMPTE("1:23:45:11").GetAssFormatted().c_str());
 
76
}
 
77
 
 
78
TEST(lagi_time, smpte_parse_invalid) {
 
79
        EXPECT_EQ(0, (int)agi::SmpteFormatter(25).FromSMPTE("1:23:45.11"));
 
80
}
 
81
 
 
82
TEST(lagi_time, to_smpte) {
 
83
        EXPECT_STREQ("01:23:45:11", agi::SmpteFormatter(25).ToSMPTE(Time("1:23:45.44")).c_str());
 
84
}