Ensure outgoing errors are logged.
[shibboleth/cpp-sp.git] / shib-target / testini.cpp
1 /*
2  *  Copyright 2001-2005 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.h"
18 #include <iostream>
19
20 using namespace std;
21 using namespace shibtarget;
22
23 static void test (ShibINI &ini, const char* header)
24 {
25   cout << "Testing Header: \"";
26   cout << header;
27   cout << "\"\tExists: ";
28   cout << (ini.exists (header) ? "Yes\n" : "No\n");
29 }
30
31 static void test (ShibINI &ini, const char* header, const char* tag)
32 {
33   cout << "\t\"";
34   cout << header;
35   cout << ".";
36   cout << tag;
37   cout << "\"\tExists: ";
38   if (ini.exists (header, tag)) {
39     cout << "Yes\tValue: \"";
40     cout << ini.get (header, tag);
41     cout << "\"\n";
42   } else
43     cout << "No\n";
44 }
45
46 static void test_header_iter (ShibINI &ini)
47 {
48   cout << "Test Header Iterator: ";
49   ShibINI::Iterator* iter = ini.header_iterator();
50   for (const string* str = iter->begin(); str; str = iter->next())
51     cout << "\"" << *str << "\" ";
52   cout << "\n";
53
54   delete iter;
55 }
56
57 static void test_tag_iter (ShibINI &ini, const char* header)
58 {
59   string h = header;
60   cout << "Test Tag Iterator \"" << header << "\" : ";
61   ShibINI::Iterator* iter = ini.tag_iterator(h);
62   for (const string* str = iter->begin(); str; str = iter->next())
63     cout << "\"" << *str << "\" ";
64   cout << "\n";
65
66   delete iter;
67 }
68
69 static void run_test (ShibINI &ini)
70 {
71   char* headers[] = { "test1", "", "header1", "Header1", "header2", "header2 " };
72   char* tags[] = { "test1", "test2", "test3", "test4", "test5", "TeSt5", "test 6" };
73
74   ini.dump(cout);
75
76   test_header_iter (ini);
77
78   for (int i = 0; i < sizeof(headers)/sizeof(*headers); i++) {
79     test (ini, headers[i]);
80
81     for (int j = 0; j < sizeof(tags)/sizeof(*tags); j++) 
82       test (ini, headers[i], tags[j]);
83
84     test_tag_iter (ini, headers[i]);
85   }
86
87 }
88
89 main()
90 {
91   ShibINI ini("testini.ini");
92   run_test (ini);
93
94   ShibINI ini2("testini.ini", false);
95   run_test (ini2);
96 }