Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / RequestedAuthnContext20Test.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "internal.h"
18 #include <saml/saml2/core/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
23
24 class RequestedAuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25     XMLCh* expectedComparison; 
26
27 public:
28     void setUp() {
29         expectedComparison = XMLString::transcode("exact"); 
30
31         singleElementFile = data_path + "saml2/core/impl/RequestedAuthnContext.xml";
32         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/RequestedAuthnContextOptionalAttributes.xml";
33         childElementsFile  = data_path + "saml2/core/impl/RequestedAuthnContextChildElements.xml";    
34         SAMLObjectBaseTestCase::setUp();
35     }
36     
37     void tearDown() {
38         XMLString::release(&expectedComparison);
39         SAMLObjectBaseTestCase::tearDown();
40     }
41
42     void testSingleElementUnmarshall() {
43         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44         RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
45         TS_ASSERT(rac !=nullptr);
46         TS_ASSERT(rac->getComparison()==nullptr);
47
48         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
49         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
50     }
51
52     void testSingleElementOptionalAttributesUnmarshall() {
53         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
54         RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
55         TS_ASSERT(rac!=nullptr);
56         assertEquals("Comparison attribute", expectedComparison, rac->getComparison());
57
58         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
59         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
60     }
61
62     void testChildElementsUnmarshall() {
63         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
64         RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
65         TS_ASSERT(rac !=nullptr);
66         TS_ASSERT(rac->getComparison()==nullptr);
67
68         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 3, rac->getAuthnContextClassRefs().size());
69         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
70     }
71
72     void testSingleElementMarshall() {
73         RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
74         assertEquals(expectedDOM, rac);
75     }
76
77     void testSingleElementOptionalAttributesMarshall() {
78         RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
79         rac->setComparison(expectedComparison);
80         assertEquals(expectedOptionalAttributesDOM, rac);
81     }
82
83     void testChildElementsMarshall() {
84         RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
85         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
86         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
87         rac->addNamespace(*ns);
88         rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
89         rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
90         rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
91         assertEquals(expectedChildElementsDOM, rac);
92         delete ns;
93     }
94
95 };