Index: remoting/base/capabilities_unittest.cc |
diff --git a/remoting/base/capabilities_unittest.cc b/remoting/base/capabilities_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2b7d0fb45177b63c92ae53cf403e339589fa31a8 |
--- /dev/null |
+++ b/remoting/base/capabilities_unittest.cc |
@@ -0,0 +1,104 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/values.h" |
+#include "remoting/base/capabilities.h" |
+#include "remoting/proto/control.pb.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace remoting { |
+ |
+namespace { |
+ |
+const char kCapsAbc[] = "a b c"; |
+const char kCapsAz[] = "a z"; |
+const char kCapsXyz[] = "x y z"; |
+ |
+} // namespace |
+ |
+TEST(CapabilitiesTest, Empty) { |
+ // Verify that the set is empty after creation. |
+ Capabilities caps1; |
+ EXPECT_EQ(caps1.Size(), 0u); |
+ |
+ // Verify that an empty string produces an empty set. |
+ Capabilities caps2(""); |
+ EXPECT_EQ(caps2.Size(), 0u); |
+ |
+ // Verify that a string containing only spaces produces an empty set. |
+ Capabilities caps3(" "); |
+ EXPECT_EQ(caps3.Size(), 0u); |
+ |
+ // Verify that an empty set can be converted to a protobuf and back. |
+ EXPECT_TRUE(caps2.FromProtocolMessage(*caps1.ToProtocolMessage())); |
+ EXPECT_EQ(caps2.Size(), 0u); |
+ |
+ // Verify that an empty set can be converted to base::ListValue and back. |
+ EXPECT_TRUE(caps2.FromListValue(*caps1.ToListValue())); |
+ EXPECT_EQ(caps2.Size(), 0u); |
+} |
+ |
+TEST(CapabilitiesTest, NotEmpty) { |
+ Capabilities caps1(kCapsAbc); |
+ |
+ EXPECT_EQ(caps1.Size(), 3u); |
+ EXPECT_TRUE(caps1.HasCapability("a")); |
+ EXPECT_TRUE(caps1.HasCapability("b")); |
+ EXPECT_TRUE(caps1.HasCapability("c")); |
+ |
+ // Verify that the set can be converted to a protobuf and back. |
+ Capabilities caps2; |
+ EXPECT_TRUE(caps2.FromProtocolMessage(*caps1.ToProtocolMessage())); |
+ EXPECT_EQ(caps2.Size(), 3u); |
+ EXPECT_TRUE(caps2.HasCapability("a")); |
+ EXPECT_TRUE(caps2.HasCapability("b")); |
+ EXPECT_TRUE(caps2.HasCapability("c")); |
+ |
+ // Verify that the set can be converted to base::ListValue and back. |
+ EXPECT_TRUE(caps2.FromListValue(*caps1.ToListValue())); |
+ EXPECT_EQ(caps2.Size(), 3u); |
+ EXPECT_TRUE(caps2.HasCapability("a")); |
+ EXPECT_TRUE(caps2.HasCapability("b")); |
+ EXPECT_TRUE(caps2.HasCapability("c")); |
+} |
+ |
+TEST(CapabilitiesTest, Intersect) { |
+ Capabilities caps_abc(kCapsAbc); |
+ Capabilities caps_az(kCapsAz); |
+ Capabilities caps_empty; |
+ Capabilities caps_xyz(kCapsXyz); |
+ |
+ // Test intersection. |
+ Capabilities caps_a = caps_abc.Intersect(caps_az); |
+ EXPECT_EQ(caps_a.Size(), 1u); |
+ EXPECT_TRUE(caps_a.HasCapability("a")); |
+ |
+ // Test intersection with an empty set. |
+ EXPECT_EQ(caps_abc.Intersect(caps_empty).Size(), 0u); |
+ |
+ // Test intersection with a non-intersecting set. |
+ EXPECT_EQ(caps_abc.Intersect(caps_xyz).Size(), 0u); |
+} |
+ |
+TEST(CapabilitiesTest, BadListValue) { |
+ base::ListValue value1; |
+ value1.AppendString("a b"); |
+ |
+ Capabilities caps; |
+ EXPECT_FALSE(caps.FromListValue(value1)); |
+ |
+ base::ListValue value2; |
+ value2.AppendBoolean(false); |
+ EXPECT_FALSE(caps.FromListValue(value2)); |
+} |
+ |
+TEST(CapabilitiesTest, BadProtocolMessage) { |
+ protocol::Capabilities message1; |
+ *(message1.add_capability()) = "a b"; |
+ |
+ Capabilities caps; |
+ EXPECT_FALSE(caps.FromProtocolMessage(message1)); |
+} |
+ |
+} // namespace remoting |