desktop: added timezone list to CalendarEditDlg
[barry.git] / desktop / src / ostest.cc
blobf2f9710ac1ce41a85f513562928021ef6bfaedb7
1 ///
2 /// \file ostest.cc
3 /// Test application for the OpenSync API
4 ///
6 /*
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <iostream>
23 #include <stdexcept>
24 #include <memory>
25 #include <barry/barry.h>
26 #include "os22.h"
27 #include "os40.h"
28 #include "deviceset.h"
30 using namespace std;
31 using namespace OpenSync;
33 void DeviceSetTest(Barry::GlobalConfigFile &config, APISet &set)
35 DeviceSet dset(config, set);
36 cout << "========================================================\n";
37 cout << " Device Set results:\n";
38 cout << "========================================================\n";
39 cout << dset << endl;
42 void Test(API &os)
44 cout << "=======================================================\n";
45 cout << " Begin test run: " << os.GetVersion() << "\n";
46 cout << "=======================================================\n";
48 format_list_type flist;
49 os.GetFormats(flist);
50 cout << "Formats:\n" << flist << endl;
52 string_list_type slist;
53 os.GetPluginNames(slist);
54 cout << "Plugins:\n" << slist << endl;
56 os.GetGroupNames(slist);
57 cout << "Groups:\n" << slist << endl;
59 for( string_list_type::iterator b = slist.begin(); b != slist.end(); ++ b) {
60 member_list_type mlist;
61 os.GetMembers(*b, mlist);
62 cout << "Members for group: " << *b << endl;
63 cout << "---------------------------------------\n";
64 cout << mlist << endl;
68 // Test Group / Members
71 const std::string group_name = "ostest_trial_group";
73 cout << "Testing with group_name: " << group_name << endl;
75 // start fresh
76 try { os.DeleteGroup(group_name); }
77 catch( std::runtime_error &re ) {
78 cout << "DeleteGroup: " << re.what() << endl;
81 // add group twice, to confirm behaviour
82 os.AddGroup(group_name);
83 cout << "Added: " << group_name << endl;
85 try {
86 os.AddGroup(group_name);
87 throw std::logic_error("AddGroup() succeeded incorrectly!");
89 catch( std::runtime_error &re ) {
90 cout << "AddGroup: " << re.what() << endl;
93 if( OpenSync40 *os40 = dynamic_cast<OpenSync40*>(&os) ) {
94 try { os40->DeleteMember(group_name, 1); }
95 catch( std::runtime_error &re ) {
96 cout << "DeleteMember: " << re.what() << endl;
100 os.AddMember(group_name, "barry-sync", "Barry sync member");
101 os.AddMember(group_name, "evo2-sync", "Evolution sync member");
103 // test deleting the member twice, to confirm behaviour
104 // only os40 has DeleteMember()
105 if( OpenSync40 *os40 = dynamic_cast<OpenSync40*>(&os) ) {
106 os.AddMember(group_name, "file-sync", "File sync member");
107 os40->DeleteMember(group_name, "file-sync");
108 try { os40->DeleteMember(group_name, "file-sync"); }
109 catch( std::runtime_error &re ) {
110 cout << "DeleteMember: " << re.what() << endl;
114 // display our test group
115 member_list_type mlist;
116 os.GetMembers(group_name, mlist);
117 cout << "Members for group: " << group_name << endl;
118 cout << "---------------------------------------\n";
119 cout << mlist << endl;
121 // dump configurations
122 cout << group_name << "(1): " << (os.IsConfigurable(group_name, 1) ?
123 "configurable" : "not configurable") << endl;
124 cout << group_name << "(2): " << (os.IsConfigurable(group_name, 2) ?
125 "configurable" : "not configurable") << endl;
127 cout << "Member 1's configuration:\n";
128 cout << os.GetConfiguration(group_name, 1) << endl;
129 cout << "Member 2's configuration:\n";
130 cout << os.GetConfiguration(group_name, 2) << endl;
132 // add comment to bottom of barry-sync config
133 long id = mlist.FindId("barry-sync");
134 string barry_config = os.GetConfiguration(group_name, id);
135 if( dynamic_cast<OpenSync22*>(&os) )
136 barry_config += "\n# This is a test\n";
137 else
138 barry_config += "<!-- This is a test -->\n";
139 os.SetConfiguration(group_name, id, barry_config);
140 cout << "New config for member " << id << ":\n";
141 cout << os.GetConfiguration(group_name, id);
143 // discover
144 os.Discover(group_name);
146 // try a sync
147 SyncStatus status_callbacks;
148 os.Sync(group_name, status_callbacks, PST_DO_NOT_SET);
149 os.Sync(group_name, status_callbacks, PST_DO_NOT_SET);
151 // loop
152 string command;
153 while( (cout << "Enter 'q' to quit: "),
154 getline(cin, command),
155 command[0] != 'q' )
157 os.Sync(group_name, status_callbacks, PST_DO_NOT_SET);
160 // delete group twice, to confirm behaviour
161 os.DeleteGroup(group_name);
162 cout << "Deleted: " << group_name << endl;
164 try {
165 os.DeleteGroup(group_name);
166 throw std::logic_error("DeleteGroup() succeeded incorrectly!");
168 catch( std::runtime_error &re ) {
169 cout << "DeleteGroup failed as expected" << endl;
172 cout << "=======================================================\n";
173 cout << " End test run: " << os.GetVersion() << "\n";
174 cout << "=======================================================\n";
177 #ifdef WITH_OPENSYNC40
178 void ShowAdvanced(OS40PluginConfig &cfg, const char *name)
180 cout << name << ": " << cfg.GetAdvanced(name) << endl;
182 #endif
184 void TestConfig(OpenSync40 &os, const char *name, long member_id)
186 #ifndef WITH_OPENSYNC40
187 cout << "OpenSync40 support not compiled in." << endl;
188 #else
189 OS40PluginConfig cfg = os.GetConfigurationObj(name, member_id);
190 ShowAdvanced(cfg, "PinCode");
191 ShowAdvanced(cfg, "Debug");
192 cfg.SetAdvanced("TestName", "Test Display Name", "Whippoorwill");
194 OS40PluginConfig::OS40ConfigResourcePtr res =
195 cfg.GetResource("contact");
196 if( res->IsExistingResource() ) {
197 cout << "Resource: " << res->GetName() << ": "
198 << (res->IsEnabled() ? "enabled" : "disabled")
199 << endl;
200 cout << " pref format: " << res->GetPreferredFormat() << endl;
201 cout << " mime: " << res->GetMime() << endl;
202 cout << " objtype: " << res->GetObjType() << endl;
203 cout << " path: " << res->GetPath() << endl;
204 cout << " url: " << res->GetUrl() << endl;
206 string config;
207 if( res->FindObjFormat("vcard30", config) ) {
208 cout << " objformat: vcard30: " << config << endl;
210 else {
211 cout << " no vcard30 found" << endl;
214 else {
215 cout << "No contact resource found" << endl;
218 // add one / set one
219 res = cfg.GetResource("testresource");
220 if( res->IsExistingResource() )
221 cout << "testresource exists" << endl;
222 res->SetObjFormat("vcard30").
223 SetUrl("http://netdirect.ca/").
224 SetName("ResourceName").
225 Enable().
226 AddResource();
227 cfg.Save();
228 #endif
231 void TestConfig(API &os)
233 OpenSync40 *os40 = dynamic_cast<OpenSync40*> (&os);
234 TestConfig(*os40, "test", 1);
235 TestConfig(*os40, "test", 2);
238 int main()
240 Barry::Init(true);
242 try {
243 Barry::GlobalConfigFile config("ostest");
245 APISet set;
246 set.OpenAvailable();
248 DeviceSetTest(config, set);
250 if( set.os40() ) {
251 TestConfig(*set.os40());
252 Test(*set.os40());
255 if( set.os22() ) {
256 Test(*set.os22());
260 catch( std::exception &e ) {
261 cout << "TEST FAILED: " << e.what() << endl;
264 return 0;