hidl_version: Add comparison operators

Test: libhidl_test passes
Change-Id: I8bb01599ae581484d80014bd99c4aff09a953824
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 8bdb5fe..0670dd9 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -703,6 +703,23 @@
         return (mMajor == other.get_major() && mMinor == other.get_minor());
     }
 
+    bool operator<(const hidl_version& other) const {
+        return (mMajor < other.get_major() ||
+                (mMajor == other.get_major() && mMinor < other.get_minor()));
+    }
+
+    bool operator>(const hidl_version& other) const {
+        return other < *this;
+    }
+
+    bool operator<=(const hidl_version& other) const {
+        return !(*this > other);
+    }
+
+    bool operator>=(const hidl_version& other) const {
+        return !(*this < other);
+    }
+
     constexpr uint16_t get_major() const { return mMajor; }
     constexpr uint16_t get_minor() const { return mMinor; }
 
@@ -798,4 +815,3 @@
 
 
 #endif  // ANDROID_HIDL_SUPPORT_H
-
diff --git a/test_main.cpp b/test_main.cpp
index 0a7ad90..ca5d017 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -255,6 +255,31 @@
     EXPECT_2DARRAYEQ(array, array2, 2, 3);
 }
 
+TEST_F(LibHidlTest, HidlVersionTest) {
+    using android::hardware::hidl_version;
+    hidl_version v1_0{1, 0};
+    EXPECT_EQ(1, v1_0.get_major());
+    EXPECT_EQ(0, v1_0.get_minor());
+    hidl_version v2_0{2, 0};
+    hidl_version v2_1{2, 1};
+    hidl_version v2_2{2, 2};
+    hidl_version v3_0{3, 0};
+    hidl_version v3_0b{3,0};
+
+    EXPECT_TRUE(v1_0 < v2_0);
+    EXPECT_TRUE(v2_0 < v2_1);
+    EXPECT_TRUE(v2_1 < v3_0);
+    EXPECT_TRUE(v2_0 > v1_0);
+    EXPECT_TRUE(v2_1 > v2_0);
+    EXPECT_TRUE(v3_0 > v2_1);
+    EXPECT_TRUE(v3_0 == v3_0b);
+    EXPECT_TRUE(v3_0 <= v3_0b);
+    EXPECT_TRUE(v2_2 <= v3_0);
+    EXPECT_TRUE(v3_0 >= v3_0b);
+    EXPECT_TRUE(v3_0 >= v2_2);
+}
+
+
 int main(int argc, char **argv) {
     ::testing::InitGoogleTest(&argc, argv);
     return RUN_ALL_TESTS();