aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in6
-rw-r--r--xbmc/addons/AddonVersion.cpp25
-rw-r--r--xbmc/addons/AddonVersion.h1
-rw-r--r--xbmc/addons/test/Makefile9
-rw-r--r--xbmc/addons/test/TestAddonVersion.cpp233
5 files changed, 246 insertions, 28 deletions
diff --git a/Makefile.in b/Makefile.in
index 2aaa79f584..e07970fe34 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -289,12 +289,14 @@ GTEST_DIR = lib/gtest
GTEST_INCLUDES = -I$(GTEST_DIR)/include
GTEST_LIBS = $(GTEST_DIR)/lib/.libs/libgtest.a
-CHECK_DIRS = xbmc/filesystem/test \
+CHECK_DIRS = xbmc/addons/test \
+ xbmc/filesystem/test \
xbmc/utils/test \
xbmc/threads/test \
xbmc/interfaces/python/test \
xbmc/test
-CHECK_LIBS = xbmc/filesystem/test/filesystemTest.a \
+CHECK_LIBS = xbmc/addons/test/addonsTest.a \
+ xbmc/filesystem/test/filesystemTest.a \
xbmc/utils/test/utilsTest.a \
xbmc/threads/test/threadTest.a \
xbmc/interfaces/python/test/pythonSwigTest.a \
diff --git a/xbmc/addons/AddonVersion.cpp b/xbmc/addons/AddonVersion.cpp
index 5a6fb4d3ec..a83dd4ed7c 100644
--- a/xbmc/addons/AddonVersion.cpp
+++ b/xbmc/addons/AddonVersion.cpp
@@ -146,29 +146,4 @@ namespace ADDON
return true;
}
-
- bool AddonVersion::Test()
- {
- AddonVersion v1_0("1.0");
- AddonVersion v1_00("1.00");
- AddonVersion v1_0_0("1.0.0");
- AddonVersion v1_1("1.1");
- AddonVersion v1_01("1.01");
- AddonVersion v1_0_1("1.0.1");
-
- bool ret = false;
-
- // These are totally sane
- ret = (v1_0 < v1_1) && (v1_0 < v1_01) && (v1_0 < v1_0_1) &&
- (v1_1 > v1_0_1) && (v1_01 > v1_0_1);
-
- // These are rather sane
- ret &= (v1_0 != v1_0_0) && (v1_0 < v1_0_0) && (v1_0_0 > v1_0) &&
- (v1_00 != v1_0_0) && (v1_00 < v1_0_0) && (v1_0_0 > v1_00);
-
- ret &= (v1_0 == v1_00) && !(v1_0 < v1_00) && !(v1_0 > v1_00);
- ret &= (v1_1 == v1_01) && !(v1_1 < v1_01) && !(v1_1 > v1_01);
-
- return ret;
- }
}
diff --git a/xbmc/addons/AddonVersion.h b/xbmc/addons/AddonVersion.h
index f804278169..c87d64a42d 100644
--- a/xbmc/addons/AddonVersion.h
+++ b/xbmc/addons/AddonVersion.h
@@ -58,7 +58,6 @@ namespace ADDON
static bool SplitFileName(CStdString& ID, CStdString& version,
const CStdString& filename);
- static bool Test();
protected:
CStdString m_originalVersion;
int mEpoch;
diff --git a/xbmc/addons/test/Makefile b/xbmc/addons/test/Makefile
new file mode 100644
index 0000000000..bf74bd6ca3
--- /dev/null
+++ b/xbmc/addons/test/Makefile
@@ -0,0 +1,9 @@
+SRCS= \
+ TestAddonVersion.cpp
+
+LIB=addonsTest.a
+
+INCLUDES += -I../../../lib/gtest/include
+
+include ../../../Makefile.include
+-include $(patsubst %.cpp,%.P,$(patsubst %.c,%.P,$(SRCS)))
diff --git a/xbmc/addons/test/TestAddonVersion.cpp b/xbmc/addons/test/TestAddonVersion.cpp
new file mode 100644
index 0000000000..910c593c5f
--- /dev/null
+++ b/xbmc/addons/test/TestAddonVersion.cpp
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2005-2014 Team XBMC
+ * http://xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "addons/AddonVersion.h"
+
+#include "gtest/gtest.h"
+
+using namespace ADDON;
+
+class TestAddonVersion : public testing::Test
+{
+public:
+ TestAddonVersion()
+ : v1_0("1.0"),
+ v1_00("1.00"),
+ v1_0_0("1.0.0"),
+ v1_1("1.1"),
+ v1_01("1.01"),
+ v1_0_1("1.0.1"),
+ e1_v1_0_0("1:1.0.0"),
+ e1_v1_0_1("1:1.0.1"),
+ e2_v1_0_0("2:1.0.0"),
+ e1_v1_0_0_r1("1:1.0.0-1"),
+ e1_v1_0_1_r1("1:1.0.1-1"),
+ e1_v1_0_0_r2("1:1.0.0-2"),
+ v1_0_0_beta("1.0.0~beta"),
+ v1_0_0_alpha("1.0.0~alpha"),
+ v1_0_0_alpha2("1.0.0~alpha2"),
+ v1_0_0_alpha3("1.0.0~alpha3"),
+ v1_0_0_alpha10("1.0.0~alpha10")
+ {
+ }
+
+ AddonVersion v1_0;
+ AddonVersion v1_00;
+ AddonVersion v1_0_0;
+ AddonVersion v1_1;
+ AddonVersion v1_01;
+ AddonVersion v1_0_1;
+ AddonVersion e1_v1_0_0;
+ AddonVersion e1_v1_0_1;
+ AddonVersion e2_v1_0_0;
+ AddonVersion e1_v1_0_0_r1;
+ AddonVersion e1_v1_0_1_r1;
+ AddonVersion e1_v1_0_0_r2;
+ AddonVersion v1_0_0_beta;
+ AddonVersion v1_0_0_alpha;
+ AddonVersion v1_0_0_alpha2;
+ AddonVersion v1_0_0_alpha3;
+ AddonVersion v1_0_0_alpha10;
+};
+
+TEST_F(TestAddonVersion, Constructor)
+{
+ EXPECT_STREQ(v1_0.Upstream(), "1.0");
+ EXPECT_EQ(v1_0.Epoch(), 0);
+ EXPECT_STREQ(v1_0.Revision(), "0");
+
+ EXPECT_STREQ(v1_00.Upstream(), "1.00");
+ EXPECT_EQ(v1_00.Epoch(), 0);
+ EXPECT_STREQ(v1_00.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_0.Upstream(), "1.0.0");
+ EXPECT_EQ(v1_0_0.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0.Revision(), "0");
+
+ EXPECT_STREQ(v1_1.Upstream(), "1.1");
+ EXPECT_EQ(v1_1.Epoch(), 0);
+ EXPECT_STREQ(v1_1.Revision(), "0");
+
+ EXPECT_STREQ(v1_01.Upstream(), "1.01");
+ EXPECT_EQ(v1_01.Epoch(), 0);
+ EXPECT_STREQ(v1_01.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_1.Upstream(), "1.0.1");
+ EXPECT_EQ(v1_0_1.Epoch(), 0);
+ EXPECT_STREQ(v1_0_1.Revision(), "0");
+
+ EXPECT_STREQ(e1_v1_0_0.Upstream(), "1.0.0");
+ EXPECT_EQ(e1_v1_0_0.Epoch(), 1);
+ EXPECT_STREQ(e1_v1_0_0.Revision(), "0");
+
+ EXPECT_STREQ(e1_v1_0_1.Upstream(), "1.0.1");
+ EXPECT_EQ(e1_v1_0_1.Epoch(), 1);
+ EXPECT_STREQ(e1_v1_0_1.Revision(), "0");
+
+ EXPECT_STREQ(e2_v1_0_0.Upstream(), "1.0.0");
+ EXPECT_EQ(e2_v1_0_0.Epoch(), 2);
+ EXPECT_STREQ(e2_v1_0_0.Revision(), "0");
+
+ EXPECT_STREQ(e1_v1_0_0_r1.Upstream(), "1.0.0");
+ EXPECT_EQ(e1_v1_0_0_r1.Epoch(), 1);
+ EXPECT_STREQ(e1_v1_0_0_r1.Revision(), "1");
+
+ EXPECT_STREQ(e1_v1_0_1_r1.Upstream(), "1.0.1");
+ EXPECT_EQ(e1_v1_0_1_r1.Epoch(), 1);
+ EXPECT_STREQ(e1_v1_0_1_r1.Revision(), "1");
+
+ EXPECT_STREQ(e1_v1_0_0_r2.Upstream(), "1.0.0");
+ EXPECT_EQ(e1_v1_0_0_r2.Epoch(), 1);
+ EXPECT_STREQ(e1_v1_0_0_r2.Revision(), "2");
+
+ EXPECT_STREQ(v1_0_0_beta.Upstream(), "1.0.0~beta");
+ EXPECT_EQ(v1_0_0_beta.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0_beta.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_0_alpha.Upstream(), "1.0.0~alpha");
+ EXPECT_EQ(v1_0_0_alpha.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0_alpha.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_0_alpha2.Upstream(), "1.0.0~alpha2");
+ EXPECT_EQ(v1_0_0_alpha2.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0_alpha2.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_0_alpha3.Upstream(), "1.0.0~alpha3");
+ EXPECT_EQ(v1_0_0_alpha3.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0_alpha3.Revision(), "0");
+
+ EXPECT_STREQ(v1_0_0_alpha10.Upstream(), "1.0.0~alpha10");
+ EXPECT_EQ(v1_0_0_alpha10.Epoch(), 0);
+ EXPECT_STREQ(v1_0_0_alpha10.Revision(), "0");
+}
+
+TEST_F(TestAddonVersion, Equals)
+{
+ EXPECT_EQ(v1_0, AddonVersion("1.0"));
+ EXPECT_EQ(v1_00, AddonVersion("1.00"));
+ EXPECT_EQ(v1_0_0, AddonVersion("1.0.0"));
+ EXPECT_EQ(v1_1, AddonVersion("1.1"));
+ EXPECT_EQ(v1_01, AddonVersion("1.01"));
+ EXPECT_EQ(v1_0_1, AddonVersion("1.0.1"));
+ EXPECT_EQ(e1_v1_0_0, AddonVersion("1:1.0.0"));
+ EXPECT_EQ(e1_v1_0_1, AddonVersion("1:1.0.1"));
+ EXPECT_EQ(e2_v1_0_0, AddonVersion("2:1.0.0"));
+ EXPECT_EQ(e1_v1_0_0_r1, AddonVersion("1:1.0.0-1"));
+ EXPECT_EQ(e1_v1_0_1_r1, AddonVersion("1:1.0.1-1"));
+ EXPECT_EQ(e1_v1_0_0_r2, AddonVersion("1:1.0.0-2"));
+ EXPECT_EQ(v1_0_0_beta, AddonVersion("1.0.0~beta"));
+ EXPECT_EQ(v1_0_0_alpha, AddonVersion("1.0.0~alpha"));
+ EXPECT_EQ(v1_0_0_alpha2, AddonVersion("1.0.0~alpha2"));
+ EXPECT_EQ(v1_0_0_alpha3, AddonVersion("1.0.0~alpha3"));
+ EXPECT_EQ(v1_0_0_alpha10, AddonVersion("1.0.0~alpha10"));
+}
+
+TEST_F(TestAddonVersion, Equivalent)
+{
+ EXPECT_FALSE(v1_0 != v1_00);
+ EXPECT_FALSE(v1_0 < v1_00);
+ EXPECT_FALSE(v1_0 > v1_00);
+ EXPECT_TRUE(v1_0 == v1_00);
+
+ EXPECT_FALSE(v1_01 != v1_1);
+ EXPECT_FALSE(v1_01 < v1_1);
+ EXPECT_FALSE(v1_01 > v1_1);
+ EXPECT_TRUE(v1_01 == v1_1);
+}
+
+TEST_F(TestAddonVersion, LessThan)
+{
+ EXPECT_LT(v1_0, v1_0_0);
+ EXPECT_LT(v1_0, v1_1);
+ EXPECT_LT(v1_0, v1_01);
+ EXPECT_LT(v1_0, v1_0_1);
+
+ EXPECT_LT(v1_00, v1_0_0);
+ EXPECT_LT(v1_00, v1_1);
+ EXPECT_LT(v1_00, v1_01);
+ EXPECT_LT(v1_00, v1_0_1);
+
+ EXPECT_LT(v1_0_0, v1_1);
+ EXPECT_LT(v1_0_0, v1_01);
+ EXPECT_LT(v1_0_0, v1_0_1);
+
+ EXPECT_LT(v1_0_1, v1_01);
+ EXPECT_LT(v1_0_1, v1_1);
+
+ // epochs
+ EXPECT_LT(v1_0_0, e1_v1_0_0);
+ EXPECT_LT(v1_0_0, e1_v1_0_1);
+ EXPECT_LT(v1_0_0, e2_v1_0_0);
+ EXPECT_LT(v1_0_1, e1_v1_0_1);
+ EXPECT_LT(v1_0_1, e2_v1_0_0);
+
+ EXPECT_LT(e1_v1_0_0, e1_v1_0_1);
+ EXPECT_LT(e1_v1_0_0, e2_v1_0_0);
+ EXPECT_LT(e1_v1_0_1, e2_v1_0_0);
+
+ // revisions
+ EXPECT_LT(e1_v1_0_0, e1_v1_0_0_r1);
+ EXPECT_LT(e1_v1_0_0, e1_v1_0_1_r1);
+ EXPECT_LT(e1_v1_0_0, e1_v1_0_0_r2);
+ EXPECT_LT(e1_v1_0_1, e1_v1_0_1_r1);
+ EXPECT_LT(e1_v1_0_0_r1, e1_v1_0_1);
+ EXPECT_LT(e1_v1_0_0_r1, e1_v1_0_1_r1);
+ EXPECT_LT(e1_v1_0_0_r1, e1_v1_0_0_r2);
+ EXPECT_LT(e1_v1_0_0_r2, e1_v1_0_1);
+ EXPECT_LT(e1_v1_0_0_r2, e1_v1_0_1_r1);
+ EXPECT_LT(e1_v1_0_1_r1, e2_v1_0_0);
+
+ // alpha, beta
+ EXPECT_LT(v1_0_0_beta, v1_0_0);
+ EXPECT_LT(v1_0_0_alpha, v1_0_0);
+ EXPECT_LT(v1_0_0_alpha, v1_0_0_beta);
+ EXPECT_LT(v1_0_0_alpha, v1_0_0_alpha2);
+ EXPECT_LT(v1_0_0_alpha, v1_0_0_alpha3);
+ EXPECT_LT(v1_0_0_alpha, v1_0_0_alpha10);
+ EXPECT_LT(v1_0_0_alpha2, v1_0_0);
+ EXPECT_LT(v1_0_0_alpha2, v1_0_0_beta);
+ EXPECT_LT(v1_0_0_alpha2, v1_0_0_alpha3);
+ EXPECT_LT(v1_0_0_alpha2, v1_0_0_alpha10);
+ EXPECT_LT(v1_0_0_alpha3, v1_0_0);
+ EXPECT_LT(v1_0_0_alpha3, v1_0_0_beta);
+ EXPECT_LT(v1_0_0_alpha3, v1_0_0_alpha10);
+ EXPECT_LT(v1_0_0_alpha10, v1_0_0);
+ EXPECT_LT(v1_0_0_alpha10, v1_0_0_beta);
+}