Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / NewEncryptedID20Test.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 <xmltooling/encryption/Encryption.h>
20 #include <xmltooling/util/XMLConstants.h>
21
22 using namespace opensaml;
23 using namespace opensaml::saml2p;
24 using namespace xmlencryption;
25
26 class NewEncryptedID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27
28 public:
29     void setUp() {
30         singleElementFile = data_path + "saml2/core/impl/NewEncryptedID.xml";
31         childElementsFile  = data_path + "saml2/core/impl/NewEncryptedIDChildElements.xml";    
32         SAMLObjectBaseTestCase::setUp();
33     }
34     
35     void tearDown() {
36         SAMLObjectBaseTestCase::tearDown();
37     }
38
39     void testSingleElementUnmarshall() {
40         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
41         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
42         TS_ASSERT(encID!=nullptr);
43         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()==nullptr);
44         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 0, encID->getEncryptedKeys().size());
45     }
46
47     void testChildElementsUnmarshall() {
48         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
49         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
50         TS_ASSERT(encID!=nullptr);
51         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()!=nullptr);
52         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 2, encID->getEncryptedKeys().size());
53     }
54
55     void testSingleElementMarshall() {
56         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
57         assertEquals(expectedDOM, encID);
58     }
59
60     void testChildElementsMarshall() {
61         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
62         // Do this just so don't have to redeclare the xenc namespace prefix on every child element in the control XML file
63         Namespace* ns = new Namespace(xmlconstants::XMLENC_NS, xmlconstants::XMLENC_PREFIX);
64         encID->addNamespace(*ns);
65         encID->setEncryptedData(EncryptedDataBuilder::buildEncryptedData());
66         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
67         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
68         assertEquals(expectedChildElementsDOM, encID);
69     }
70
71 };