/
pdb-test.php
462 lines (391 loc) · 12.6 KB
/
pdb-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?php
/* Testing program to make sure PHP-PDB will work on this system
*
* Copyright (C) 2001 - PHP-PDB development team
* Licensed under the GNU LGPL software license.
* See the doc/LEGAL file for more legal information
* See https://github.com/fidian/php-pdb for more information about the library
*/
// Turn on all error reporting
ini_set('error_reporting', E_ALL);
include'./php-pdb.inc';
include'./modules/addrbook.inc';
include'./modules/datebook.inc';
include'./modules/doc.inc';
include'./modules/list.inc';
include'./modules/memo.inc';
include'./modules/smallbasic.inc';
include'./modules/todo.inc';
$Tests = array();
$TestType = 'Unknown';
/*
* Perform the tests
* Cache the results
*/
?>
<html><head><title>PHP-PDB Testing</title>
<body bgcolor="#FFFFFF">
<?php
ob_start();
?>
<h1><a name="Data"></a>Data conversion testing</h1><?php $TestType = 'Data' ?>
<ul>
<li>Int8 (Write) = <?php
PassFail('return PalmDB::Int8(40);', '28') ?></li>
<li>Int8 (Read) = <?php
PassFail('return PalmDB::LoadInt8(pack(\'H*\', \'28\'));', 40) ?></li>
<li>Int16 (Write) = <?php
PassFail('return PalmDB::Int16(1796);', '0704') ?></li>
<li>Int16 (Read) = <?php
PassFail('return PalmDB::LoadInt16(pack(\'H*\', \'0704\'));', 1796) ?></li>
<li>Int32 (Write) = <?php
PassFail('return PalmDB::Int32(40195090);', '02655412') ?></li>
<li>Int32 (Read) = <?php
PassFail('return PalmDB::LoadInt32(pack(\'H*\', \'02655412\'));', 40195090) ?></li>
<?php
// Double() refers to $this, so it must be in an instantiated class
$dbl = new PalmDB();
$Fail = 0;
?>
<li>Double (Write) = <?php
$Fail += PassFail('$dbl = new PalmDB();
return $dbl->Double(10.53);', '40250f5c28f5c28f') ?></li>
<li>Double (Read) = <?php
$Fail += PassFail('$dbl = new PalmDB();
return $dbl->LoadDouble(pack(\'H*\', \'40250f5c28f5c28f\'));', 10.53);
if ($Fail) {
echo '<br>Don\'t worry -- this method is not used by anything in ' . 'the PHP-PDB library yet. It is a utility function that is ' . 'added for completeness. If you absolutely do need this ' . 'function, take a look at the PHP-PDB source or just submit ' . "a bug report.\n";
}
?></li>
<li>String (Write) = <?php
PassFail('return PalmDB::String(\'abcd\', \'3\');', '616263') ?></li>
<li>String (Read) = <?php
PassFail('$p = new PalmDB();
return $p->LoadString(pack(\'H*\', \'6162630000\'), 4);', 'abc'); ?></li>
</ul>
<h1><a name="Modules"></a>Modules</h1><?php $TestType = 'Modules' ?>
<ul>
<li>Addresses = <?php PassFail('return AddressbookTest();', '3ce11d66da0a869632623f000460374a') ?></li>
<li>Datebook = <?php PassFail('return DatebookTest();', 'acb80f080d5d8161fb6651e0fc0310df') ?></li>
<li>Doc = <?php PassFail('return DocTest(false);', '91fa7442b46075d8ff451c58457d7246') ?></li>
<li>Doc (compressed) = <?php PassFail('return DocTest(true);', 'c5d02609dcfd8e565318da246226cd64') ?></li>
<li>List = <?php PassFail('return ListTest();', 'dfcb278a4508f33a3e6a0ba288d5d49e') ?></li>
<li>Memo = <?php PassFail('return MemoTest();', '3066a78037a2c7394605d9a6b2af4e48') ?></li>
<li>SmallBASIC = <?php PassFail('return SmallBASICTest();', 'e680fa5719b5ca1d7408148e2d8c7b43') ?></li>
<li>Todo = <?php PassFail('return TodoTest();', 'd009e145a7633a33f1376712e3a6bc12') ?></li>
</ul>
<?php
$results = ob_get_contents();
ob_end_clean();
/*
* Create the summary table
*/
?>
<h1>Summary</h1>
<table align=center bgcolor="#EFEFFF" border=1 cellpadding=10 cellspacing=0>
<tr bgcolor="#C0C0FF"><th>Test Type</th>
<th bgcolor="#C0FFC0">Pass</th><th bgcolor="#FFC0C0">Fail</th><th>% Working</th></tr>
<?php
$TestTotalPass = 0;
$TestTotalFail = 0;
foreach ($Tests as $Type => $Test) {
$Percent = $Test['Pass'] / ($Test['Pass'] + $Test['Fail']);
$Percent *= 100;
$Percent = intval($Percent);
echo '<tr';
if ($Test['Fail'])echo ' bgcolor="#FFDFDF"';
echo '><td><a href="#' . $Type . '">' . $Type . '</a></td><td align=center bgcolor="#EFFFEF">' . $Test['Pass'] . '</td><td align=center bgcolor="#FFEFEF">' . $Test['Fail'] . '</td><td align=center>' . $Percent . " %</td></tr>\n";
$TestTotalPass += $Test['Pass'];
$TestTotalFail += $Test['Fail'];
}
?><tr bgcolor="#C0C0FF"><td><b>Total</b></td>
<td align=center bgcolor="#C0FFC0"><b><?php echo $TestTotalPass
?></b></td><td align=center bgcolor="#FFC0C0"><b><?php echo $TestTotalFail
?></b></td><td align=center><b><?php
$Percent = $TestTotalPass / ($TestTotalPass + $TestTotalFail);
$Percent *= 100;
$Percent = intval($Percent);
echo $Percent;
?> %</b></td></tr>
</table>
<?php
/*
* If there were failures,
* Then print out some cool information
* Also print out cached test results here
*/
if ($TestTotalFail) {
?>
<p align=center><a href="#SolveProblems">Click Here</a> for information
about test failures and what should be done about them.</p>
<?php
}
echo $results;
if ($TestTotalFail) {
?>
<h1><a name="SolveProblems"></a>Test failure information</h1>
<p>Please perform these steps, in order, to resolve the problem.</p>
<ol>
<li>Make sure that you are running the latest version of <a
href="https://github.com/fidian/php-pdb">PHP-PDB</a>. If you are not,
upgrade.</li>
<li>Determine which tests failed. Just look above this section for anything
that says "<FONT color="red">fail</font>".</li>
<ul>
<li>If it was in the Data section and it was not the Double test, then
something is <b>seriously</b> wrong. Please send us a bug report
immediately.</li>
<li>If it was the Double test in the Data section, then you do not need
to worry. Nothing in the PHP-PDB library uses this function (yet), but
a class might be written to use the Double function. It is a good idea
to get the problem fixed, just in case you wish to use double-precision
numbers saved in your generated databases. If you do report the problem,
please include the entire error message that was generated (the <i>Wanted
"abcdefg" but got "1234567"</i> message).</li>
<li>If it was in the Modules section, and if you don't need that module,
then you can safely ignore the warning, but it would be really nice if you
reported the error to us. (Just the fact that module <i>X</i> failed --
we don't need the long string of letters and numbers.)</li>
<li>If you can't see the error, then something is wacky. Weird. Try
looking at the Summary table (at the top) to see which section the problem
is in.</li>
</ul>
<li>Report the problem to us in the <a
href="https://github.com/fidian/php-pdb/issues">Issue Tracker</a></li>
</ol>
<?php
}
?>
</body></html>
<?php
/*////////////////////////////////////
* Thus began the testing functions //
* ////////////////////////////////////
*
* Address book
*/
function AddressbookTest() {
$addr = new PalmAddress();
// Create some categories
$categorias = array(
1 => 'VIP',
'AAA',
'Inicial'
);
$addr->SetCategoryList($categorias);
// Add one entry
$fields = array(
'LastName' => 'Pascual',
'FirstName' => 'Eduardo',
'Phone1' => '21221552',
'Phone2' => '58808912',
'Phone5' => 'epascual@cie.com.mx',
'Address' => 'Hda. la Florida 10A',
'City' => 'Izcalli'
);
$addr->SetRecordRaw($fields);
$addr->GoToRecord('+1');
// Add another
$fields = array(
'LastName' => 'de tal',
'FirstName' => 'fulanito',
'Address' => 'Direccion',
'Phone1' => '21232425',
'Phone2' => 'fulanito@dondesea.com',
'Phone1Type' => PDB_ADDR_LABEL_HOME,
'Phone2Type' => PDB_ADDR_LABEL_EMAIL,
'Phone3Type' => PDB_ADDR_LABEL_WORK,
'Phone4Type' => PDB_ADDR_LABEL_FAX,
'Phone5Type' => PDB_ADDR_LABEL_OTHER,
'Display' => 1,
'Reserved' => ''
);
$addr->SetRecordRaw($fields);
$addr->SetRecordAttrib(PDB_RECORD_ATTRIB_PRIVATE | 1); // Private record, category 1
return GenerateMd5($addr);
}
/*
* Datebook
*/
function DatebookTest() {
$d = new PalmDatebook();
/* Create a repeating event that happens every other Friday.
* I want it to be an all-day event that says "Pay Day!" */
$Repeat = array(
'Type' => PDB_DATEBOOK_REPEAT_WEEKLY,
'Frequency' => 2,
'Days' => '5',
'StartOfWeek' => 0
);
$Record = array(
'Date' => '2001-11-2',
'Description' => 'Pay Day!',
'Repeat' => $Repeat
);
// Add the record to the datebook
$d->SetRecordRaw($Record);
return GenerateMd5($d);
}
/*
* DOC
*/
function DocTest($IsCompressed) {
$d = new PalmDoc('Title Goes Here', $IsCompressed);
$text = "Mary had a little lamb,\n" .
"little lamb,\n" .
"little lamb.\n" .
"Mary had a little lamb,\n" .
"its fleece as white as snow.\n" .
"\n" .
"It followed her to school one day,\n" .
"school one day,\n" .
"school one day.\n" .
"It followed her to school one day.\n" .
"and I hope this doc text test works well.\n" .
"\n" .
"(Yeah, I know. It does not rhyme.)\n";;
// Just in case the file is edited and the newlines are changed a bit.
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
$text = explode("\n", $text);
$newText = '';
foreach ($text as $t) {
trim($t);
$newText .= $t . "\n";
}
$d->AddText($newText);
return GenerateMd5($d);
}
/*
* List
*/
function ListTest() {
$d = new PalmListDB('List Test');
$d->SetRecordRaw(array(
'abc',
'123',
'Have Lots Of Fun!'
));
return GenerateMd5($d);
}
/*
* Memo
*/
function MemoTest() {
$d = new PalmMemo();
$d->SetText('Rolling along with the wind is no place to be.');
return GenerateMd5($d);
}
/*
* SmallBASIC
*/
function SmallBASICTest() {
$d = new PalmSmallBASIC('pen.bas');
$text = "! pen \n" .
"\n" .
"print \"Use /B (Graffiti) to exit\"\n" .
"\n" .
"pen on\n" .
"while 1\n" .
" if pen(0)\n" .
" line pen(4),pen(5)\n" .
" fi\n" .
"wend\n" .
"pen off\n";;
$text = str_replace('!', '\'', $text);
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
$d->ConvertFromText($text);
return GenerateMd5($d);
}
/*
* Todo
*/
function TodoTest() {
$todo = new PalmTodoList();
// Add some categories
$categorias = array(
1 => 'Visita',
'Fax',
'Correo'
);
$todo->SetCategoryList($categorias);
// Add a record
$record = array(
'Description' => 'Enviar Fax',
'Note' => "25\nProbar palm",
'Priority' => 2
);
$todo->SetRecordRaw($record);
$todo->SetRecordAttrib(2); // Category #2
$todo->GoToRecord('+1');
// Add another record
$record = array(
'Description' => 'Llamar a juan',
'Note' => '35',
'DueDate' => '2002-5-31'
);
$todo->SetRecordRaw($record);
$todo->SetRecordAttrib(PDB_RECORD_ATTRIB_PRIVATE | PDB_RECORD_ATTRIB_DIRTY | 0); // Two flags and category 0
return GenerateMd5($todo);
}
/*////////////////////////////////////
* Thus began the utility functions //
* ////////////////////////////////////
*
* GenerateMd5
*/
function GenerateMd5(&$PalmDB, $DumpToScreen = false) {
/* Change the dates so the header looks the same no matter when we
* generate the file */
$PalmDB->CreationTime = 1;
$PalmDB->ModificationTime = 1;
$PalmDB->BackupTime = 1;
if (! $DumpToScreen)ob_start();
$PalmDB->WriteToStdout();
if (! $DumpToScreen) {
$file = ob_get_contents();
ob_end_clean();
return md5($file);
}
return 'MD5 not generated';
}
/*
* PassFail
*/
function PassFail($test, $want = false) {
global $TestType, $Tests;
// Run the test, and try to detect errors
error_reporting(0);
$test_1 = eval($test);
error_reporting(E_ALL);
$test_2 = eval($test);
if (!isset($Tests[$TestType]))$Tests[$TestType] = array(
'Fail' => 0,
'Pass' => 0
);
$FailMsg = '';
$Failure = false;
if ($test_1 != $test_2) {
$FailMsg = 'Warning or error encountered during test.';
$Failure = true;
} elseif ($want === false) {
if ($test_1) {
$FailMsg = "Data: \"$test_1\"";
$Failure = true;
}
} else {
if ($test_1 != $want) {
$FailMsg = "Wanted \"$want\" but got \"$test_1\"";
$Failure = true;
}
}
if ($Failure) {
echo "<FONT color=\"red\">fail</font><br>$FailMsg";
$Tests[$TestType]['Fail']++;
return 1;
}
echo '<FONT color="green">pass</font>';
$Tests[$TestType]['Pass']++;
return 0;
}