From 88027d1b5e80e35f34c5ee733c2ff6908fe043d7 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 10 May 2006 18:04:21 +0000 Subject: [PATCH] More unit tests. --- samltest/.gitignore | 1 + .../data/saml1/core/impl/AdviceWithChildren.xml | Bin 470 -> 596 bytes samltest/internal.h | 1 + samltest/saml1/core/impl/.gitignore | 1 + samltest/saml1/core/impl/ActionTest.h | 10 +-- samltest/saml1/core/impl/AdviceTest.h | 73 +++++++++++++++++++++ .../saml1/core/impl/AssertionIDReferenceTest.h | 61 +++++++++++++++++ samltest/samltest.vcproj | 52 +++++++++++++++ 8 files changed, 192 insertions(+), 7 deletions(-) create mode 100644 samltest/saml1/core/impl/.gitignore create mode 100644 samltest/saml1/core/impl/AdviceTest.h create mode 100644 samltest/saml1/core/impl/AssertionIDReferenceTest.h diff --git a/samltest/.gitignore b/samltest/.gitignore index 994c81d..39a97ca 100644 --- a/samltest/.gitignore +++ b/samltest/.gitignore @@ -1,2 +1,3 @@ /Debug /*.user +/*.cpp diff --git a/samltest/data/saml1/core/impl/AdviceWithChildren.xml b/samltest/data/saml1/core/impl/AdviceWithChildren.xml index eeab16c0b4fcc28af50017b1e158ee79cd380c1c..a341c10c8395b969db39459ed4750ebb9cc4bc60 100644 GIT binary patch delta 122 zcmcb{e1&C0CF8`0V(GRFN(}J~h73jw#tbG5rVM5b<_s1LmOxQn1}+9qhGHNrWk?0G z@_?)ohD0D;!T{1`2vlVbBy|}KfO>Vo{16~%%wPpJ%?c=Pzz_v7X)+h1^5of!)&Ni| B6OaG^ delta 11 Scmcb@a*cUICFA7pjIjV7C action(ActionBuilder::buildAction()); - assertEquals(expectedDOM, action.get()); + assertEquals(expectedDOM, ActionBuilder::buildAction()); } void testSingleElementOptionalAttributesMarshall() { - auto_ptr action(ActionBuilder::buildAction()); + Action* action=ActionBuilder::buildAction(); action->setNamespace(expectedNamespace); action->setValue(expectedContents); - assertEquals(expectedOptionalAttributesDOM, action.get()); + assertEquals(expectedOptionalAttributesDOM, action); } }; diff --git a/samltest/saml1/core/impl/AdviceTest.h b/samltest/saml1/core/impl/AdviceTest.h new file mode 100644 index 0000000..50d5eed --- /dev/null +++ b/samltest/saml1/core/impl/AdviceTest.h @@ -0,0 +1,73 @@ +/* + * 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 AdviceTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { + XMLCh* AssertionID; + XMLCh* IssueInstant; + +public: + void setUp() { + AssertionID=XMLString::transcode("_123456789"); + IssueInstant=XMLString::transcode("1971-03-19T13:23:00Z"); + singleElementFile = data_path + "saml1/core/impl/singleAdvice.xml"; + childElementsFile = data_path + "saml1/core/impl/AdviceWithChildren.xml"; + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + XMLString::release(&AssertionID); + XMLString::release(&IssueInstant); + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + Advice* advice = dynamic_cast(xo.get()); + TS_ASSERT(advice!=NULL); + TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 0, advice->getAssertionIDReferences().size()); + TSM_ASSERT_EQUALS("Number of child Assertion elements", 0, advice->getAssertions().size()); + } + + void testChildElementsUnmarshall() { + auto_ptr xo(unmarshallElement(childElementsFile)); + Advice* advice = dynamic_cast(xo.get()); + TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 2, advice->getAssertionIDReferences().size()); + TSM_ASSERT_EQUALS("Number of child Assertion elements", 1, advice->getAssertions().size()); + } + + void testSingleElementMarshall() { + assertEquals(expectedDOM, AdviceBuilder::buildAdvice()); + } + + void testChildElementsMarshall() { + Advice* advice=AdviceBuilder::buildAdvice(); + + advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference()); + Assertion* assertion=AssertionBuilder::buildAssertion(); + assertion->setAssertionID(AssertionID); + assertion->setIssueInstant(IssueInstant); + advice->getAssertions().push_back(assertion); + advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference()); + + assertEquals(expectedChildElementsDOM, advice); + } + +}; diff --git a/samltest/saml1/core/impl/AssertionIDReferenceTest.h b/samltest/saml1/core/impl/AssertionIDReferenceTest.h new file mode 100644 index 0000000..e7ca8c5 --- /dev/null +++ b/samltest/saml1/core/impl/AssertionIDReferenceTest.h @@ -0,0 +1,61 @@ +/* + * 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 AssertionIDReferenceTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { + XMLCh* expectedNCName; + +public: + void setUp() { + singleElementFile = data_path + "saml1/core/impl/singleAssertionIDReference.xml"; + singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionIDReferenceContents.xml"; + expectedNCName = XMLString::transcode("NibbleAHappyWarthog"); + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + XMLString::release(&expectedNCName); + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + AssertionIDReference* assertionIDReference = dynamic_cast(xo.get()); + TS_ASSERT(assertionIDReference!=NULL); + TSM_ASSERT("NCName present", assertionIDReference->getReference()==NULL); + } + + void testSingleElementOptionalAttributesUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementOptionalAttributesFile)); + AssertionIDReference* assertionIDReference = dynamic_cast(xo.get()); + TSM_ASSERT_SAME_DATA("NCName ", expectedNCName, assertionIDReference->getReference(), XMLString::stringLen(expectedNCName)); + } + + void testSingleElementMarshall() { + assertEquals(expectedDOM, AssertionIDReferenceBuilder::buildAssertionIDReference()); + } + + void testSingleElementOptionalAttributesMarshall() { + AssertionIDReference* assertionIDReference=AssertionIDReferenceBuilder::buildAssertionIDReference(); + assertionIDReference->setReference(expectedNCName); + assertEquals(expectedOptionalAttributesDOM, assertionIDReference); + } + +}; diff --git a/samltest/samltest.vcproj b/samltest/samltest.vcproj index bca3280..7e39b7f 100644 --- a/samltest/samltest.vcproj +++ b/samltest/samltest.vcproj @@ -195,6 +195,14 @@ RelativePath=".\saml1\core\impl\ActionTest.cpp" > + + + + @@ -261,6 +269,50 @@ /> + + + + + + + + + + + + + + + + -- 2.1.4