Add copyright comment headers to appropriate files
[gssweb.git] / json_gssapi / test / GSSExceptionTest.cpp
1 /*
2  * Copyright (c) 2014, 2015 JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #include "GSSExceptionTest.h"
36 #include "GSSException.h"
37 #include <string>
38 #include <iostream>
39
40
41 // Registers the fixture into the 'registry'
42 CPPUNIT_TEST_SUITE_REGISTRATION( GSSExceptionTest );
43
44 void GSSExceptionTest::setUp()
45 {
46   CppUnit::TestFixture::setUp();
47 }
48
49 void GSSExceptionTest::tearDown()
50 {
51   CppUnit::TestFixture::tearDown();
52 }
53
54
55 void GSSExceptionTest::testWithMessage()
56 {
57   try {
58     throw GSSException("Test message");
59   } catch (GSSException e)
60   {
61     CPPUNIT_ASSERT_EQUAL_MESSAGE(
62       "GSSException message reporting is incorrect.",
63       std::string("Test message\n\
64 GSS Error message:\n\
65   Major status:\n\
66     The routine completed successfully\n\
67 \n\
68   Minor status details: \n\
69     Unknown error\n"), 
70       std::string(e.what())
71     );
72   }
73 }
74
75 void GSSExceptionTest::testWithMessageAndMajor()
76 {
77   try {
78     throw GSSException("Test message", 524288);
79   } catch (GSSException e)
80   {
81     CPPUNIT_ASSERT_EQUAL_MESSAGE(
82       "GSSException message reporting is incorrect.",
83       std::string("Test message\n\
84 GSS Error message:\n\
85   Major status:\n\
86     No context has been established\n\
87 \n\
88   Minor status details: \n\
89     Unknown error\n"), 
90       std::string(e.what())
91     );
92   }
93 }
94
95 void GSSExceptionTest::testWithMessageAndMajorAndMinor()
96 {
97   OM_uint32 major, minor, context = 0;
98   gss_buffer_desc_struct buf;
99   
100   try {
101     major = gss_display_status(&minor, 2109382930, GSS_C_MECH_CODE, GSS_C_NO_OID, &context, &buf);
102     throw GSSException("Test message", major, minor);
103   } catch (GSSException e)
104   {
105     CPPUNIT_ASSERT_EQUAL_MESSAGE(
106       "GSSException message reporting is incorrect.",
107       std::string("Test message\n\
108 GSS Error message:\n\
109   Major status:\n\
110     An invalid status code was supplied\n\
111 \n\
112   Minor status details: \n\
113     Invalid argument\n"), 
114       std::string(e.what())
115     );
116   }
117 }
118
119 void GSSExceptionTest::testWithMessageAndMajorAndMinorAndMechanism()
120 {
121
122   OM_uint32 major, minor, context = 0;
123   gss_buffer_desc_struct buf;
124   
125   try {
126     major = gss_display_status(&minor, 2109382930, GSS_C_MECH_CODE, GSS_C_NO_OID, &context, &buf);
127     throw GSSException("Test message", major, minor, GSS_C_NO_OID);
128   } catch (GSSException e)
129   {
130     CPPUNIT_ASSERT_EQUAL_MESSAGE(
131       "GSSException message reporting is incorrect.",
132       std::string("Test message\n\
133 GSS Error message:\n\
134   Major status:\n\
135     An invalid status code was supplied\n\
136 \n\
137   Minor status details: \n\
138     Invalid argument\n"), 
139       std::string(e.what())
140     );
141   }
142   
143 }