Remove some tracing, fix string compares.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / ExceptionTest.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include "XMLObjectBaseTestCase.h"\r
18 \r
19 #include <xmltooling/exceptions.h>\r
20 \r
21 \r
22 class ExceptionTest : public CxxTest::TestSuite {\r
23 public:\r
24 \r
25     void testException(void) {\r
26 #define TEST(n,b,a) XMLToolingException e##n(b); \\r
27                 TS_ASSERT(!strcmp(a,e##n.what()))\r
28 \r
29 #define TESTP(n,b,a,p) MarshallingException e##n(b,p); \\r
30                 TS_ASSERT(!strcmp(a,e##n.what()))\r
31 \r
32 \r
33         TESTP(1,"This is a test.",          "This is a test.",      params(2,"Foo","bar"));\r
34         TESTP(2,"This is a test.$",         "This is a test.",      params(2,"Foo","bar"));\r
35         TESTP(3,"This is a $ test.",        "This is a  test.",     params(2,"Foo","bar"));\r
36         TESTP(4,"$$This is a test.$",       "$This is a test.",     params(2,"Foo","bar"));\r
37         TESTP(5,"$This is a $test.",        "This is a test.",      params(2,"Foo","bar"));\r
38         TESTP(6,"$1 is a $2",               "Foo is a bar",         params(2,"Foo","bar"));\r
39         TESTP(7,"$This is a $test.",        "Foo is a bar.",        namedparams(2,"This","Foo","test","bar"));\r
40         TESTP(8,"Unable to generate random data: $1",\r
41                 "Unable to generate random data: OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised",\r
42                 params(1,"OpenSSLCryptoProvider::getRandom - OpenSSL random not properly initialised"));\r
43 \r
44         string buf=e7.toString();\r
45         auto_ptr<XMLToolingException> ptr(XMLToolingException::fromString(buf.c_str()));\r
46         TS_ASSERT(typeid(*ptr)==typeid(MarshallingException));\r
47         TS_ASSERT(!strcmp(ptr->what(),"Foo is a bar."));\r
48     }\r
49 };\r