OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "dbus/message.h" | 5 #include "dbus/message.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/eintr_wrapper.h" | 8 #include "base/eintr_wrapper.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 | 558 |
559 EXPECT_EQ("", message->GetDestination()); | 559 EXPECT_EQ("", message->GetDestination()); |
560 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); | 560 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); |
561 EXPECT_EQ("", message->GetInterface()); | 561 EXPECT_EQ("", message->GetInterface()); |
562 EXPECT_EQ("", message->GetMember()); | 562 EXPECT_EQ("", message->GetMember()); |
563 EXPECT_EQ("", message->GetErrorName()); | 563 EXPECT_EQ("", message->GetErrorName()); |
564 EXPECT_EQ("", message->GetSender()); | 564 EXPECT_EQ("", message->GetSender()); |
565 EXPECT_EQ(0U, message->GetSerial()); | 565 EXPECT_EQ(0U, message->GetSerial()); |
566 EXPECT_EQ(0U, message->GetReplySerial()); | 566 EXPECT_EQ(0U, message->GetReplySerial()); |
567 | 567 |
568 message->SetDestination("org.chromium.destination"); | 568 EXPECT_TRUE(message->SetDestination("org.chromium.destination")); |
569 message->SetPath(dbus::ObjectPath("/org/chromium/path")); | 569 EXPECT_TRUE(message->SetPath(dbus::ObjectPath("/org/chromium/path"))); |
570 message->SetInterface("org.chromium.interface"); | 570 EXPECT_TRUE(message->SetInterface("org.chromium.interface")); |
571 message->SetMember("member"); | 571 EXPECT_TRUE(message->SetMember("member")); |
572 message->SetErrorName("org.chromium.error"); | 572 EXPECT_TRUE(message->SetErrorName("org.chromium.error")); |
573 message->SetSender(":1.2"); | 573 EXPECT_TRUE(message->SetSender(":1.2")); |
574 message->SetSerial(123); | 574 message->SetSerial(123); |
575 message->SetReplySerial(456); | 575 message->SetReplySerial(456); |
576 | 576 |
577 EXPECT_EQ("org.chromium.destination", message->GetDestination()); | 577 EXPECT_EQ("org.chromium.destination", message->GetDestination()); |
578 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); | 578 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); |
579 EXPECT_EQ("org.chromium.interface", message->GetInterface()); | 579 EXPECT_EQ("org.chromium.interface", message->GetInterface()); |
580 EXPECT_EQ("member", message->GetMember()); | 580 EXPECT_EQ("member", message->GetMember()); |
581 EXPECT_EQ("org.chromium.error", message->GetErrorName()); | 581 EXPECT_EQ("org.chromium.error", message->GetErrorName()); |
582 EXPECT_EQ(":1.2", message->GetSender()); | 582 EXPECT_EQ(":1.2", message->GetSender()); |
583 EXPECT_EQ(123U, message->GetSerial()); | 583 EXPECT_EQ(123U, message->GetSerial()); |
584 EXPECT_EQ(456U, message->GetReplySerial()); | 584 EXPECT_EQ(456U, message->GetReplySerial()); |
585 } | 585 } |
| 586 |
| 587 TEST(MessageTest, SetInvalidHeaders) { |
| 588 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 589 EXPECT_EQ("", message->GetDestination()); |
| 590 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); |
| 591 EXPECT_EQ("", message->GetInterface()); |
| 592 EXPECT_EQ("", message->GetMember()); |
| 593 EXPECT_EQ("", message->GetErrorName()); |
| 594 EXPECT_EQ("", message->GetSender()); |
| 595 |
| 596 // Empty element between periods. |
| 597 EXPECT_FALSE(message->SetDestination("org..chromium")); |
| 598 // Trailing '/' is only allowed for the root path. |
| 599 EXPECT_FALSE(message->SetPath(dbus::ObjectPath("/org/chromium/"))); |
| 600 // Interface name cannot contain '/'. |
| 601 EXPECT_FALSE(message->SetInterface("org/chromium/interface")); |
| 602 // Member name cannot begin with a digit. |
| 603 EXPECT_FALSE(message->SetMember("1member")); |
| 604 // Error name cannot begin with a period. |
| 605 EXPECT_FALSE(message->SetErrorName(".org.chromium.error")); |
| 606 // Disallowed characters. |
| 607 EXPECT_FALSE(message->SetSender("?!#*")); |
| 608 |
| 609 EXPECT_EQ("", message->GetDestination()); |
| 610 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); |
| 611 EXPECT_EQ("", message->GetInterface()); |
| 612 EXPECT_EQ("", message->GetMember()); |
| 613 EXPECT_EQ("", message->GetErrorName()); |
| 614 EXPECT_EQ("", message->GetSender()); |
| 615 } |
OLD | NEW |