8b0f1bb82d6dd0a9ea95b3190a29f90d6e90a430
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / ExceptionTest.h
1 /*
2  *  Copyright 2001-2007 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 "XMLObjectBaseTestCase.h"
18
19 #include <xmltooling/exceptions.h>
20
21
22 class ExceptionTest : public CxxTest::TestSuite {
23 public:
24
25     void testException(void) {
26 #define TEST(n,b,a) XMLToolingException e##n(b); \
27                 TS_ASSERT(!strcmp(a,e##n.what()))
28
29 #define TESTP(n,b,a,p) MarshallingException e##n(b,p); \
30                 TS_ASSERT(!strcmp(a,e##n.what()))
31
32
33         TESTP(1,"This is a test.",          "This is a test.",      params(2,"Foo","bar"));
34         TESTP(2,"This is a test.$",         "This is a test.",      params(2,"Foo","bar"));
35         TESTP(3,"This is a $ test.",        "This is a  test.",     params(2,"Foo","bar"));
36         TESTP(4,"$$This is a test.$",       "$This is a test.",     params(2,"Foo","bar"));
37         TESTP(5,"$This is a $test.",        "This is a test.",      params(2,"Foo","bar"));
38         TESTP(6,"$1 is a $2",               "Foo is a bar",         params(2,"Foo","bar"));
39         TESTP(7,"$This is a $test.",        "Foo is a bar.",        namedparams(2,"This","Foo","test","bar"));
40         TESTP(8,"Unable to generate random data: $1",
41                 "Unable to generate random data: OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised",
42                 params(1,"OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised"));
43
44         string buf=e7.toString();
45         auto_ptr<XMLToolingException> ptr(XMLToolingException::fromString(buf.c_str()));
46         TS_ASSERT(typeid(*ptr)==typeid(MarshallingException));
47         TS_ASSERT(!strcmp(ptr->what(),"Foo is a bar."));
48     }
49 };