2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
21 #include "XMLObjectBaseTestCase.h"
23 #include <xmltooling/exceptions.h>
26 class ExceptionTest : public CxxTest::TestSuite {
29 void testException(void) {
30 #define TEST(n,b,a) XMLToolingException e##n(b); \
31 TS_ASSERT(!strcmp(a,e##n.what()))
33 #define TESTP(n,b,a,p) MarshallingException e##n(b,p); \
34 TS_ASSERT(!strcmp(a,e##n.what()))
37 TESTP(1,"This is a test.", "This is a test.", params(2,"Foo","bar"));
38 TESTP(2,"This is a test.$", "This is a test.", params(2,"Foo","bar"));
39 TESTP(3,"This is a $ test.", "This is a test.", params(2,"Foo","bar"));
40 TESTP(4,"$$This is a test.$", "$This is a test.", params(2,"Foo","bar"));
41 TESTP(5,"$This is a $test.", "This is a test.", params(2,"Foo","bar"));
42 TESTP(6,"$1 is a $2", "Foo is a bar", params(2,"Foo","bar"));
43 TESTP(7,"$This is a $test.", "Foo is a bar.", namedparams(2,"This","Foo","test","bar"));
44 TESTP(8,"Unable to generate random data: $1",
45 "Unable to generate random data: OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised",
46 params(1,"OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised"));
48 string buf=e7.toString();
49 auto_ptr<XMLToolingException> ptr(XMLToolingException::fromString(buf.c_str()));
50 TS_ASSERT(typeid(*ptr)==typeid(MarshallingException));
51 TS_ASSERT(!strcmp(ptr->what(),"Foo is a bar."));