summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/component
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/component
Publish
Diffstat (limited to 'vespalib/src/tests/component')
-rw-r--r--vespalib/src/tests/component/.gitignore4
-rw-r--r--vespalib/src/tests/component/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/component/DESC1
-rw-r--r--vespalib/src/tests/component/FILES1
-rw-r--r--vespalib/src/tests/component/component.cpp204
5 files changed, 218 insertions, 0 deletions
diff --git a/vespalib/src/tests/component/.gitignore b/vespalib/src/tests/component/.gitignore
new file mode 100644
index 00000000000..2cc2b6d4073
--- /dev/null
+++ b/vespalib/src/tests/component/.gitignore
@@ -0,0 +1,4 @@
+.depend
+Makefile
+component_test
+vespalib_component_test_app
diff --git a/vespalib/src/tests/component/CMakeLists.txt b/vespalib/src/tests/component/CMakeLists.txt
new file mode 100644
index 00000000000..0f30f398db2
--- /dev/null
+++ b/vespalib/src/tests/component/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_component_test_app
+ SOURCES
+ component.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_component_test_app COMMAND vespalib_component_test_app)
diff --git a/vespalib/src/tests/component/DESC b/vespalib/src/tests/component/DESC
new file mode 100644
index 00000000000..176a43ab3bf
--- /dev/null
+++ b/vespalib/src/tests/component/DESC
@@ -0,0 +1 @@
+component test. Take a look at component.cpp for details.
diff --git a/vespalib/src/tests/component/FILES b/vespalib/src/tests/component/FILES
new file mode 100644
index 00000000000..bf84bdd6d20
--- /dev/null
+++ b/vespalib/src/tests/component/FILES
@@ -0,0 +1 @@
+component.cpp
diff --git a/vespalib/src/tests/component/component.cpp b/vespalib/src/tests/component/component.cpp
new file mode 100644
index 00000000000..ee21f816588
--- /dev/null
+++ b/vespalib/src/tests/component/component.cpp
@@ -0,0 +1,204 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("component_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/exceptions.h>
+
+#include <vespa/vespalib/component/version.h>
+#include <vespa/vespalib/component/versionspecification.h>
+
+using namespace vespalib;
+
+void
+EXPECT_LT(const VersionSpecification::string &lhs,
+ const VersionSpecification::string &rhs)
+{
+ EXPECT_TRUE(VersionSpecification(lhs) < VersionSpecification(rhs));
+ EXPECT_FALSE(VersionSpecification(lhs) == VersionSpecification(rhs));
+ EXPECT_FALSE(VersionSpecification(rhs) < VersionSpecification(lhs));
+}
+
+void
+EXPECT_EQ(const VersionSpecification::string &lhs,
+ const VersionSpecification::string &rhs)
+{
+ EXPECT_FALSE(VersionSpecification(lhs) < VersionSpecification(rhs));
+ EXPECT_TRUE(VersionSpecification(lhs) == VersionSpecification(rhs));
+ EXPECT_FALSE(VersionSpecification(rhs) < VersionSpecification(lhs));
+}
+
+void
+EXPECT_NE(const VersionSpecification::string &lhs,
+ const VersionSpecification::string &rhs)
+{
+ EXPECT_TRUE(VersionSpecification(lhs) < VersionSpecification(rhs) ||
+ VersionSpecification(rhs) < VersionSpecification(lhs));
+ EXPECT_FALSE(VersionSpecification(lhs) == VersionSpecification(rhs));
+}
+
+void
+EXPECT_GT(const VersionSpecification::string &lhs,
+ const VersionSpecification::string &rhs)
+{
+ EXPECT_FALSE(VersionSpecification(lhs) < VersionSpecification(rhs));
+ EXPECT_FALSE(VersionSpecification(lhs) == VersionSpecification(rhs));
+ EXPECT_TRUE(VersionSpecification(rhs) < VersionSpecification(lhs));
+}
+
+TEST("requireThatCompareToIsSymmetric")
+{
+ EXPECT_LT("1", "2");
+ EXPECT_EQ("2", "2");
+ EXPECT_GT("2", "1");
+
+ EXPECT_LT("1.2", "3.4");
+ EXPECT_EQ("3.4", "3.4");
+ EXPECT_GT("3.4", "1.2");
+
+ EXPECT_LT("1.2.3", "4.5.6");
+ EXPECT_EQ("4.5.6", "4.5.6");
+ EXPECT_GT("4.5.6", "1.2.3");
+
+ EXPECT_LT("1.2.3.4", "5.6.7.8");
+ EXPECT_EQ("5.6.7.8", "5.6.7.8");
+ EXPECT_GT("5.6.7.8", "1.2.3.4");
+}
+
+TEST("requireThatCompareToIsTransitive")
+{
+ EXPECT_LT("1", "2");
+ EXPECT_LT("2", "3");
+ EXPECT_LT("1", "3");
+
+ EXPECT_LT("1.1", "1.2");
+ EXPECT_LT("1.2", "1.3");
+ EXPECT_LT("1.1", "1.3");
+
+ EXPECT_LT("1.1.1", "1.1.2");
+ EXPECT_LT("1.1.2", "1.1.3");
+ EXPECT_LT("1.1.1", "1.1.3");
+
+ EXPECT_LT("1.1.1.1", "1.1.1.2");
+ EXPECT_LT("1.1.1.2", "1.1.1.3");
+ EXPECT_LT("1.1.1.1", "1.1.1.3");
+}
+
+TEST("requireThatUnspecifiedComponentDoesNotMatchSpecified")
+{
+ EXPECT_EQ("1", "1");
+ EXPECT_NE("1", "1.2");
+ EXPECT_NE("1", "1.2.3");
+ EXPECT_NE("1", "1.2.3.4");
+
+ EXPECT_NE("1.2", "1");
+ EXPECT_EQ("1.2", "1.2");
+ EXPECT_NE("1.2", "1.2.3");
+ EXPECT_NE("1.2", "1.2.3.4");
+
+ EXPECT_NE("1.2.3", "1");
+ EXPECT_NE("1.2.3", "1.2");
+ EXPECT_EQ("1.2.3", "1.2.3");
+ EXPECT_NE("1.2.3", "1.2.3.4");
+
+ EXPECT_NE("1.2.3.4", "1");
+ EXPECT_NE("1.2.3.4", "1.2");
+ EXPECT_NE("1.2.3.4", "1.2.3");
+ EXPECT_EQ("1.2.3.4", "1.2.3.4");
+}
+
+TEST("testText")
+{
+ VersionSpecification v("0.1.2.3");
+ EXPECT_EQUAL(0, v.getMajor());
+ EXPECT_EQUAL(1, v.getMinor());
+ EXPECT_EQUAL(2, v.getMicro());
+ EXPECT_EQUAL("3", v.getQualifier());
+ v = VersionSpecification("1.2.3.4");
+ EXPECT_EQUAL(1, v.getMajor());
+ EXPECT_EQUAL(2, v.getMinor());
+ EXPECT_EQUAL(3, v.getMicro());
+ EXPECT_EQUAL("4", v.getQualifier());
+ v = VersionSpecification("1");
+ EXPECT_EQUAL(1, v.getMajor());
+ EXPECT_EQUAL(0, v.getMinor());
+ EXPECT_EQUAL(0, v.getMicro());
+ EXPECT_EQUAL("", v.getQualifier());
+ EXPECT_EXCEPTION(v = VersionSpecification("-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = VersionSpecification("1.-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = VersionSpecification("1.2.-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = VersionSpecification("1.2.3.-1"), IllegalArgumentException, "Invalid character in qualifier");
+}
+
+TEST("testText2")
+{
+ Version v("0.1.2.3");
+ EXPECT_EQUAL(0, v.getMajor());
+ EXPECT_EQUAL(1, v.getMinor());
+ EXPECT_EQUAL(2, v.getMicro());
+ EXPECT_EQUAL("3", v.getQualifier());
+ v = Version("1.2.3.4");
+ EXPECT_EQUAL(1, v.getMajor());
+ EXPECT_EQUAL(2, v.getMinor());
+ EXPECT_EQUAL(3, v.getMicro());
+ EXPECT_EQUAL("4", v.getQualifier());
+ v = Version("1");
+ EXPECT_EQUAL(1, v.getMajor());
+ EXPECT_EQUAL(0, v.getMinor());
+ EXPECT_EQUAL(0, v.getMicro());
+ EXPECT_EQUAL("", v.getQualifier());
+ EXPECT_EXCEPTION(v = Version("-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = Version("1.-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = Version("1.2.-1"), IllegalArgumentException, "integer must start with a digit");
+ EXPECT_EXCEPTION(v = Version("1.2.3.-1"), IllegalArgumentException, "Invalid character in qualifier");
+}
+
+TEST("testEmpty")
+{
+ Version ev;
+ VersionSpecification evs;
+
+ EXPECT_EQUAL("", ev.toString());
+ EXPECT_EQUAL("*.*.*", evs.toString());
+
+ EXPECT_TRUE(ev == Version(0,0,0,""));
+
+ EXPECT_TRUE(evs.matches(ev));
+ EXPECT_TRUE(evs.matches(Version(1,2,3)));
+ EXPECT_TRUE(!evs.matches(Version(1,2,3,"foo")));
+}
+
+TEST("testSimple")
+{
+ // test Version:
+
+ Version v(1, 2, 3, "qualifier");
+ EXPECT_EQUAL(1, v.getMajor());
+ EXPECT_EQUAL(2, v.getMinor());
+ EXPECT_EQUAL(3, v.getMicro());
+ EXPECT_EQUAL("qualifier", v.getQualifier());
+
+ EXPECT_EQUAL("1.2.3.qualifier", v.toString());
+
+ // test VersionSpecification:
+
+ VersionSpecification vs(1, 2, 3, "qualifier");
+ EXPECT_EQUAL(1, vs.getMajor());
+ EXPECT_EQUAL(2, vs.getMinor());
+ EXPECT_EQUAL(3, vs.getMicro());
+ EXPECT_EQUAL("qualifier", vs.getQualifier());
+
+ EXPECT_EQUAL(1, vs.getSpecifiedMajor());
+ EXPECT_EQUAL(2, vs.getSpecifiedMinor());
+ EXPECT_EQUAL(3, vs.getSpecifiedMicro());
+
+ EXPECT_EQUAL("1.2.3.qualifier", vs.toString());
+
+ // test cross-class function
+ EXPECT_TRUE(vs.matches(v));
+}
+
+TEST_MAIN()
+{
+ TEST_RUN_ALL();
+}