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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 dbus::MessageReader reader(error_response.get()); | 550 dbus::MessageReader reader(error_response.get()); |
551 std::string error_message; | 551 std::string error_message; |
552 ASSERT_TRUE(reader.PopString(&error_message)); | 552 ASSERT_TRUE(reader.PopString(&error_message)); |
553 EXPECT_EQ(kErrorMessage, error_message); | 553 EXPECT_EQ(kErrorMessage, error_message); |
554 } | 554 } |
555 | 555 |
556 TEST(MessageTest, GetAndSetHeaders) { | 556 TEST(MessageTest, GetAndSetHeaders) { |
557 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 557 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
558 | 558 |
559 EXPECT_EQ("", message->GetDestination()); | 559 EXPECT_EQ("", message->GetDestination()); |
560 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); | 560 EXPECT_EQ(dbus::ObjectPath(std::string()), 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 EXPECT_TRUE(message->SetDestination("org.chromium.destination")); | 568 EXPECT_TRUE(message->SetDestination("org.chromium.destination")); |
569 EXPECT_TRUE(message->SetPath(dbus::ObjectPath("/org/chromium/path"))); | 569 EXPECT_TRUE(message->SetPath(dbus::ObjectPath("/org/chromium/path"))); |
570 EXPECT_TRUE(message->SetInterface("org.chromium.interface")); | 570 EXPECT_TRUE(message->SetInterface("org.chromium.interface")); |
571 EXPECT_TRUE(message->SetMember("member")); | 571 EXPECT_TRUE(message->SetMember("member")); |
572 EXPECT_TRUE(message->SetErrorName("org.chromium.error")); | 572 EXPECT_TRUE(message->SetErrorName("org.chromium.error")); |
573 EXPECT_TRUE(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 | 586 |
587 TEST(MessageTest, SetInvalidHeaders) { | 587 TEST(MessageTest, SetInvalidHeaders) { |
588 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 588 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
589 EXPECT_EQ("", message->GetDestination()); | 589 EXPECT_EQ("", message->GetDestination()); |
590 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); | 590 EXPECT_EQ(dbus::ObjectPath(std::string()), message->GetPath()); |
591 EXPECT_EQ("", message->GetInterface()); | 591 EXPECT_EQ("", message->GetInterface()); |
592 EXPECT_EQ("", message->GetMember()); | 592 EXPECT_EQ("", message->GetMember()); |
593 EXPECT_EQ("", message->GetErrorName()); | 593 EXPECT_EQ("", message->GetErrorName()); |
594 EXPECT_EQ("", message->GetSender()); | 594 EXPECT_EQ("", message->GetSender()); |
595 | 595 |
596 // Empty element between periods. | 596 // Empty element between periods. |
597 EXPECT_FALSE(message->SetDestination("org..chromium")); | 597 EXPECT_FALSE(message->SetDestination("org..chromium")); |
598 // Trailing '/' is only allowed for the root path. | 598 // Trailing '/' is only allowed for the root path. |
599 EXPECT_FALSE(message->SetPath(dbus::ObjectPath("/org/chromium/"))); | 599 EXPECT_FALSE(message->SetPath(dbus::ObjectPath("/org/chromium/"))); |
600 // Interface name cannot contain '/'. | 600 // Interface name cannot contain '/'. |
601 EXPECT_FALSE(message->SetInterface("org/chromium/interface")); | 601 EXPECT_FALSE(message->SetInterface("org/chromium/interface")); |
602 // Member name cannot begin with a digit. | 602 // Member name cannot begin with a digit. |
603 EXPECT_FALSE(message->SetMember("1member")); | 603 EXPECT_FALSE(message->SetMember("1member")); |
604 // Error name cannot begin with a period. | 604 // Error name cannot begin with a period. |
605 EXPECT_FALSE(message->SetErrorName(".org.chromium.error")); | 605 EXPECT_FALSE(message->SetErrorName(".org.chromium.error")); |
606 // Disallowed characters. | 606 // Disallowed characters. |
607 EXPECT_FALSE(message->SetSender("?!#*")); | 607 EXPECT_FALSE(message->SetSender("?!#*")); |
608 | 608 |
609 EXPECT_EQ("", message->GetDestination()); | 609 EXPECT_EQ("", message->GetDestination()); |
610 EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); | 610 EXPECT_EQ(dbus::ObjectPath(std::string()), message->GetPath()); |
611 EXPECT_EQ("", message->GetInterface()); | 611 EXPECT_EQ("", message->GetInterface()); |
612 EXPECT_EQ("", message->GetMember()); | 612 EXPECT_EQ("", message->GetMember()); |
613 EXPECT_EQ("", message->GetErrorName()); | 613 EXPECT_EQ("", message->GetErrorName()); |
614 EXPECT_EQ("", message->GetSender()); | 614 EXPECT_EQ("", message->GetSender()); |
615 } | 615 } |
616 | 616 |
617 TEST(MessageTest, ToString_LongString) { | 617 TEST(MessageTest, ToString_LongString) { |
618 const std::string kLongString(1000, 'o'); | 618 const std::string kLongString(1000, 'o'); |
619 | 619 |
620 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 620 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
621 dbus::MessageWriter writer(message.get()); | 621 dbus::MessageWriter writer(message.get()); |
622 writer.AppendString(kLongString); | 622 writer.AppendString(kLongString); |
623 | 623 |
624 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" | 624 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" |
625 "signature: s\n\n" | 625 "signature: s\n\n" |
626 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo" | 626 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo" |
627 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... " | 627 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... " |
628 "(1000 bytes in total)\"\n", | 628 "(1000 bytes in total)\"\n", |
629 message->ToString()); | 629 message->ToString()); |
630 } | 630 } |
OLD | NEW |