OSVersionTests.cs
5.49 KB
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
using NUnit.Framework;
namespace UnityEngine.XR.ARKit.Tests
{
[TestFixture]
class OSVersionTestFixture
{
void GreaterThan(int major, int minor, int point)
{
Assert.That(new OSVersion(major + 1, minor, point) > new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) > new OSVersion(major + 1, minor, point)));
Assert.That(new OSVersion(major, minor + 1, point) > new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) > new OSVersion(major, minor + 1, point)));
Assert.That(new OSVersion(major, minor, point + 1) > new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) > new OSVersion(major, minor, point + 1)));
}
void LessThan(int major, int minor, int point)
{
Assert.That(new OSVersion(major - 1, minor, point) < new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) < new OSVersion(major - 1, minor, point)));
Assert.That(new OSVersion(major, minor - 1, point) < new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) < new OSVersion(major, minor - 1, point)));
Assert.That(new OSVersion(major, minor, point - 1) < new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major, minor, point) < new OSVersion(major, minor, point - 1)));
}
void LessThanOrEqualTo(int major, int minor, int point)
{
Assert.That(new OSVersion(major, minor, point) <= new OSVersion(major, minor, point));
LessThan(major, minor, point);
}
void GreaterThanOrEqualTo(int major, int minor, int point)
{
Assert.That(new OSVersion(major, minor, point) >= new OSVersion(major, minor, point));
GreaterThan(major, minor, point);
}
void EqualTo(int major, int minor, int point)
{
Assert.That(new OSVersion(major, minor, point) == new OSVersion(major, minor, point));
Assert.That(!(new OSVersion(major + 1, minor, point) == new OSVersion(major, minor, point)));
Assert.That(!(new OSVersion(major, minor + 1, point) == new OSVersion(major, minor, point)));
Assert.That(!(new OSVersion(major, minor, point + 1) == new OSVersion(major, minor, point)));
}
void NotEqualTo(int major, int minor, int point)
{
Assert.That(!(new OSVersion(major, minor, point) != new OSVersion(major, minor, point)));
Assert.That(new OSVersion(major + 1, minor, point) != new OSVersion(major, minor, point));
Assert.That(new OSVersion(major, minor + 1, point) != new OSVersion(major, minor, point));
Assert.That(new OSVersion(major, minor, point + 1) != new OSVersion(major, minor, point));
}
void TestStringParser(int major, int minor, int point)
{
var version = new OSVersion(major, minor, point);
var versionString = version.ToString();
Assert.That(OSVersion.Parse(versionString).Equals(version));
// Add unicode characters
Assert.That(OSVersion.Parse("iPhone version 中文" + versionString + "عربى -/@!@#$23").Equals(version));
}
[Test]
public void GreaterThan()
{
GreaterThan(1, 2, 3);
}
[Test]
public void GreaterThanOrEqualTo()
{
GreaterThanOrEqualTo(1, 2, 3);
}
[Test]
public void LessThan()
{
LessThan(2, 3, 4);
}
[Test]
public void LessThanOrEqualTo()
{
LessThanOrEqualTo(2, 3, 4);
}
[Test]
public void EqualTo()
{
EqualTo(1, 2, 3);
}
[Test]
public void NotEqualTo()
{
NotEqualTo(1, 2, 3);
}
[Test]
public void StringParser()
{
for (int point = 0; point < 10; ++point)
{
TestStringParser(0, 1, point);
TestStringParser(12, 0, point);
TestStringParser(9, 0, point);
TestStringParser(0, 99, point);
TestStringParser(999, 999, point);
TestStringParser(0, 0, point);
}
Assert.That(OSVersion.Parse("iOS 12.2") == new OSVersion(12, 2));
Assert.That(OSVersion.Parse("iOS 12.3.1") == new OSVersion(12, 3, 1));
// We do a lot of tests against iOS 12, so let's actually check that.
Assert.That(OSVersion.Parse("12") >= new OSVersion(12));
Assert.That(OSVersion.Parse("12.0") >= new OSVersion(12));
Assert.That(OSVersion.Parse("12.1") >= new OSVersion(12));
Assert.That(OSVersion.Parse("12.1.1") >= new OSVersion(12));
}
[Test]
public void IgnoresLeadingZeroes()
{
Assert.That(OSVersion.Parse("0012.02.004") == new OSVersion(12, 2, 4));
}
[Test]
public void StopsParsingAtFirstInvalidCharacter()
{
Assert.That(OSVersion.Parse("12.2 .4") == new OSVersion(12, 2));
}
[Test]
public void HandlesNull()
{
Assert.That(OSVersion.Parse(null) == new OSVersion(0));
}
[Test]
public void HandlesEmptyString()
{
Assert.That(OSVersion.Parse("") == new OSVersion(0));
}
}
}