https://issues.shibboleth.net/jira/browse/SSPCPP-185
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / TemplateEngineTest.h
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 "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         TemplateEngine::TemplateParameters p;
35         p.m_map["foo1"] = "bar1";
36         p.m_map["foo3"] = "bar3";
37         p.m_map["encoded"] = "http://www.example.org/foo/bar#foobar";
38         
39         string path = data_path + "template.in";
40         ifstream in(path.c_str());
41         ostringstream out;
42         
43         engine->run(in,out,p);
44         
45         string compstr;
46         path = data_path + "template.out";
47         ifstream compfile(path.c_str());
48         while (getline(compfile,path))
49             compstr += path + '\n';
50             
51         TSM_ASSERT_EQUALS("Template output did not match.", out.str(), compstr);
52     }
53 };