Bumped copyright dates for 2013
[barry.git] / test / fhbuild.cc
blob9b938301c37aef304ffc18a30b66a6af0a30c54f
1 ///
2 /// \file fhbuild.cc
3 /// Compile-time test to make sure all FieldHandle<> templates
4 /// and classes are complete.
5 ///
7 /*
8 Copyright (C) 2012-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <barry/barry.h>
24 #include <iostream>
26 using namespace std;
27 using namespace Barry;
29 void DumpId(const FieldIdentity &id)
31 cout << " sub = " << (id.HasSubfields ? "true" : "false")
32 << ", parent = "
33 << (id.ParentName ? id.ParentName : "NULL") << endl;
34 cout << " FieldTypeCode = " << id.FieldTypeCode << endl;
35 cout << " Ldif = " << (id.Ldif ? id.Ldif : "NULL")
36 << ", ObjectClass = "
37 << (id.ObjectClass ? id.ObjectClass : "NULL")
38 << endl;
39 cout << " Iconv = " << (id.IconvNeeded ? "true" : "false")
40 << endl << endl;
43 void DumpEnumConstants(const EnumConstants *ec)
45 cout << " Available constants:" << endl;
47 EnumConstants::EnumConstantList::const_iterator
48 b = ec->GetConstantList().begin(),
49 e = ec->GetConstantList().end();
50 for( ; b != e; ++b ) {
51 cout << " " << b->DisplayName
52 << " (" << b->Name << ")"
53 << " = " << b->Value << endl;
55 cout << endl;
58 template <class RecordT>
59 struct FieldHandler
61 const RecordT &m_rec;
63 FieldHandler(const RecordT &obj)
64 : m_rec(obj)
68 void operator()(EnumFieldBase<RecordT> *ep,
69 const FieldIdentity &id) const
71 cout << id.DisplayName << " (" << id.Name << "): "
72 << ep->GetName(ep->GetValue(m_rec))
73 << " (" << ep->GetValue(m_rec) << ")"
74 << endl;
75 DumpId(id);
76 DumpEnumConstants(ep);
79 void operator()(typename FieldHandle<RecordT>::PostalPointer pp,
80 const FieldIdentity &id) const
82 cout << id.DisplayName << " (" << id.Name << "): "
83 << m_rec.*(pp.m_PostalAddress).*(pp.m_PostalField)
84 << endl;
85 DumpId(id);
88 template <class TypeT>
89 void operator()(TypeT RecordT::* mp, const FieldIdentity &id) const
91 cout << id.DisplayName << " (" << id.Name << "): "
92 << m_rec.*mp << endl;
93 DumpId(id);
97 class VirtualFieldHandler : public FieldValueHandlerBase
99 public:
100 /// For type std::string
101 virtual void operator()(const std::string &v,
102 const FieldIdentity &id) const
104 cout << id.DisplayName << " (" << id.Name << "): "
105 << v << endl;
106 DumpId(id);
108 /// For type EmailAddressList
109 virtual void operator()(const EmailAddressList &v,
110 const FieldIdentity &id) const
112 cout << id.DisplayName << " (" << id.Name << "): "
113 << v << endl;
114 DumpId(id);
116 /// For type Barry::TimeT
117 virtual void operator()(const Barry::TimeT &v,
118 const FieldIdentity &id) const
120 cout << id.DisplayName << " (" << id.Name << "): "
121 << v << endl;
122 DumpId(id);
124 /// For type uint8_t
125 virtual void operator()(const uint8_t &v,
126 const FieldIdentity &id) const
128 cout << id.DisplayName << " (" << id.Name << "): "
129 << (unsigned int) v << endl;
130 DumpId(id);
132 /// For type uint16_t
133 virtual void operator()(const uint16_t &v,
134 const FieldIdentity &id) const
136 cout << id.DisplayName << " (" << id.Name << "): "
137 << v << endl;
138 DumpId(id);
140 /// For type uint32_t
141 virtual void operator()(const uint32_t &v,
142 const FieldIdentity &id) const
144 cout << id.DisplayName << " (" << id.Name << "): "
145 << v << endl;
146 DumpId(id);
148 /// For type uint64_t
149 virtual void operator()(const uint64_t &v,
150 const FieldIdentity &id) const
152 cout << id.DisplayName << " (" << id.Name << "): "
153 << v << endl;
154 DumpId(id);
156 /// For type bool
157 virtual void operator()(const bool &v,
158 const FieldIdentity &id) const
160 cout << id.DisplayName << " (" << id.Name << "): "
161 << v << endl;
162 DumpId(id);
164 /// For type int32_t
165 virtual void operator()(const int32_t &v,
166 const FieldIdentity &id) const
168 cout << id.DisplayName << " (" << id.Name << "): "
169 << v << endl;
170 DumpId(id);
172 /// For type EmailList
173 virtual void operator()(const EmailList &v,
174 const FieldIdentity &id) const
176 cout << id.DisplayName << " (" << id.Name << "): "
177 << v << endl;
178 DumpId(id);
180 /// For type Date
181 virtual void operator()(const Date &v,
182 const FieldIdentity &id) const
184 cout << id.DisplayName << " (" << id.Name << "): "
185 << v << endl;
186 DumpId(id);
188 /// For type CategoryList
189 virtual void operator()(const CategoryList &v,
190 const FieldIdentity &id) const
192 cout << id.DisplayName << " (" << id.Name << "): "
193 << v << endl;
194 DumpId(id);
196 /// For type PostalAddress
197 virtual void operator()(const PostalAddress &v,
198 const FieldIdentity &id) const
200 cout << id.DisplayName << " (" << id.Name << "): "
201 << v << endl;
202 DumpId(id);
204 /// For type UnknownsType
205 virtual void operator()(const UnknownsType &v,
206 const FieldIdentity &id) const
208 cout << id.DisplayName << " (" << id.Name << "): "
209 << v << endl;
210 DumpId(id);
214 void TestContact()
216 Contact contact;
217 contact.RecType = 8;
218 contact.RecordId = 100000;
219 contact.EmailAddresses.push_back("cdfrey@foursquare.net");
220 contact.EmailAddresses.push_back("cdfrey@netdirect.ca");
221 contact.Phone = "519-555-1212";
222 contact.Fax = "no fax";
223 contact.HomeFax = "home fax";
224 contact.WorkPhone = "work 51235";
225 contact.WorkPhone2 = "work2 12351234";
226 contact.HomePhone = "home 12341234";
227 contact.HomePhone2 = "home2 4234234";
228 contact.MobilePhone = "mobile 88888";
229 contact.MobilePhone2 = "mobile2 23424";
230 contact.Pager = "pager 123412342";
231 contact.PIN = "PIN 1234";
232 contact.Radio = "CBC";
233 contact.OtherPhone = "other 12341234";
234 contact.FirstName = "Chris";
235 contact.LastName = "Frey";
236 contact.Company = "Company naaaaaaaaaaame";
237 contact.DefaultCommunicationsMethod = "E";
238 contact.JobTitle = "Programmer";
239 contact.PublicKey = "seeeecrit";
240 contact.URL = "http://netdirect.ca/~cdfrey/";
241 contact.Prefix = "nothing";
242 contact.Notes = "This is a notes field that can hold mega data";
243 contact.UserDefined1 = "user 1";
244 contact.UserDefined2 = "user 2";
245 contact.UserDefined3 = "user 3";
246 contact.UserDefined4 = "user 4";
247 contact.Image = "no image available";
248 contact.Nickname = "LRU";
249 Date d;
250 d.FromYYYYMMDD("20120101");
251 contact.Birthday = d;
252 contact.WorkAddress.Address1 = "work address 1";
253 contact.WorkAddress.Address2 = "work address 2";
254 contact.WorkAddress.Address3 = "work address 3";
255 contact.WorkAddress.City = "work city";
256 contact.WorkAddress.Province = "work Province";
257 contact.WorkAddress.PostalCode = "work PostalCode";
258 contact.WorkAddress.Country = "work Country";
259 contact.HomeAddress.Address1 = "home address 1";
260 contact.HomeAddress.Address2 = "home address 2";
261 contact.HomeAddress.Address3 = "home address 3";
262 contact.HomeAddress.City = "home city";
263 contact.HomeAddress.Province = "home Province";
264 contact.HomeAddress.PostalCode = "home PostalCode";
265 contact.HomeAddress.Country = "home Country";
266 contact.Categories.push_back("office");
267 contact.Categories.push_back("entertainment");
269 FieldHandler<Contact> handler(contact);
270 ForEachField(Contact::GetFieldHandles(), handler);
272 cout << "================================================" << endl;
274 VirtualFieldHandler vhandler;
275 ForEachFieldValue(contact, vhandler);
278 void BlankTestAll()
280 VirtualFieldHandler vhandler;
282 cout << "All parsers......" << endl;
284 #undef HANDLE_PARSER
285 #define HANDLE_PARSER(tname) \
286 cout << "Record: " << #tname << endl; \
287 cout << "===================================================" << endl;\
288 tname obj##tname; \
289 FieldHandler<tname> fh##tname(obj##tname); \
290 cout << "By member pointer..." << endl; \
291 ForEachField(tname::GetFieldHandles(), fh##tname); \
292 cout << "\nBy value..." << endl; \
293 ForEachFieldValue(obj##tname, vhandler); \
294 cout << endl;
296 ALL_KNOWN_PARSER_TYPES
299 cout << "All builders........" << endl;
301 #undef HANDLE_BUILDER
302 #define HANDLE_BUILDER(tname) \
303 cout << "Record: " << #tname << endl; \
304 cout << "===================================================" << endl;\
305 tname bobj##tname; \
306 FieldHandler<tname> bfh##tname(bobj##tname); \
307 cout << "By member pointer..." << endl; \
308 ForEachField(tname::GetFieldHandles(), bfh##tname); \
309 cout << "\nBy value..." << endl; \
310 ForEachFieldValue(bobj##tname, vhandler); \
311 cout << endl;
313 ALL_KNOWN_BUILDER_TYPES
316 int main()
318 TestContact();
319 BlankTestAll();