From 169c334402b6ed47f4cdc4e066ba4a60c5323c46 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Thu, 11 May 2006 03:36:11 +0000 Subject: [PATCH] New tests --- samltest/saml1/core/impl/AttributeDesignatorTest.h | 66 +++++++++++++++++++++ samltest/saml1/core/impl/AttributeStatementTest.h | 69 ++++++++++++++++++++++ samltest/samltest.vcproj | 58 +++++++++++++++++- 3 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 samltest/saml1/core/impl/AttributeDesignatorTest.h create mode 100644 samltest/saml1/core/impl/AttributeStatementTest.h diff --git a/samltest/saml1/core/impl/AttributeDesignatorTest.h b/samltest/saml1/core/impl/AttributeDesignatorTest.h new file mode 100644 index 0000000..b6f005b --- /dev/null +++ b/samltest/saml1/core/impl/AttributeDesignatorTest.h @@ -0,0 +1,66 @@ +/* + * Copyright 2001-2006 Internet2 + * + * 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 "internal.h" +#include + +using namespace opensaml::saml1; + +class AttributeDesignatorTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { + XMLCh* expectedAttributeName; + XMLCh* expectedAttributeNamespace; + +public: + void setUp() { + expectedAttributeName=XMLString::transcode("AttributeName"); + expectedAttributeNamespace=XMLString::transcode("namespace"); + singleElementFile = data_path + "saml1/core/impl/singleAttributeDesignator.xml"; + singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAttributeDesignatorAttributes.xml"; + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + XMLString::release(&expectedAttributeName); + XMLString::release(&expectedAttributeNamespace); + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + AttributeDesignator& ad = dynamic_cast(*xo.get()); + TSM_ASSERT("AttributeName", ad.getAttributeName()==NULL); + TSM_ASSERT("AttributeNamespace", ad.getAttributeNamespace()==NULL); + } + + void testSingleElementOptionalAttributesUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementOptionalAttributesFile)); + AttributeDesignator& ad = dynamic_cast(*xo.get()); + TSM_ASSERT_SAME_DATA("AttributeName", expectedAttributeName, ad.getAttributeName(), XMLString::stringLen(expectedAttributeName)); + TSM_ASSERT_SAME_DATA("AttributeNamespace", expectedAttributeNamespace, ad.getAttributeNamespace(), XMLString::stringLen(expectedAttributeNamespace)); + } + + void testSingleElementMarshall() { + assertEquals(expectedDOM, AttributeDesignatorBuilder::buildAttributeDesignator()); + } + + void testSingleElementOptionalAttributesMarshall() { + AttributeDesignator* ad=AttributeDesignatorBuilder::buildAttributeDesignator(); + ad->setAttributeName(expectedAttributeName); + ad->setAttributeNamespace(expectedAttributeNamespace); + assertEquals(expectedOptionalAttributesDOM, ad); + } + +}; diff --git a/samltest/saml1/core/impl/AttributeStatementTest.h b/samltest/saml1/core/impl/AttributeStatementTest.h new file mode 100644 index 0000000..3b6c054 --- /dev/null +++ b/samltest/saml1/core/impl/AttributeStatementTest.h @@ -0,0 +1,69 @@ +/* + * Copyright 2001-2006 Internet2 + * + * 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 "internal.h" +#include + +using namespace opensaml::saml1; + +class AttributeStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { +public: + void setUp() { + singleElementFile = data_path + "saml1/core/impl/singleAttributeStatement.xml"; + childElementsFile = data_path + "saml1/core/impl/AttributeStatementWithChildren.xml"; + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + AttributeStatement& as = dynamic_cast(*xo.get()); + TSM_ASSERT(" element present", as.getSubject()==NULL); + TSM_ASSERT_EQUALS("Non zero count of elements", 0, as.getAttributes().size()); + } + + void testChildElementsUnmarshall() { + auto_ptr xo(unmarshallElement(childElementsFile)); + AttributeStatement& as = dynamic_cast(*xo.get()); + TSM_ASSERT(" element not present", as.getSubject()!=NULL); + TSM_ASSERT_EQUALS("count of elements", 5, as.getAttributes().size()); + + as.getAttributes().erase(as.getAttributes().begin()); + TSM_ASSERT_EQUALS("count of elements after single remove", 4, as.getAttributes().size()); + + as.getAttributes().erase(as.getAttributes().begin()); + as.getAttributes().erase(as.getAttributes().begin()+1); + TSM_ASSERT_EQUALS("count of elements after double remove", 2, as.getAttributes().size()); + } + + void testSingleElementMarshall() { + assertEquals(expectedDOM, AttributeStatementBuilder::buildAttributeStatement()); + } + + void testChildElementsMarshall() { + AttributeStatement* as=AttributeStatementBuilder::buildAttributeStatement(); + as->setSubject(SubjectBuilder::buildSubject()); + for (int i = 0; i < 5; i++) { + as->getAttributes().push_back(AttributeBuilder::buildAttribute()); + } + + assertEquals(expectedChildElementsDOM, as); + } + +}; diff --git a/samltest/samltest.vcproj b/samltest/samltest.vcproj index 5c4b19d..09f17b3 100644 --- a/samltest/samltest.vcproj +++ b/samltest/samltest.vcproj @@ -207,6 +207,14 @@ RelativePath=".\saml1\core\impl\AssertionTest.cpp" > + + + + @@ -281,7 +289,7 @@ > @@ -290,7 +298,7 @@ > @@ -303,6 +311,50 @@ > + + + + + + + + + + + + + + + + @@ -318,7 +370,7 @@