diff options
Diffstat (limited to 'messagebus/src/tests/simpleprotocol/simpleprotocol.cpp')
-rw-r--r-- | messagebus/src/tests/simpleprotocol/simpleprotocol.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp new file mode 100644 index 00000000000..eaf609a2be1 --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp @@ -0,0 +1,72 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("simpleprotocol_test"); + +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/messagebus/errorcode.h> +#include <vespa/messagebus/ireplyhandler.h> +#include <vespa/messagebus/network/identity.h> +#include <vespa/messagebus/routing/routingcontext.h> +#include <vespa/messagebus/testlib/receptor.h> +#include <vespa/messagebus/testlib/simpleprotocol.h> +#include <vespa/messagebus/testlib/simplemessage.h> +#include <vespa/messagebus/testlib/simplereply.h> +#include <vespa/messagebus/testlib/slobrok.h> +#include <vespa/messagebus/testlib/testserver.h> +#include <vespa/messagebus/vtag.h> + +using namespace mbus; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("simpleprotocol_test"); + + vespalib::Version version = 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<SimpleMessage&>(*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<SimpleMessage&>(*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<SimpleReply&>(*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<SimpleReply&>(*tmp).getValue() == "reply"); + } + TEST_DONE(); +} |