~ubuntu-branches/ubuntu/oneiric/ctemplate/oneiric

« back to all changes in this revision

Viewing changes to src/tests/template_test_util.cc

  • Committer: Bazaar Package Importer
  • Author(s): Florian Reinhard
  • Date: 2010-01-14 22:31:32 UTC
  • Revision ID: james.westby@ubuntu.com-20100114223132-w9ritwjg2av4rfb3
Tags: upstream-0.96
ImportĀ upstreamĀ versionĀ 0.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2007, Google Inc.
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are
 
6
// met:
 
7
//
 
8
//     * Redistributions of source code must retain the above copyright
 
9
// notice, this list of conditions and the following disclaimer.
 
10
//     * Redistributions in binary form must reproduce the above
 
11
// copyright notice, this list of conditions and the following disclaimer
 
12
// in the documentation and/or other materials provided with the
 
13
// distribution.
 
14
//     * Neither the name of Google Inc. nor the names of its
 
15
// contributors may be used to endorse or promote products derived from
 
16
// this software without specific prior written permission.
 
17
//
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 
 
30
// ---
 
31
// Author: Jim Morrison
 
32
 
 
33
#include "config_for_unittests.h"
 
34
#include "tests/template_test_util.h"
 
35
#include <ctemplate/template_dictionary.h>
 
36
#include <ctemplate/template_namelist.h>
 
37
#include <ctemplate/template_string.h>
 
38
 
 
39
#include <string>
 
40
#include <vector>
 
41
 
 
42
using std::string;
 
43
using std::vector;
 
44
 
 
45
_START_GOOGLE_NAMESPACE_
 
46
 
 
47
TemporaryRegisterTemplate::TemporaryRegisterTemplate(const char* name) {
 
48
  old_namelist_ = TemplateNamelist::namelist_;
 
49
  if (old_namelist_) {
 
50
    namelist_ = *old_namelist_;
 
51
  }
 
52
 
 
53
  namelist_.insert(name);
 
54
  TemplateNamelist::namelist_ = &namelist_;
 
55
}
 
56
 
 
57
TemporaryRegisterTemplate::~TemporaryRegisterTemplate() {
 
58
  TemplateNamelist::namelist_ = old_namelist_;
 
59
}
 
60
 
 
61
const char* TemplateDictionaryPeer::GetSectionValue(
 
62
    const TemplateString& variable)
 
63
    const {
 
64
  return dict_->GetSectionValue(variable);
 
65
}
 
66
 
 
67
bool TemplateDictionaryPeer::IsHiddenSection(
 
68
    const TemplateString& name) const {
 
69
  return dict_->IsHiddenSection(name);
 
70
}
 
71
 
 
72
bool TemplateDictionaryPeer::IsUnhiddenSection(
 
73
    const TemplateString& name) const {
 
74
  return dict_->IsUnhiddenSection(name);
 
75
}
 
76
 
 
77
bool TemplateDictionaryPeer::IsHiddenTemplate(
 
78
    const TemplateString& name) const {
 
79
  return dict_->IsHiddenTemplate(name);
 
80
}
 
81
 
 
82
int TemplateDictionaryPeer::GetSectionDictionaries(
 
83
    const TemplateString& section_name,
 
84
    vector<const TemplateDictionary*>* dicts) const {
 
85
  dicts->clear();
 
86
  if (dict_->IsHiddenSection(section_name))
 
87
    return 0;
 
88
 
 
89
  TemplateDictionaryInterface::Iterator* di =
 
90
      dict_->CreateSectionIterator(section_name);
 
91
  while (di->HasNext())
 
92
    dicts->push_back(static_cast<const TemplateDictionary*>(&di->Next()));
 
93
  delete di;
 
94
 
 
95
  return static_cast<int>(dicts->size());
 
96
}
 
97
 
 
98
int TemplateDictionaryPeer::GetIncludeDictionaries(
 
99
    const TemplateString& section_name,
 
100
    vector<const TemplateDictionary*>* dicts) const {
 
101
  dicts->clear();
 
102
  if (dict_->IsHiddenTemplate(section_name))
 
103
    return 0;
 
104
 
 
105
  TemplateDictionaryInterface::Iterator* di =
 
106
      dict_->CreateTemplateIterator(section_name);
 
107
  while (di->HasNext())
 
108
    dicts->push_back(static_cast<const TemplateDictionary*>(&di->Next()));
 
109
  delete di;
 
110
 
 
111
  return static_cast<int>(dicts->size());
 
112
}
 
113
 
 
114
const char* TemplateDictionaryPeer::GetIncludeTemplateName(
 
115
    const TemplateString& variable, int dictnum) const {
 
116
  return dict_->GetIncludeTemplateName(variable, dictnum);
 
117
}
 
118
 
 
119
const char* TemplateDictionaryPeer::GetFilename() const {
 
120
  return dict_->filename_;
 
121
}
 
122
 
 
123
_END_GOOGLE_NAMESPACE_