1 package be
.nikiroo
.utils
.test_code
;
3 import be
.nikiroo
.utils
.Version
;
4 import be
.nikiroo
.utils
.test
.TestCase
;
5 import be
.nikiroo
.utils
.test
.TestLauncher
;
7 class VersionTest
extends TestLauncher
{
8 public VersionTest(String
[] args
) {
9 super("Version test", args
);
11 addTest(new TestCase("String <-> int") {
13 public void test() throws Exception
{
14 assertEquals("Cannot parse version 1.2.3 from int to String",
15 "1.2.3", new Version(1, 2, 3).toString());
17 "Cannot parse major version \"1.2.3\" from String to int",
18 1, new Version("1.2.3").getMajor());
20 "Cannot parse minor version \"1.2.3\" from String to int",
21 2, new Version("1.2.3").getMinor());
23 "Cannot parse patch version \"1.2.3\" from String to int",
24 3, new Version("1.2.3").getPatch());
28 addTest(new TestCase("Bad input") {
30 public void test() throws Exception
{
32 "Bad input should return an empty version",
35 "Doors 98 SE Special Deluxe Edition Pro++ Not-Home")
39 "Bad input should return [unknown]",
42 "Doors 98 SE Special Deluxe Edition Pro++ Not-Home")
47 addTest(new TestCase("Read current version") {
49 public void test() throws Exception
{
50 assertNotNull("The version should not be NULL (in any case!)",
51 Version
.getCurrentVersion());
52 assertEquals("The current version should not be empty", false,
53 Version
.getCurrentVersion().isEmpty());
57 addTest(new TestCase("Tag version") {
59 public void test() throws Exception
{
60 Version version
= new Version("1.0.0-debian0");
61 assertEquals("debian", version
.getTag());
62 assertEquals(0, version
.getTagVersion());
63 version
= new Version("1.0.0-debian.0");
64 assertEquals("debian.", version
.getTag());
65 assertEquals(0, version
.getTagVersion());
66 version
= new Version("1.0.0-debian-0");
67 assertEquals("debian-", version
.getTag());
68 assertEquals(0, version
.getTagVersion());
69 version
= new Version("1.0.0-debian-12");
70 assertEquals("debian-", version
.getTag());
71 assertEquals(12, version
.getTagVersion());
73 // tag with no tag version
74 version
= new Version("1.0.0-dev");
75 assertEquals(1, version
.getMajor());
76 assertEquals(0, version
.getMinor());
77 assertEquals(0, version
.getPatch());
78 assertEquals("dev", version
.getTag());
79 assertEquals(-1, version
.getTagVersion());
83 addTest(new TestCase("Comparing versions") {
85 public void test() throws Exception
{
87 new Version(1, 1, 1).isNewerThan(new Version(1, 1, 0)));
89 new Version(2, 0, 0).isNewerThan(new Version(1, 1, 1)));
91 new Version(10, 7, 8).isNewerThan(new Version(9, 9, 9)));
93 new Version(0, 0, 0).isOlderThan(new Version(0, 0, 1)));
95 new Version(1, 1, 1).compareTo(new Version(0, 1, 1)));
97 new Version(0, 0, 1).compareTo(new Version(0, 1, 1)));
99 new Version(0, 0, 1).compareTo(new Version(0, 0, 1)));
101 new Version(0, 0, 1).equals(new Version(0, 0, 1)));
103 new Version(0, 2, 1).equals(new Version(0, 0, 1)));
106 new Version(1, 0, 1, "my.tag.", 2).equals(new Version(
107 1, 0, 1, "my.tag.", 2)));
109 new Version(1, 0, 1, "my.tag.", 2).equals(new Version(
110 1, 0, 0, "my.tag.", 2)));
112 new Version(1, 0, 1, "my.tag.", 2).equals(new Version(
113 1, 0, 1, "not-my.tag.", 2)));
117 addTest(new TestCase("toString") {
119 public void test() throws Exception
{
121 Version version
= new Version("01.002.4");
122 assertEquals("Leading 0s not working", "1.2.4",
126 version
= new Version("1 . 2.4 ");
127 assertEquals("Additional spaces not working", "1.2.4",
130 String
[] tests
= new String
[] { "1.0.0", "1.2.3", "1.0.0-dev",
132 for (String test
: tests
) {
133 version
= new Version(test
);
134 assertEquals("toString and back conversion failed", test
,