-
Notifications
You must be signed in to change notification settings - Fork 54
/
TestCompatVersionCompare.cpp
159 lines (144 loc) · 5.22 KB
/
TestCompatVersionCompare.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
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
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "gtest/gtest.h"
#include "nsAppRunner.h"
#include "nsString.h"
void CheckCompatVersionCompare(const nsCString& aOldCompatVersion,
const nsCString& aNewCompatVersion,
bool aExpectedSame, bool aExpectedDowngrade) {
printf("Comparing '%s' to '%s'.\n", aOldCompatVersion.get(),
aNewCompatVersion.get());
int32_t result = CompareCompatVersions(aOldCompatVersion, aNewCompatVersion);
ASSERT_EQ(aExpectedSame, result == 0)
<< "Version sameness check should match.";
ASSERT_EQ(aExpectedDowngrade, result > 0)
<< "Version downgrade check should match.";
}
void CheckExpectedResult(const char* aOldAppVersion, const char* aOldAppID,
const char* aOldToolkitID, const char* aNewAppVersion,
const char* aNewAppID, const char* aNewToolkitID,
bool aExpectedSame, bool aExpectedDowngrade) {
nsCString oldCompatVersion;
BuildCompatVersion(aOldAppVersion, aOldAppID, aOldToolkitID,
oldCompatVersion);
nsCString newCompatVersion;
BuildCompatVersion(aNewAppVersion, aNewAppID, aNewToolkitID,
newCompatVersion);
CheckCompatVersionCompare(oldCompatVersion, newCompatVersion, aExpectedSame,
aExpectedDowngrade);
}
// clang-format off
TEST(CompatVersionCompare, CompareVersionChange) {
// Identical
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
true, false);
// Build ID changes
CheckExpectedResult(
"67.0", "20000000000000", "20000000000001",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000001", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000001",
false, false);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000001", "20000000000000",
false, false);
// Version changes
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"68.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"68.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
true, false);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.2", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"67.0.2", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
false, true);
// Unexpected ID formats
CheckExpectedResult(
"67.0.1", "build1", "build1",
"67.0.1", "build2", "build2",
false, false);
CheckExpectedResult(
"67.0.1", "build10", "build10",
"67.0.1", "build2", "build2",
false, true);
CheckExpectedResult(
"67.0.1", "1", "1",
"67.0.1", "10", "10",
false, false);
CheckExpectedResult(
"67.0.1", "10", "10",
"67.0.1", "1", "1",
false, true);
// These support an upgrade case from a normal-style build ID to the one
// we're suggesting Ubuntu use.
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.1", "1build1", "1build1",
false, false);
CheckExpectedResult(
"67.0.1", "1build1", "1build1",
"67.0.1", "20000000000000", "20000000000000",
false, true);
// The actual case from bug 1554029:
CheckExpectedResult(
"67.0", "20190516215225", "20190516215225",
"67.0.5", "20190523030228","20190523030228",
false, false);
CheckExpectedResult(
"67.0.5", "20190523030228", "20190523030228",
"67.0", "20190516215225", "20190516215225",
false, true);
// A newer or equal version should not go on to test the build IDs (bug 1556612).
CheckExpectedResult(
"65.0", "30000000000000", "20000000000000",
"66.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"65.0", "20000000000000", "30000000000000",
"66.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"66.0", "30000000000000", "20000000000000",
"65.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"66.0", "20000000000000", "30000000000000",
"65.0", "20000000000000", "20000000000000",
false, true);
// Check that if the last run was safe mode then we consider this an upgrade.
CheckCompatVersionCompare(
NS_LITERAL_CSTRING("Safe Mode"),
NS_LITERAL_CSTRING("67.0.1_20000000000000/20000000000000"),
false, false);
}
// clang-format on