summaryrefslogtreecommitdiff
path: root/cpp/common/framing/test
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2006-09-19 22:06:50 +0000
committerRafael H. Schloming <rhs@apache.org>2006-09-19 22:06:50 +0000
commit913489deb2ee9dbf44455de5f407ddaf4bd8c540 (patch)
tree7ea442d6867d0076f1c9ea4f4265664059e7aff5 /cpp/common/framing/test
downloadqpid-python-913489deb2ee9dbf44455de5f407ddaf4bd8c540.tar.gz
Import of qpid from etp:
URL: https://etp.108.redhat.com/svn/etp/trunk/blaze Repository Root: https://etp.108.redhat.com/svn/etp Repository UUID: 06e15bec-b515-0410-bef0-cc27a458cf48 Revision: 608 git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@447994 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/common/framing/test')
-rw-r--r--cpp/common/framing/test/BodyHandlerTest.cpp107
-rw-r--r--cpp/common/framing/test/Makefile21
-rw-r--r--cpp/common/framing/test/field_table_test.cpp55
-rw-r--r--cpp/common/framing/test/framing_test.cpp147
-rw-r--r--cpp/common/framing/test/header_test.cpp144
5 files changed, 474 insertions, 0 deletions
diff --git a/cpp/common/framing/test/BodyHandlerTest.cpp b/cpp/common/framing/test/BodyHandlerTest.cpp
new file mode 100644
index 0000000000..94038d9a6c
--- /dev/null
+++ b/cpp/common/framing/test/BodyHandlerTest.cpp
@@ -0,0 +1,107 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <iostream>
+#include "amqp_framing.h"
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace qpid::framing;
+
+class BodyHandlerTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(BodyHandlerTest);
+ CPPUNIT_TEST(testMethod);
+ CPPUNIT_TEST(testHeader);
+ CPPUNIT_TEST(testContent);
+ CPPUNIT_TEST(testHeartbeat);
+ CPPUNIT_TEST_SUITE_END();
+private:
+
+ class TestBodyHandler : public BodyHandler{
+ AMQMethodBody* const method;
+ AMQHeaderBody* const header;
+ AMQContentBody* const content;
+ AMQHeartbeatBody* const heartbeat;
+
+ public:
+
+ TestBodyHandler(AMQMethodBody* _method) : method(_method), header(0), content(0), heartbeat(0){}
+ TestBodyHandler(AMQHeaderBody* _header) : method(0), header(_header), content(0), heartbeat(0){}
+ TestBodyHandler(AMQContentBody* _content) : method(0), header(0), content(_content), heartbeat(0){}
+ TestBodyHandler(AMQHeartbeatBody* _heartbeat) : method(0), header(0), content(0), heartbeat(_heartbeat){}
+
+ virtual void handleMethod(AMQMethodBody::shared_ptr body){
+ CPPUNIT_ASSERT(method);
+ CPPUNIT_ASSERT_EQUAL(method, body.get());
+ }
+ virtual void handleHeader(AMQHeaderBody::shared_ptr body){
+ CPPUNIT_ASSERT(header);
+ CPPUNIT_ASSERT_EQUAL(header, body.get());
+ }
+ virtual void handleContent(AMQContentBody::shared_ptr body){
+ CPPUNIT_ASSERT(content);
+ CPPUNIT_ASSERT_EQUAL(content, body.get());
+ }
+ virtual void handleHeartbeat(AMQHeartbeatBody::shared_ptr body){
+ CPPUNIT_ASSERT(heartbeat);
+ CPPUNIT_ASSERT_EQUAL(heartbeat, body.get());
+ }
+ };
+
+public:
+
+ void testMethod()
+ {
+ AMQMethodBody* method = new QueueDeclareBody();
+ AMQFrame frame(0, method);
+ TestBodyHandler handler(method);
+ handler.handleBody(frame.getBody());
+ }
+
+ void testHeader()
+ {
+ AMQHeaderBody* header = new AMQHeaderBody();
+ AMQFrame frame(0, header);
+ TestBodyHandler handler(header);
+ handler.handleBody(frame.getBody());
+ }
+
+ void testContent()
+ {
+ AMQContentBody* content = new AMQContentBody();
+ AMQFrame frame(0, content);
+ TestBodyHandler handler(content);
+ handler.handleBody(frame.getBody());
+ }
+
+ void testHeartbeat()
+ {
+ AMQHeartbeatBody* heartbeat = new AMQHeartbeatBody();
+ AMQFrame frame(0, heartbeat);
+ TestBodyHandler handler(heartbeat);
+ handler.handleBody(frame.getBody());
+ }
+};
+
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(BodyHandlerTest);
+
diff --git a/cpp/common/framing/test/Makefile b/cpp/common/framing/test/Makefile
new file mode 100644
index 0000000000..487b8d537b
--- /dev/null
+++ b/cpp/common/framing/test/Makefile
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2006 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+QPID_HOME = ../../../..
+LDLIBS=-lapr-1 -lcppunit $(COMMON_LIB)
+INCLUDES=$(TEST_INCLUDES) -I ../generated
+include ${QPID_HOME}/cpp/test_plugins.mk
+
diff --git a/cpp/common/framing/test/field_table_test.cpp b/cpp/common/framing/test/field_table_test.cpp
new file mode 100644
index 0000000000..48332e05bc
--- /dev/null
+++ b/cpp/common/framing/test/field_table_test.cpp
@@ -0,0 +1,55 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <iostream>
+#include "amqp_framing.h"
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace qpid::framing;
+
+class FieldTableTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(FieldTableTest);
+ CPPUNIT_TEST(testMe);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ void testMe()
+ {
+ FieldTable ft;
+ ft.setString("A", "BCDE");
+ CPPUNIT_ASSERT_EQUAL(std::string("BCDE"), ft.getString("A"));
+
+ Buffer buffer(100);
+ buffer.putFieldTable(ft);
+ buffer.flip();
+ FieldTable ft2;
+ buffer.getFieldTable(ft2);
+ CPPUNIT_ASSERT_EQUAL(std::string("BCDE"), ft2.getString("A"));
+
+ }
+};
+
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(FieldTableTest);
+
diff --git a/cpp/common/framing/test/framing_test.cpp b/cpp/common/framing/test/framing_test.cpp
new file mode 100644
index 0000000000..1978c2cbed
--- /dev/null
+++ b/cpp/common/framing/test/framing_test.cpp
@@ -0,0 +1,147 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "amqp_framing.h"
+#include "ConnectionRedirectBody.h"
+#include <iostream>
+#include <sstream>
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <typeinfo>
+
+using namespace qpid::framing;
+
+// TODO aconway 2006-09-12: Why do we need explicit qpid::framing:: below?
+
+template <class T>
+std::string tostring(const T& x)
+{
+ std::ostringstream out;
+ out << x;
+ return out.str();
+}
+
+class FramingTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(FramingTest);
+ CPPUNIT_TEST(testBasicQosBody);
+ CPPUNIT_TEST(testConnectionSecureBody);
+ CPPUNIT_TEST(testConnectionRedirectBody);
+ CPPUNIT_TEST(testAccessRequestBody);
+ CPPUNIT_TEST(testBasicConsumeBody);
+ CPPUNIT_TEST(ConnectionRedirectBody);
+ CPPUNIT_TEST(BasicConsumeOkBody);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ Buffer buffer;
+
+ public:
+
+ FramingTest() : buffer(100) {}
+
+ void testBasicQosBody()
+ {
+ BasicQosBody in(0xCAFEBABE, 0xABBA, true);
+ in.encodeContent(buffer);
+ buffer.flip();
+ BasicQosBody out;
+ out.decodeContent(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+ void testConnectionSecureBody()
+ {
+ std::string s = "security credential";
+ ConnectionSecureBody in(s);
+ in.encodeContent(buffer);
+ buffer.flip();
+ ConnectionSecureBody out;
+ out.decodeContent(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+ void testConnectionRedirectBody()
+ {
+ std::string a = "hostA";
+ std::string b = "hostB";
+ qpid::framing::ConnectionRedirectBody in(a, b);
+ in.encodeContent(buffer);
+ buffer.flip();
+ qpid::framing::ConnectionRedirectBody out;
+ out.decodeContent(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+ void testAccessRequestBody()
+ {
+ std::string s = "text";
+ AccessRequestBody in(s, true, false, true, false, true);
+ in.encodeContent(buffer);
+ buffer.flip();
+ AccessRequestBody out;
+ out.decodeContent(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+ void testBasicConsumeBody()
+ {
+ std::string q = "queue";
+ std::string t = "tag";
+ BasicConsumeBody in(0, q, t, false, true, false, false);
+ in.encodeContent(buffer);
+ buffer.flip();
+ BasicConsumeBody out;
+ out.decodeContent(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+
+ void ConnectionRedirectBody()
+ {
+ std::string a = "hostA";
+ std::string b = "hostB";
+ AMQFrame in(999, new qpid::framing::ConnectionRedirectBody(a, b));
+ in.encode(buffer);
+ buffer.flip();
+ AMQFrame out;
+ out.decode(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+
+ void BasicConsumeOkBody()
+ {
+ std::string s = "hostA";
+ AMQFrame in(999, new qpid::framing::BasicConsumeOkBody(s));
+ in.encode(buffer);
+ buffer.flip();
+ AMQFrame out;
+ for(int i = 0; i < 5; i++){
+ out.decode(buffer);
+ CPPUNIT_ASSERT_EQUAL(tostring(in), tostring(out));
+ }
+ }
+};
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(FramingTest);
+
+
+
diff --git a/cpp/common/framing/test/header_test.cpp b/cpp/common/framing/test/header_test.cpp
new file mode 100644
index 0000000000..0ff6d47d57
--- /dev/null
+++ b/cpp/common/framing/test/header_test.cpp
@@ -0,0 +1,144 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <iostream>
+#include "amqp_framing.h"
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace qpid::framing;
+
+class HeaderTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(HeaderTest);
+ CPPUNIT_TEST(testGenericProperties);
+ CPPUNIT_TEST(testAllSpecificProperties);
+ CPPUNIT_TEST(testSomeSpecificProperties);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ // TODO aconway 2006-09-12: Need more detailed tests,
+ // need tests to assert something!
+ //
+ void testGenericProperties()
+ {
+ AMQHeaderBody body(BASIC);
+ dynamic_cast<BasicHeaderProperties*>(body.getProperties())->getHeaders().setString("A", "BCDE");
+ Buffer buffer(100);
+
+ body.encode(buffer);
+ buffer.flip();
+ AMQHeaderBody body2;
+ body2.decode(buffer, body.size());
+ BasicHeaderProperties* props =
+ dynamic_cast<BasicHeaderProperties*>(body2.getProperties());
+ CPPUNIT_ASSERT_EQUAL(std::string("BCDE"),
+ props->getHeaders().getString("A"));
+ }
+
+ void testAllSpecificProperties(){
+ string contentType("text/html");
+ string contentEncoding("UTF8");
+ u_int8_t deliveryMode(2);
+ u_int8_t priority(3);
+ string correlationId("abc");
+ string replyTo("no-address");
+ string expiration("why is this a string?");
+ string messageId("xyz");
+ u_int64_t timestamp(0xabcd);
+ string type("eh?");
+ string userId("guest");
+ string appId("just testing");
+ string clusterId("no clustering required");
+
+ AMQHeaderBody body(BASIC);
+ BasicHeaderProperties* properties =
+ dynamic_cast<BasicHeaderProperties*>(body.getProperties());
+ properties->setContentType(contentType);
+ properties->getHeaders().setString("A", "BCDE");
+ properties->setDeliveryMode(deliveryMode);
+ properties->setPriority(priority);
+ properties->setCorrelationId(correlationId);
+ properties->setReplyTo(replyTo);
+ properties->setExpiration(expiration);
+ properties->setMessageId(messageId);
+ properties->setTimestamp(timestamp);
+ properties->setType(type);
+ properties->setUserId(userId);
+ properties->setAppId(appId);
+ properties->setClusterId(clusterId);
+
+ Buffer buffer(10000);
+ body.encode(buffer);
+ buffer.flip();
+ AMQHeaderBody temp;
+ temp.decode(buffer, body.size());
+ properties = dynamic_cast<BasicHeaderProperties*>(temp.getProperties());
+
+ CPPUNIT_ASSERT_EQUAL(contentType, properties->getContentType());
+ CPPUNIT_ASSERT_EQUAL(std::string("BCDE"), properties->getHeaders().getString("A"));
+ CPPUNIT_ASSERT_EQUAL(deliveryMode, properties->getDeliveryMode());
+ CPPUNIT_ASSERT_EQUAL(priority, properties->getPriority());
+ CPPUNIT_ASSERT_EQUAL(correlationId, properties->getCorrelationId());
+ CPPUNIT_ASSERT_EQUAL(replyTo, properties->getReplyTo());
+ CPPUNIT_ASSERT_EQUAL(expiration, properties->getExpiration());
+ CPPUNIT_ASSERT_EQUAL(messageId, properties->getMessageId());
+ CPPUNIT_ASSERT_EQUAL(timestamp, properties->getTimestamp());
+ CPPUNIT_ASSERT_EQUAL(type, properties->getType());
+ CPPUNIT_ASSERT_EQUAL(userId, properties->getUserId());
+ CPPUNIT_ASSERT_EQUAL(appId, properties->getAppId());
+ CPPUNIT_ASSERT_EQUAL(clusterId, properties->getClusterId());
+ }
+
+ void testSomeSpecificProperties(){
+ string contentType("application/octet-stream");
+ u_int8_t deliveryMode(5);
+ u_int8_t priority(6);
+ string expiration("Z");
+ u_int64_t timestamp(0xabe4a34a);
+
+ AMQHeaderBody body(BASIC);
+ BasicHeaderProperties* properties =
+ dynamic_cast<BasicHeaderProperties*>(body.getProperties());
+ properties->setContentType(contentType);
+ properties->setDeliveryMode(deliveryMode);
+ properties->setPriority(priority);
+ properties->setExpiration(expiration);
+ properties->setTimestamp(timestamp);
+
+ Buffer buffer(100);
+ body.encode(buffer);
+ buffer.flip();
+ AMQHeaderBody temp;
+ temp.decode(buffer, body.size());
+ properties = dynamic_cast<BasicHeaderProperties*>(temp.getProperties());
+
+ CPPUNIT_ASSERT_EQUAL(contentType, properties->getContentType());
+ CPPUNIT_ASSERT_EQUAL((int) deliveryMode, (int) properties->getDeliveryMode());
+ CPPUNIT_ASSERT_EQUAL((int) priority, (int) properties->getPriority());
+ CPPUNIT_ASSERT_EQUAL(expiration, properties->getExpiration());
+ CPPUNIT_ASSERT_EQUAL(timestamp, properties->getTimestamp());
+ }
+};
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(HeaderTest);
+