1a86c10d33fefed2e239ffa3409f06b3302256a6
[shibboleth/sp.git] / test / inittest.cpp
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 "../shib-target/shib-target.h"
18 #include "../shib-target/shib-paths.h"
19
20 using namespace std;
21 using namespace saml;
22 using namespace shibboleth;
23 using namespace shibtarget;
24
25 ShibTargetConfig* g_Config = NULL;
26
27 void shutdown(void)
28 {
29   g_Config->shutdown();
30   g_Config = NULL;
31 }
32
33 void init(void)
34 {
35   try {
36     g_Config=&ShibTargetConfig::getConfig();
37     g_Config->setFeatures(
38                           ShibTargetConfig::Listener |
39                           ShibTargetConfig::Metadata |
40                           ShibTargetConfig::AAP |
41                           ShibTargetConfig::RequestMapper |
42                           ShibTargetConfig::LocalExtensions
43                           );
44
45     if (!g_Config->init(SHIB_SCHEMAS) || !g_Config->load(SHIB_CONFIG)) {
46       cerr << "init() failed to initialize SHIB Target" << endl;
47       exit(1);
48     }
49   }
50   catch (...) {
51     cerr << "init() failed to initialize SHIB Target" << endl;
52     exit (1);
53   }
54 }
55
56 int main(int argc, char* argv[])
57 {
58   cout << "Running init 1.." << endl;
59   init();
60   cout << "Running shutdown 1.." << endl;
61   shutdown();
62   cout << "Running init 2.." << endl;
63   init();
64   cout << "Running shutdown 2.." << endl;
65   shutdown();
66   cout << "Done." << endl;
67   exit(0);
68 }