2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "addons/AddonVersion.h"
11 #include <gtest/gtest.h>
13 using namespace ADDON
;
15 class TestAddonVersion
: public testing::Test
28 e1_v1_0_0_r1("1:1.0.0-1"),
29 e1_v1_0_1_r1("1:1.0.1-1"),
30 e1_v1_0_0_r2("1:1.0.0-2"),
31 v1_0_0_beta("1.0.0~beta"),
32 v1_0_0_alpha("1.0.0~alpha"),
33 v1_0_0_alpha2("1.0.0~alpha2"),
34 v1_0_0_alpha3("1.0.0~alpha3"),
35 v1_0_0_alpha10("1.0.0~alpha10")
45 CAddonVersion e1_v1_0_0
;
46 CAddonVersion e1_v1_0_1
;
47 CAddonVersion e2_v1_0_0
;
48 CAddonVersion e1_v1_0_0_r1
;
49 CAddonVersion e1_v1_0_1_r1
;
50 CAddonVersion e1_v1_0_0_r2
;
51 CAddonVersion v1_0_0_beta
;
52 CAddonVersion v1_0_0_alpha
;
53 CAddonVersion v1_0_0_alpha2
;
54 CAddonVersion v1_0_0_alpha3
;
55 CAddonVersion v1_0_0_alpha10
;
58 TEST_F(TestAddonVersion
, Constructor
)
60 EXPECT_EQ(v1_0
.Upstream(), "1.0");
61 EXPECT_EQ(v1_0
.Epoch(), 0);
62 EXPECT_TRUE(v1_0
.Revision().empty());
64 EXPECT_EQ(v1_00
.Upstream(), "1.00");
65 EXPECT_EQ(v1_00
.Epoch(), 0);
66 EXPECT_TRUE(v1_00
.Revision().empty());
68 EXPECT_EQ(v1_0_0
.Upstream(), "1.0.0");
69 EXPECT_EQ(v1_0_0
.Epoch(), 0);
70 EXPECT_TRUE(v1_0_0
.Revision().empty());
72 EXPECT_EQ(v1_1
.Upstream(), "1.1");
73 EXPECT_EQ(v1_1
.Epoch(), 0);
74 EXPECT_TRUE(v1_1
.Revision().empty());
76 EXPECT_EQ(v1_01
.Upstream(), "1.01");
77 EXPECT_EQ(v1_01
.Epoch(), 0);
78 EXPECT_TRUE(v1_01
.Revision().empty());
80 EXPECT_EQ(v1_0_1
.Upstream(), "1.0.1");
81 EXPECT_EQ(v1_0_1
.Epoch(), 0);
82 EXPECT_TRUE(v1_0_1
.Revision().empty());
84 EXPECT_EQ(e1_v1_0_0
.Upstream(), "1.0.0");
85 EXPECT_EQ(e1_v1_0_0
.Epoch(), 1);
86 EXPECT_TRUE(e1_v1_0_0
.Revision().empty());
88 EXPECT_EQ(e1_v1_0_1
.Upstream(), "1.0.1");
89 EXPECT_EQ(e1_v1_0_1
.Epoch(), 1);
90 EXPECT_TRUE(e1_v1_0_1
.Revision().empty());
92 EXPECT_EQ(e2_v1_0_0
.Upstream(), "1.0.0");
93 EXPECT_EQ(e2_v1_0_0
.Epoch(), 2);
94 EXPECT_TRUE(e2_v1_0_0
.Revision().empty());
96 EXPECT_EQ(e1_v1_0_0_r1
.Upstream(), "1.0.0");
97 EXPECT_EQ(e1_v1_0_0_r1
.Epoch(), 1);
98 EXPECT_EQ(e1_v1_0_0_r1
.Revision(), "1");
100 EXPECT_EQ(e1_v1_0_1_r1
.Upstream(), "1.0.1");
101 EXPECT_EQ(e1_v1_0_1_r1
.Epoch(), 1);
102 EXPECT_EQ(e1_v1_0_1_r1
.Revision(), "1");
104 EXPECT_EQ(e1_v1_0_0_r2
.Upstream(), "1.0.0");
105 EXPECT_EQ(e1_v1_0_0_r2
.Epoch(), 1);
106 EXPECT_EQ(e1_v1_0_0_r2
.Revision(), "2");
108 EXPECT_EQ(v1_0_0_beta
.Upstream(), "1.0.0~beta");
109 EXPECT_EQ(v1_0_0_beta
.Epoch(), 0);
110 EXPECT_TRUE(v1_0_0_beta
.Revision().empty());
112 EXPECT_EQ(v1_0_0_alpha
.Upstream(), "1.0.0~alpha");
113 EXPECT_EQ(v1_0_0_alpha
.Epoch(), 0);
114 EXPECT_TRUE(v1_0_0_alpha
.Revision().empty());
116 EXPECT_EQ(v1_0_0_alpha2
.Upstream(), "1.0.0~alpha2");
117 EXPECT_EQ(v1_0_0_alpha2
.Epoch(), 0);
118 EXPECT_TRUE(v1_0_0_alpha2
.Revision().empty());
120 EXPECT_EQ(v1_0_0_alpha3
.Upstream(), "1.0.0~alpha3");
121 EXPECT_EQ(v1_0_0_alpha3
.Epoch(), 0);
122 EXPECT_TRUE(v1_0_0_alpha3
.Revision().empty());
124 EXPECT_EQ(v1_0_0_alpha10
.Upstream(), "1.0.0~alpha10");
125 EXPECT_EQ(v1_0_0_alpha10
.Epoch(), 0);
126 EXPECT_TRUE(v1_0_0_alpha10
.Revision().empty());
129 TEST_F(TestAddonVersion
, asString
)
131 EXPECT_EQ(v1_0
.asString(), "1.0");
132 EXPECT_EQ(v1_00
.asString(), "1.00");
133 EXPECT_EQ(v1_0_0
.asString(), "1.0.0");
134 EXPECT_EQ(v1_1
.asString(), "1.1");
135 EXPECT_EQ(v1_01
.asString(), "1.01");
136 EXPECT_EQ(v1_0_1
.asString(), "1.0.1");
137 EXPECT_EQ(e1_v1_0_0
.asString(), "1:1.0.0");
138 EXPECT_EQ(e1_v1_0_1
.asString(), "1:1.0.1");
139 EXPECT_EQ(e2_v1_0_0
.asString(), "2:1.0.0");
140 EXPECT_EQ(e1_v1_0_0_r1
.asString(), "1:1.0.0-1");
141 EXPECT_EQ(e1_v1_0_1_r1
.asString(), "1:1.0.1-1");
142 EXPECT_EQ(e1_v1_0_0_r2
.asString(), "1:1.0.0-2");
143 EXPECT_EQ(v1_0_0_beta
.asString(), "1.0.0~beta");
144 EXPECT_EQ(v1_0_0_alpha
.asString(), "1.0.0~alpha");
145 EXPECT_EQ(v1_0_0_alpha2
.asString(), "1.0.0~alpha2");
146 EXPECT_EQ(v1_0_0_alpha3
.asString(), "1.0.0~alpha3");
147 EXPECT_EQ(v1_0_0_alpha10
.asString(), "1.0.0~alpha10");
150 TEST_F(TestAddonVersion
, Equals
)
152 EXPECT_EQ(v1_0
, CAddonVersion("1.0"));
153 EXPECT_EQ(v1_00
, CAddonVersion("1.00"));
154 EXPECT_EQ(v1_0_0
, CAddonVersion("1.0.0"));
155 EXPECT_EQ(v1_1
, CAddonVersion("1.1"));
156 EXPECT_EQ(v1_01
, CAddonVersion("1.01"));
157 EXPECT_EQ(v1_0_1
, CAddonVersion("1.0.1"));
158 EXPECT_EQ(e1_v1_0_0
, CAddonVersion("1:1.0.0"));
159 EXPECT_EQ(e1_v1_0_1
, CAddonVersion("1:1.0.1"));
160 EXPECT_EQ(e2_v1_0_0
, CAddonVersion("2:1.0.0"));
161 EXPECT_EQ(e1_v1_0_0_r1
, CAddonVersion("1:1.0.0-1"));
162 EXPECT_EQ(e1_v1_0_1_r1
, CAddonVersion("1:1.0.1-1"));
163 EXPECT_EQ(e1_v1_0_0_r2
, CAddonVersion("1:1.0.0-2"));
164 EXPECT_EQ(v1_0_0_beta
, CAddonVersion("1.0.0~beta"));
165 EXPECT_EQ(v1_0_0_alpha
, CAddonVersion("1.0.0~alpha"));
166 EXPECT_EQ(v1_0_0_alpha2
, CAddonVersion("1.0.0~alpha2"));
167 EXPECT_EQ(v1_0_0_alpha3
, CAddonVersion("1.0.0~alpha3"));
168 EXPECT_EQ(v1_0_0_alpha10
, CAddonVersion("1.0.0~alpha10"));
171 TEST_F(TestAddonVersion
, LessThan
)
173 EXPECT_LT(v1_0
, v1_0_0
);
174 EXPECT_LT(v1_0
, v1_1
);
175 EXPECT_LT(v1_0
, v1_01
);
176 EXPECT_LT(v1_0
, v1_0_1
);
178 EXPECT_LT(v1_00
, v1_0_0
);
179 EXPECT_LT(v1_00
, v1_1
);
180 EXPECT_LT(v1_00
, v1_01
);
181 EXPECT_LT(v1_00
, v1_0_1
);
183 EXPECT_LT(v1_0_0
, v1_1
);
184 EXPECT_LT(v1_0_0
, v1_01
);
185 EXPECT_LT(v1_0_0
, v1_0_1
);
187 EXPECT_LT(v1_0_1
, v1_01
);
188 EXPECT_LT(v1_0_1
, v1_1
);
191 EXPECT_LT(v1_0_0
, e1_v1_0_0
);
192 EXPECT_LT(v1_0_0
, e1_v1_0_1
);
193 EXPECT_LT(v1_0_0
, e2_v1_0_0
);
194 EXPECT_LT(v1_0_1
, e1_v1_0_1
);
195 EXPECT_LT(v1_0_1
, e2_v1_0_0
);
197 EXPECT_LT(e1_v1_0_0
, e1_v1_0_1
);
198 EXPECT_LT(e1_v1_0_0
, e2_v1_0_0
);
199 EXPECT_LT(e1_v1_0_1
, e2_v1_0_0
);
202 EXPECT_LT(e1_v1_0_0
, e1_v1_0_0_r1
);
203 EXPECT_LT(e1_v1_0_0
, e1_v1_0_1_r1
);
204 EXPECT_LT(e1_v1_0_0
, e1_v1_0_0_r2
);
205 EXPECT_LT(e1_v1_0_1
, e1_v1_0_1_r1
);
206 EXPECT_LT(e1_v1_0_0_r1
, e1_v1_0_1
);
207 EXPECT_LT(e1_v1_0_0_r1
, e1_v1_0_1_r1
);
208 EXPECT_LT(e1_v1_0_0_r1
, e1_v1_0_0_r2
);
209 EXPECT_LT(e1_v1_0_0_r2
, e1_v1_0_1
);
210 EXPECT_LT(e1_v1_0_0_r2
, e1_v1_0_1_r1
);
211 EXPECT_LT(e1_v1_0_1_r1
, e2_v1_0_0
);
214 EXPECT_LT(v1_0_0_beta
, v1_0_0
);
215 EXPECT_LT(v1_0_0_alpha
, v1_0_0
);
216 EXPECT_LT(v1_0_0_alpha
, v1_0_0_beta
);
217 EXPECT_LT(v1_0_0_alpha
, v1_0_0_alpha2
);
218 EXPECT_LT(v1_0_0_alpha
, v1_0_0_alpha3
);
219 EXPECT_LT(v1_0_0_alpha
, v1_0_0_alpha10
);
220 EXPECT_LT(v1_0_0_alpha2
, v1_0_0
);
221 EXPECT_LT(v1_0_0_alpha2
, v1_0_0_beta
);
222 EXPECT_LT(v1_0_0_alpha2
, v1_0_0_alpha3
);
223 EXPECT_LT(v1_0_0_alpha2
, v1_0_0_alpha10
);
224 EXPECT_LT(v1_0_0_alpha3
, v1_0_0
);
225 EXPECT_LT(v1_0_0_alpha3
, v1_0_0_beta
);
226 EXPECT_LT(v1_0_0_alpha3
, v1_0_0_alpha10
);
227 EXPECT_LT(v1_0_0_alpha10
, v1_0_0
);
228 EXPECT_LT(v1_0_0_alpha10
, v1_0_0_beta
);
230 // pep-0440/local-version-identifiers
231 // ref: https://www.python.org/dev/peps/pep-0440/#local-version-identifiers
232 // Python addons use this kind of versioning particularly for script.module
233 // addons. The "same" version number may exist in different branches or
234 // targeting different kodi versions while keeping consistency with the
235 // upstream module version. The addon version available in upper repos
236 // (let's say matrix) must have a higher version than the one stored in
237 // lower branches (e.g. leia) so that users receive the addon update
238 // when upgrading kodi.
239 // So, for instance, we use version x.x.x or version x.x.x+kodiversion.r to
240 // refer to the same upstream version x.x.x of the module.
241 // Eg: script.module.foo-1.0.0 or script.module.foo-1.0.0+leia.1 for upstream
242 // module foo (version 1.0.0) available for leia; and
243 // script.module.foo-1.0.0+matrix.1 for upstream module foo (1.0.0) for matrix.
244 // In summary, 1.0.0 or 1.0.0+leia.1 must be < than 1.0.0+matrix.1
245 // tests below assure this won't get broken inadvertently
246 EXPECT_LT(CAddonVersion("1.0.0"), CAddonVersion("1.0.0+matrix.1"));
247 EXPECT_LT(CAddonVersion("1.0.0+leia.1"), CAddonVersion("1.0.0+matrix.1"));
248 EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.0+matrix.2"));
249 EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.1+matrix.1"));
250 EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.1.0+matrix.1"));
251 EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("2.0.0+matrix.1"));
252 EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.0.1"));
253 EXPECT_LT(CAddonVersion("1.0.0+Leia.1"), CAddonVersion("1.0.0+matrix.1"));
254 EXPECT_LT(CAddonVersion("1.0.0+leia.1"), CAddonVersion("1.0.0+Matrix.1"));
257 TEST_F(TestAddonVersion
, Equivalent
)
259 EXPECT_FALSE(v1_0
!= v1_00
);
260 EXPECT_FALSE(v1_0
< v1_00
);
261 EXPECT_FALSE(v1_0
> v1_00
);
262 EXPECT_TRUE(v1_0
== v1_00
);
264 EXPECT_FALSE(v1_01
!= v1_1
);
265 EXPECT_FALSE(v1_01
< v1_1
);
266 EXPECT_FALSE(v1_01
> v1_1
);
267 EXPECT_TRUE(v1_01
== v1_1
);
269 // pep-0440/local-version-identifiers
270 EXPECT_TRUE(CAddonVersion("1.0.0+leia.1") == CAddonVersion("1.0.0+Leia.1"));