// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include #include #include #include #include #include using namespace mbus; TEST_SETUP(Test); int Test::Main() { TEST_INIT("simpleprotocol_test"); vespalib::Version version = vespalib::Vtag::currentVersion; SimpleProtocol protocol; EXPECT_TRUE(protocol.getName() == "Simple"); { // test protocol IRoutingPolicy::UP bogus = protocol.createPolicy("bogus", ""); EXPECT_TRUE(bogus.get() == 0); } TEST_FLUSH(); { // test SimpleMessage Message::UP msg(new SimpleMessage("test")); EXPECT_TRUE(!msg->isReply()); EXPECT_TRUE(msg->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(msg->getType() == SimpleProtocol::MESSAGE); EXPECT_TRUE(static_cast(*msg).getValue() == "test"); Blob b = protocol.encode(version, *msg); EXPECT_TRUE(b.size() > 0); Routable::UP tmp = protocol.decode(version, BlobRef(b)); ASSERT_TRUE(tmp.get() != 0); EXPECT_TRUE(!tmp->isReply()); EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(tmp->getType() == SimpleProtocol::MESSAGE); EXPECT_TRUE(static_cast(*tmp).getValue() == "test"); } TEST_FLUSH(); { // test SimpleReply Reply::UP reply(new SimpleReply("reply")); EXPECT_TRUE(reply->isReply()); EXPECT_TRUE(reply->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(reply->getType() == SimpleProtocol::REPLY); EXPECT_TRUE(static_cast(*reply).getValue() == "reply"); Blob b = protocol.encode(version, *reply); EXPECT_TRUE(b.size() > 0); Routable::UP tmp = protocol.decode(version, BlobRef(b)); ASSERT_TRUE(tmp.get() != 0); EXPECT_TRUE(tmp->isReply()); EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); EXPECT_TRUE(tmp->getType() == SimpleProtocol::REPLY); EXPECT_TRUE(static_cast(*tmp).getValue() == "reply"); } TEST_DONE(); }