Template replacement engine ported from Shib, added conditional nesting.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / TemplateEngineTest.h
1 /*
2  *  Copyright 2001-2006 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 "XMLObjectBaseTestCase.h"
18
19 #include <fstream>
20 #include <sstream>
21 #include <xmltooling/util/TemplateEngine.h>
22
23 class TemplateEngineTest : public CxxTest::TestSuite {
24 public:
25     void setUp() {
26     }
27     
28     void tearDown() {
29     }
30
31     void testTemplateEngine() {
32         auto_ptr<TemplateEngine> engine(new TemplateEngine());
33
34         map<string,string> p;
35         p["foo1"] = "bar1";
36         p["foo3"] = "bar3";
37         
38         string path = data_path + "template.in";
39         ifstream in(path.c_str());
40         ostringstream out;
41         
42         engine->run(in,out,p);
43         
44         string compstr;
45         path = data_path + "template.out";
46         ifstream compfile(path.c_str());
47         while (getline(compfile,path))
48             compstr += path + '\n';
49             
50         TSM_ASSERT_EQUALS("Template output did not match.", out.str(), compstr);
51     }
52 };