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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/**
* @file lldateutil_test.cpp
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "../test/lltut.h"
#include "../lldateutil.h"
#include "lldate.h"
#include "llstring.h" // LLStringUtil::format()
#include "lltrans.h"
#include "llui.h"
#include <map>
// Baked-in return values for getString()
std::map< std::string, std::string, std::less<>> gString;
// Baked-in return values for getCountString()
// map of pairs of input xml_desc and integer count
typedef std::pair< std::string, int > count_string_t;
std::map< count_string_t, std::string > gCountString;
std::string LLTrans::getString(const std::string_view xml_desc, const LLStringUtil::format_map_t& args, bool def_string)
{
auto it = gString.find(xml_desc);
if (it != gString.end())
{
std::string text = it->second;
LLStringUtil::format(text, args);
return text;
}
return {};
}
std::string LLTrans::getCountString(std::string_view language, std::string_view xml_desc, S32 count)
{
count_string_t key(xml_desc, count);
if (gCountString.find(key) == gCountString.end())
{
return std::string("Couldn't find ") + static_cast<std::string>(xml_desc);
}
return gCountString[ count_string_t(xml_desc, count) ];
}
std::string LLUI::getLanguage()
{
return "en";
}
namespace tut
{
struct dateutil
{
// Hard-code a "now" date so unit test doesn't change with
// current time. Because server strings are in Pacific time
// roll this forward 8 hours to compensate. This represents
// 2009-12-31T00:00:00Z UTC.
dateutil()
: mNow(std::string("2009-12-31T08:00:00Z"))
{
// copied from strings.xml
gString["YearsMonthsOld"] = "[AGEYEARS] [AGEMONTHS] old";
gString["YearsOld"] = "[AGEYEARS] old";
gString["MonthsOld"] = "[AGEMONTHS] old";
gString["WeeksOld"] = "[AGEWEEKS] old";
gString["DaysOld"] = "[AGEDAYS] old";
gString["TodayOld"] = "Joined today";
gCountString[ count_string_t("AgeYears", 1) ] = "1 year";
gCountString[ count_string_t("AgeYears", 2) ] = "2 years";
gCountString[ count_string_t("AgeMonths", 1) ] = "1 month";
gCountString[ count_string_t("AgeMonths", 2) ] = "2 months";
gCountString[ count_string_t("AgeMonths", 11) ]= "11 months";
gCountString[ count_string_t("AgeWeeks", 1) ] = "1 week";
gCountString[ count_string_t("AgeWeeks", 2) ] = "2 weeks";
gCountString[ count_string_t("AgeWeeks", 3) ] = "3 weeks";
gCountString[ count_string_t("AgeWeeks", 4) ] = "4 weeks";
gCountString[ count_string_t("AgeDays", 1) ] = "1 day";
gCountString[ count_string_t("AgeDays", 2) ] = "2 days";
}
LLDate mNow;
};
typedef test_group<dateutil> dateutil_t;
typedef dateutil_t::object dateutil_object_t;
tut::dateutil_t tut_dateutil("LLDateUtil");
template<> template<>
void dateutil_object_t::test<1>()
{
set_test_name("Years");
ensure_equals("years + months",
LLDateUtil::ageFromDate("10/30/2007", mNow),
"2 years 2 months old" );
ensure_equals("years",
LLDateUtil::ageFromDate("12/31/2007", mNow),
"2 years old" );
ensure_equals("years",
LLDateUtil::ageFromDate("1/1/2008", mNow),
"1 year 11 months old" );
ensure_equals("single year + one month",
LLDateUtil::ageFromDate("11/30/2008", mNow),
"1 year 1 month old" );
ensure_equals("single year + a bit",
LLDateUtil::ageFromDate("12/12/2008", mNow),
"1 year old" );
ensure_equals("single year",
LLDateUtil::ageFromDate("12/31/2008", mNow),
"1 year old" );
}
template<> template<>
void dateutil_object_t::test<2>()
{
set_test_name("Months");
ensure_equals("months",
LLDateUtil::ageFromDate("10/30/2009", mNow),
"2 months old" );
ensure_equals("months 2",
LLDateUtil::ageFromDate("10/31/2009", mNow),
"2 months old" );
ensure_equals("single month",
LLDateUtil::ageFromDate("11/30/2009", mNow),
"1 month old" );
}
template<> template<>
void dateutil_object_t::test<3>()
{
set_test_name("Weeks");
ensure_equals("4 weeks",
LLDateUtil::ageFromDate("12/1/2009", mNow),
"4 weeks old" );
ensure_equals("weeks",
LLDateUtil::ageFromDate("12/17/2009", mNow),
"2 weeks old" );
ensure_equals("single week",
LLDateUtil::ageFromDate("12/24/2009", mNow),
"1 week old" );
}
template<> template<>
void dateutil_object_t::test<4>()
{
set_test_name("Days");
ensure_equals("days",
LLDateUtil::ageFromDate("12/29/2009", mNow),
"2 days old" );
ensure_equals("single day",
LLDateUtil::ageFromDate("12/30/2009", mNow),
"1 day old" );
ensure_equals("today",
LLDateUtil::ageFromDate("12/31/2009", mNow),
"Joined today" );
}
template<> template<>
void dateutil_object_t::test<5>()
{
set_test_name("2010 rollover");
LLDate now(std::string("2010-01-04T12:00:00Z"));
ensure_equals("days",
LLDateUtil::ageFromDate("12/13/2009", now),
"3 weeks old" );
}
//template<> template<>
//void dateutil_object_t::test<6>()
//{
// set_test_name("ISO dates");
// LLDate now(std::string("2010-01-04T12:00:00Z"));
// ensure_equals("days",
// LLDateUtil::ageFromDateISO("2009-12-13", now),
// "3 weeks old" );
//}
}
|