c2fbb055e1a02a55583366ca3fb8290f10262200
[gssweb.git] / json_gssapi / test / GSSExceptionTest.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  * 
4  * For license details, see the LICENSE file in the root of this project.
5  * 
6  */
7
8 #include "GSSExceptionTest.h"
9 #include "GSSException.h"
10 #include <string>
11 #include <iostream>
12
13
14 // Registers the fixture into the 'registry'
15 CPPUNIT_TEST_SUITE_REGISTRATION( GSSExceptionTest );
16
17 void GSSExceptionTest::setUp()
18 {
19   CppUnit::TestFixture::setUp();
20 }
21
22 void GSSExceptionTest::tearDown()
23 {
24   CppUnit::TestFixture::tearDown();
25 }
26
27
28 void GSSExceptionTest::testWithMessage()
29 {
30   try {
31     throw GSSException("Test message");
32   } catch (GSSException e)
33   {
34     CPPUNIT_ASSERT_EQUAL_MESSAGE(
35       "GSSException message reporting is incorrect.",
36       std::string("Test message\n\
37 GSS Error message:\n\
38   Major status:\n\
39     The routine completed successfully\n\
40 \n\
41   Minor status details: \n\
42     Unknown error\n"), 
43       std::string(e.what())
44     );
45   }
46 }
47
48 void GSSExceptionTest::testWithMessageAndMajor()
49 {
50   try {
51     throw GSSException("Test message", 524288);
52   } catch (GSSException e)
53   {
54     CPPUNIT_ASSERT_EQUAL_MESSAGE(
55       "GSSException message reporting is incorrect.",
56       std::string("Test message\n\
57 GSS Error message:\n\
58   Major status:\n\
59     No context has been established\n\
60 \n\
61   Minor status details: \n\
62     Unknown error\n"), 
63       std::string(e.what())
64     );
65   }
66 }
67
68 void GSSExceptionTest::testWithMessageAndMajorAndMinor()
69 {
70   OM_uint32 major, minor, context = 0;
71   gss_buffer_desc_struct buf;
72   
73   try {
74     major = gss_display_status(&minor, 2109382930, GSS_C_MECH_CODE, GSS_C_NO_OID, &context, &buf);
75     throw GSSException("Test message", major, minor);
76   } catch (GSSException e)
77   {
78     CPPUNIT_ASSERT_EQUAL_MESSAGE(
79       "GSSException message reporting is incorrect.",
80       std::string("Test message\n\
81 GSS Error message:\n\
82   Major status:\n\
83     An invalid status code was supplied\n\
84 \n\
85   Minor status details: \n\
86     Invalid argument\n"), 
87       std::string(e.what())
88     );
89   }
90 }
91
92 void GSSExceptionTest::testWithMessageAndMajorAndMinorAndMechanism()
93 {
94
95   OM_uint32 major, minor, context = 0;
96   gss_buffer_desc_struct buf;
97   
98   try {
99     major = gss_display_status(&minor, 2109382930, GSS_C_MECH_CODE, GSS_C_NO_OID, &context, &buf);
100     throw GSSException("Test message", major, minor, GSS_C_NO_OID);
101   } catch (GSSException e)
102   {
103     CPPUNIT_ASSERT_EQUAL_MESSAGE(
104       "GSSException message reporting is incorrect.",
105       std::string("Test message\n\
106 GSS Error message:\n\
107   Major status:\n\
108     An invalid status code was supplied\n\
109 \n\
110   Minor status details: \n\
111     Invalid argument\n"), 
112       std::string(e.what())
113     );
114   }
115   
116 }