blob: 4951e565984eb52a708d77085b35db023e18041d [file] [log] [blame]
Brian Silverman70325d62015-09-20 17:00:43 -04001// Copyright (c) 2008, 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: Craig Silverstein
32//
33// Most other tests use "config_for_unittests.h" to make testing easier.
34// This brings in some code most users won't use. This test is meant
35// entirely to use ctemplate as users will, just #including the public
36// .h files directly. It does hardly any work, and is mainly intended
37// as a compile check for the .h files. It will not work if you use
38// a non-standard name for the package namespace (via
39// ./configure --enable-namespace=foo
40// ), though you can fix that by changing the namespace alias below.
41
42// These are all the .h files that we export
43#include <ctemplate/per_expand_data.h>
44#include <ctemplate/template.h>
45#include <ctemplate/template_dictionary.h>
46#include <ctemplate/template_dictionary_interface.h>
47#include <ctemplate/template_emitter.h>
48#include <ctemplate/template_enums.h>
49#include <ctemplate/template_modifiers.h>
50#include <ctemplate/template_namelist.h>
51#include <ctemplate/template_pathops.h>
52#include <ctemplate/template_string.h>
53#include <stdio.h>
54#include <string>
55
56// If you used ./configure --enable-namespace=foo, replace 'ctemplate'
57// here with 'foo'.
58namespace template_ns = ctemplate;
59
60int main() {
61 template_ns::Template::StringToTemplateCache("key", "example");
62 template_ns::Template* tpl = template_ns::Template::GetTemplate(
63 "key", template_ns::DO_NOT_STRIP);
64 template_ns::TemplateDictionary dict("my dict");
65 std::string nothing_will_come_of_nothing;
66 tpl->Expand(&nothing_will_come_of_nothing, &dict);
67
68 // Try using a bit more functionality.
69 template_ns::PerExpandData data;
70 nothing_will_come_of_nothing.clear();
71 template_ns::ExpandWithData("key", template_ns::DO_NOT_STRIP, &dict, &data,
72 &nothing_will_come_of_nothing);
73
74 printf("PASS.\n");
75 return 0;
76}