00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 import mango.io.Uri,
00214 mango.io.Stdio,
00215 mango.io.Token,
00216 mango.io.Reader,
00217 mango.io.Writer,
00218 mango.io.Buffer,
00219 mango.io.Socket,
00220 mango.io.Conduit,
00221 mango.io.FilePath,
00222 mango.io.FileStyle,
00223 mango.io.FileProxy,
00224 mango.io.Tokenizer,
00225 mango.io.TextReader,
00226 mango.io.TextWriter,
00227 mango.io.FileBucket,
00228 mango.io.FileConduit,
00229 mango.io.TextLayout,
00230 mango.io.TextFormat,
00231 mango.io.ColumnWriter,
00232 mango.io.DisplayWriter,
00233 mango.io.PickleReader,
00234 mango.io.PickleWriter,
00235 mango.io.SocketConduit,
00236 mango.io.SocketListener,
00237 mango.io.ArrayAllocator,
00238 mango.io.PickleRegistry,
00239 mango.io.DatagramSocket,
00240 mango.io.MulticastSocket;
00241
00242
00243 import mango.log.Logger,
00244 mango.log.Layout,
00245 mango.log.Manager,
00246 mango.log.XmlLayout,
00247 mango.log.DateLayout,
00248 mango.log.Configurator,
00249 mango.log.FileAppender,
00250 mango.log.ConsoleAppender,
00251 mango.log.RollingFileAppender;
00252
00253
00254 import mango.io.model.IReader,
00255 mango.io.model.IWriter,
00256 mango.io.model.IPickle;
00257
00258
00259 import mango.http.server.HttpParams,
00260 mango.http.server.HttpCookies,
00261 mango.http.server.HttpHeaders,
00262 mango.http.server.HttpServer,
00263 mango.http.server.HttpRequest,
00264 mango.http.server.HttpResponse,
00265 mango.http.server.HttpProvider;
00266
00267 import mango.http.server.model.IProvider,
00268 mango.http.server.model.IProviderBridge;
00269
00270 import mango.http.client.HttpClient;
00271
00272 import mango.servlet.Servlet,
00273 mango.servlet.ServletConfig,
00274 mango.servlet.ServletContext,
00275 mango.servlet.ServletProvider;
00276
00277 import mango.cache.PlainCache,
00278 mango.cache.HashMap,
00279 mango.cache.Payload,
00280 mango.cache.QueuedCache,
00281 mango.cache.VirtualCache;
00282
00283 import mango.cluster.Message,
00284 mango.cluster.NetworkQueue,
00285 mango.cluster.NetworkCache,
00286 mango.cluster.CacheInvalidator,
00287 mango.cluster.CacheInvalidatee;
00288
00289 import mango.cluster.qos.socket.Cluster,
00290 mango.cluster.qos.socket.ClusterServer,
00291 mango.cluster.qos.socket.ProtocolReader,
00292 mango.cluster.qos.socket.ProtocolWriter;
00293
00294 import mango.icu.UMango,
00295 mango.icu.UString,
00296 mango.icu.UDomainName,
00297 mango.icu.UStringPrep,
00298 mango.icu.UConverter,
00299 mango.icu.USet,
00300 mango.icu.UCollator,
00301 mango.icu.UTimeZone,
00302 mango.icu.UEnumeration,
00303 mango.icu.UMessageFormat;
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 private Logger logger;
00314
00315
00316
00317
00318
00319
00320
00321
00322 static void testBuffer()
00323 {
00324
00325 Buffer buf = new Buffer (256);
00326
00327
00328 Writer w = new Writer (buf);
00329 Reader r = new Reader (buf);
00330
00331 int i = 10;
00332 int j = 20;
00333 double d = 3.14159;
00334 char[] c = "testing";
00335
00336
00337 w << c << i << j << d;
00338
00339
00340 r >> c >> i >> j >> d;
00341
00342 assert(i==10);
00343 assert(j==20);
00344 assert(d==3.14159);
00345 assert(c=="testing");
00346
00347
00348 buf.clear();
00349
00350
00351 w.put(c).put(i).put(j).put(d);
00352 r.get(c).get(j).get(i).get(d);
00353
00354 assert(i==20);
00355 assert(j==10);
00356 assert(d==3.14159);
00357 assert(c=="testing");
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 static void testAppend()
00370 {
00371 char[] foo = "to write some D code";
00372
00373
00374 Buffer buf = new Buffer (256);
00375
00376
00377 buf.append("now is the time for all good men ").append(foo);
00378
00379
00380 Stdout.put (buf.toString).cr();
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 static void testToken1()
00392 {
00393
00394 static ubyte[128] storage;
00395 Buffer buf = new Buffer (storage);
00396
00397
00398 IWriter w = new TextWriter (buf, ",");
00399
00400
00401 BoundToken token = new BoundToken (Tokenizers.comma);
00402
00403
00404 w.put("now is the time for all good men").put(3.14159);
00405
00406
00407 while (token.next (buf))
00408 Stdout.put (token).cr();
00409 }
00410
00411
00412
00413
00414
00415
00416
00417 static void testToken2()
00418 {
00419
00420 Buffer buf = new Buffer (256);
00421
00422
00423 IWriter w = new TextWriter (buf, ",");
00424
00425
00426 w << "now is the time for all good men" << 3.14159;
00427
00428
00429 ReaderToken text = new ReaderToken (Tokenizers.comma);
00430 ReaderToken number = new ReaderToken (Tokenizers.comma);
00431
00432
00433 IReader r = new Reader (buf);
00434
00435
00436 r >> text >> number;
00437
00438
00439 Stdout << text << ':' << number;
00440 Stdout.cr();
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450 static void testToken3()
00451 {
00452
00453 Buffer buf = new Buffer (256);
00454
00455
00456 TextWriter tw = new TextWriter (buf, ",");
00457
00458
00459 tw << 101 << 3.14159;
00460
00461
00462 TextReader tr = new TextReader (buf, Tokenizers.comma);
00463
00464 real pi;
00465 int integer;
00466
00467
00468 tr >> integer >> pi;
00469
00470
00471 Stdout << integer << ',' << pi;
00472 Stdout.cr();
00473 }
00474
00475
00476
00477
00478
00479
00480
00481
00482 version (ArrayReaderSupport)
00483 {
00484 static void testToken4()
00485 {
00486
00487 FileConduit fc = new FileConduit ("test.txt");
00488
00489
00490 IBuffer buffer = fc.createBuffer ();
00491
00492
00493 TextReader tr = new TextReader (buffer, Tokenizers.line);
00494
00495 char[] ca;
00496
00497
00498 tr.get (ca);
00499
00500
00501 Stdout.put (ca).cr();
00502 }
00503 }
00504
00505
00506
00507
00508
00509
00510
00511
00512 static void testFormat()
00513 {
00514
00515 TextFormat tf = new TextFormat (256);
00516
00517
00518 Stdout.put (tf.format ("there are %d arguments to every %.*s", 3, "contradiction")).cr();
00519 }
00520
00521
00522
00523
00524
00525
00526
00527
00528 static void testLayout()
00529 {
00530
00531 TextLayout!(char) tl = new TextLayout!(char)(256);
00532
00533
00534 Stdout.put (tl.format ("%2 %1", "one", "two")).cr();
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544 static void testClassIO()
00545 {
00546
00547 class Foo : IReadable, IWritable
00548 {
00549 private int x = 11;
00550 private int y = 112;
00551
00552 void write(IWriter writer)
00553 {
00554
00555 writer << x << y;
00556 }
00557
00558 void read(IReader reader)
00559 {
00560
00561 reader.get(x).get(y);
00562 }
00563 }
00564
00565
00566 Buffer buf = new Buffer (256);
00567
00568
00569 Writer w = new Writer(buf);
00570 Reader r = new Reader(buf);
00571
00572
00573 Foo foo = new Foo();
00574
00575
00576 w << foo;
00577
00578
00579 r >> foo;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 static void testClassSerialization()
00595 {
00596
00597 class Bar : IPickle, IPickleFactory
00598 {
00599 private int x = 11;
00600 private int y = 112;
00601
00602 void write (IWriter writer)
00603 {
00604 writer.put(x).put(y);
00605 }
00606
00607 void read (IReader reader)
00608 {
00609 reader.get(x).get(y);
00610 assert (x == 11 && y == 112);
00611 }
00612
00613 Object create (IReader reader)
00614 {
00615 Bar bar = new Bar ();
00616 bar.read (reader);
00617 return bar;
00618 }
00619
00620 char[] getGuid ()
00621 {
00622 return "unittest.Bar";
00623 }
00624 }
00625
00626 static Object create (IReader reader)
00627 {
00628 Bar bar = new Bar();
00629 bar.read (reader);
00630 return bar;
00631 }
00632
00633
00634 Buffer buf = new Buffer (256);
00635 PickleWriter w = new PickleWriter (buf);
00636 PickleReader r = new PickleReader (buf);
00637
00638 r.setAllocator (new BufferAllocator);
00639
00640
00641 Bar bar = new Bar ();
00642
00643
00644
00645 PickleRegistry.enroll (bar);
00646
00647
00648 w.freeze (bar);
00649
00650
00651
00652 Object o = r.thaw ();
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662 static void testFile4()
00663 {
00664
00665 FileConduit fc = new FileConduit ("test.txt");
00666
00667
00668 Stdio.stdout.copy (fc);
00669 }
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 static void testRandomAccess()
00680 {
00681
00682 auto FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate);
00683
00684
00685 Reader r = new Reader(fc);
00686 Writer w = new Writer(fc);
00687
00688 int x=10, y=20;
00689
00690
00691 w.put(x).put(y);
00692
00693
00694 w.flush();
00695
00696
00697 fc.seek (0);
00698
00699
00700 r.get(y).get(x);
00701
00702 assert (y==10);
00703 assert (x==20);
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 static void testConduitFilters()
00715 {
00716 class MyFilter1 : ConduitSource
00717 {
00718 int reader (void[] dst)
00719 {
00720 printf ("filtering input ...\n");
00721 return next.reader (dst);
00722 }
00723 }
00724
00725 class MyFilter2 : ConduitSink
00726 {
00727 int writer (void[] src)
00728 {
00729 printf ("filtering output ...\n");
00730 return next.writer (src);
00731 }
00732 }
00733
00734
00735 auto FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate);
00736 fc.attach (new MyFilter2);
00737 fc.attach (new MyFilter1);
00738 fc.attach (new MyFilter1);
00739
00740
00741 Reader r = new Reader(fc);
00742 Writer w = new Writer(fc);
00743
00744 int x=1;
00745
00746
00747 w.put(x).flush();
00748
00749
00750 fc.seek (0);
00751
00752
00753 r.get(x);
00754 }
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764 static void testFile5()
00765 {
00766
00767 FileConduit fc = new FileConduit ("test.txt");
00768
00769
00770 IBuffer buffer = fc.createBuffer ();
00771
00772
00773
00774 while (fc.read (buffer) != fc.Eof)
00775 Stdio.stdout.write (buffer);
00776
00777
00778 Stdio.stdout.flush (buffer);
00779 }
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789 static void testFile1()
00790 {
00791
00792 FileConduit fc = new FileConduit ("test.txt");
00793
00794
00795 CompositeToken line = new CompositeToken (Tokenizers.line, fc);
00796
00797
00798
00799 while (line.get)
00800 Stdout.put(line).cr();
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811 static void testFile2()
00812 {
00813
00814 FileConduit fc = new FileConduit ("test.txt");
00815
00816
00817 IBuffer buffer = fc.createBuffer();
00818
00819
00820 BoundToken line = new BoundToken (Tokenizers.line);
00821
00822
00823
00824 while (line.next(buffer) || line.getLength())
00825 Stdout.put(line).cr();
00826 }
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 static void testFile3()
00837 {
00838
00839 FileConduit fc = new FileConduit ("test.txt");
00840
00841
00842 IBuffer buffer = fc.createBuffer();
00843
00844
00845 Token token = new Token ();
00846
00847
00848
00849 while (Tokenizers.line.next(buffer, token) || token.getLength())
00850 Stdout.put(token).cr();
00851 }
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 void testScanFiles()
00862 {
00863
00864
00865
00866
00867 struct Dependencies
00868 {
00869 FileProxy[] mods;
00870 FilePath[] pkgs;
00871 }
00872
00873
00874
00875
00876
00877 void scanFiles (inout Dependencies deps, FilePath base)
00878 {
00879
00880
00881
00882
00883
00884
00885
00886 bit filter (FilePath fp)
00887 {
00888 char[] sbuf = fp.getExtension();
00889
00890 if (fp.getName[0] != '.')
00891 if (sbuf.length == 0 || sbuf == "d")
00892 return true;
00893
00894 return false;
00895 }
00896
00897
00898
00899
00900
00901 FileProxy proxy = new FileProxy (base);
00902 FilePath[] paths = proxy.toList (&filter);
00903
00904
00905 if (paths.length)
00906 deps.pkgs ~= base;
00907
00908 foreach (FilePath x; paths)
00909 {
00910
00911 FilePath spliced = new FilePath (x.splice (base));
00912
00913
00914 proxy = new FileProxy (spliced);
00915 if (proxy.isDirectory)
00916 scanFiles (deps, spliced);
00917 else
00918 deps.mods ~= proxy;
00919 }
00920 }
00921
00922
00923
00924
00925
00926
00927 Dependencies deps;
00928 scanFiles (deps, new FilePath (r"\dmd\src\mango"));
00929
00930 Stdout.put ("-----------------").cr();
00931 foreach (FileProxy mod; deps.mods)
00932 Stdout.put (mod.getPath()).cr();
00933
00934 Stdout.put ("-----------------").cr();
00935 foreach (FilePath pkg; deps.pkgs)
00936 Stdout.put (pkg).cr();
00937 }
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949 static void testSocket()
00950 {
00951
00952 SocketConduit sc = new SocketConduit();
00953 sc.connect (new InternetAddress("www.digitalmars.com", 80));
00954
00955
00956 IWriter w = new DisplayWriter (sc);
00957
00958
00959 w.put ("GET /d/intro.html HTTP/1.1\r\n"
00960 "Host: www.digitalmars.com\r\n\r\n").flush();
00961
00962
00963 sc.setTimeout (System.Interval.Millisec * 500);
00964
00965
00966 Stdio.stdout.copy (sc);
00967 }
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 static void testColumn()
00978 {
00979 static int[] columns = [0, 4, 14, 24];
00980
00981
00982 ColumnWriter cw = new ColumnWriter (Stdout.getBuffer(), new ColumnList(columns));
00983
00984
00985 cw.setPrecision (2);
00986
00987
00988 cw.put(1);
00989 cw.put(20.34);
00990 cw.put("test");
00991 cw.cr();
00992 cw.put("next");
00993 }
00994
00995
00996
00997
00998
00999
01000
01001
01002 static void testStdin()
01003 {
01004 int x;
01005
01006
01007 Stdout << "Enter a number: ";
01008
01009
01010 Stdin >> x;
01011 }
01012
01013
01014 import std.regexp;
01015
01016
01017
01018
01019
01020
01021
01022 static void wordRegex (IBuffer buffer)
01023 {
01024
01025 RegexTokenizer rt = new RegexTokenizer (new RegExp(r"\w+", null));
01026
01027
01028 CompositeToken word = new CompositeToken (rt, buffer);
01029
01030
01031
01032 while (word.next)
01033 Stdout.put(word).cr();
01034 }
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 static void testFileRegex()
01046 {
01047
01048 FileConduit fc = new FileConduit ("test.txt");
01049
01050
01051 wordRegex (fc.createBuffer);
01052 }
01053
01054
01055
01056
01057
01058
01059
01060
01061 static void testSocketRegex()
01062 {
01063
01064 SocketConduit sc = new SocketConduit();
01065 sc.connect (new InternetAddress("www.digitalmars.com", 80));
01066
01067
01068 IWriter w = new DisplayWriter (sc);
01069
01070
01071 w.put ("GET /d/intro.html HTTP/1.1\r\n"
01072 "Host: www.digitalmars.com\r\n\r\n").flush();
01073
01074
01075 sc.setTimeout (System.Interval.Millisec * 500);
01076
01077
01078 wordRegex (sc.createBuffer);
01079 }
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090 static void testLineRegex()
01091 {
01092
01093 FileConduit fc = new FileConduit ("test.txt");
01094
01095
01096 CompositeToken line = new CompositeToken (Tokenizers.line, fc);
01097
01098
01099
01100
01101
01102
01103
01104 Buffer rescan = new Buffer;
01105
01106
01107 while (line.get)
01108 {
01109
01110 rescan.setValidContent (line.toString);
01111
01112
01113 wordRegex (rescan);
01114 }
01115
01116 }
01117
01118
01119
01120
01121
01122
01123
01124 static void testFileSize()
01125 {
01126 FileProxy fp = new FileProxy ("test.txt");
01127
01128 Stdout.put (fp.getPath)
01129 .put(" is ")
01130 .put(fp.getSize)
01131 .put(" bytes long")
01132 .cr();
01133 }
01134
01135
01136
01137
01138
01139
01140
01141
01142 static void testFileList()
01143 {
01144 FileProxy proxy = new FileProxy (r".");
01145
01146 foreach (FilePath path; proxy.toList())
01147 Stdout.put(path).cr();
01148 }
01149
01150
01151
01152
01153
01154
01155
01156 static void testFilePath()
01157 {
01158 FilePath path = new FilePath (r"c:\1\2\3\4\abc.foo.bar");
01159
01160 Stdout << path << Writer.newline;
01161
01162 Uri uri = path.toUri();
01163 Stdout << uri.getScheme() << Writer.newline
01164 << uri.getHost() << Writer.newline
01165 << uri.getPath() << Writer.newline
01166 << uri.getPort() << Writer.newline
01167 << uri << Writer.newline;
01168
01169 uri = new Uri (uri.toString());
01170 Stdout << uri.getScheme() << Writer.newline
01171 << uri.getHost() << Writer.newline
01172 << uri.getPath() << Writer.newline
01173 << uri.getPort() << Writer.newline
01174 << uri << Writer.newline;
01175
01176 path = new FilePath (uri);
01177
01178 Stdout << path << Writer.newline;
01179 }
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194 void testMappedFile()
01195 {
01196 FileConduit conduit = new FileConduit ("test.bin", FileStyle.ReadWriteCreate);
01197 conduit.seek (200_000_000);
01198 conduit.truncate ();
01199
01200 MappedBuffer buffer = conduit.createMappedBuffer;
01201 buffer.setPosition (100_000_000);
01202 buffer.append ("test");
01203 buffer.close ();
01204
01205 conduit.close ();
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216 static void testCompositeIO()
01217 {
01218
01219 class Wumpus : IReadable, IWritable
01220 {
01221 private int x = 11,
01222 y = 112,
01223 z = 1024;
01224
01225 void write(IWriter writer)
01226 {
01227 writer.put(x).put(y).put(z);
01228 }
01229
01230 void read(IReader reader)
01231 {
01232 reader.get(x).get(y).get(z);
01233 }
01234
01235 }
01236
01237
01238 Wumpus wumpus = new Wumpus();
01239
01240
01241 FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate);
01242
01243
01244 IWriter w = new Writer(fc);
01245 IReader r = new Reader(fc);
01246
01247
01248 w.put(wumpus).flush();
01249
01250
01251 fc.seek (0);
01252
01253
01254 r.get (wumpus);
01255
01256 fc.close();
01257 }
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273 static void testDirectIO()
01274 {
01275
01276 auto FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate);
01277
01278
01279 ubyte[1024] content;
01280
01281
01282
01283
01284 IBuffer direct = new Buffer(content, content.length);
01285
01286
01287 direct.setConduit(fc);
01288
01289
01290
01291
01292
01293
01294
01295 fc.write (direct);
01296
01297
01298 fc.seek (0);
01299
01300
01301 direct.clear();
01302
01303
01304 int count = fc.read (direct);
01305 delete fc;
01306
01307 }
01308
01309
01310
01311
01312
01313
01314 static void testUri()
01315 {
01316 MutableUri uri;
01317
01318 uri = new MutableUri ("ftp1://Me:My@a:21");
01319 Stdout << uri << Writer.newline;
01320
01321 uri.parse ("http://a:8080/b/c/d;p?q=bar of soap#fragmented");
01322 Stdout << uri << Writer.newline;
01323
01324 Stdin.wait();
01325
01326 for (int i=10_000_000; i > 0; --i)
01327 uri.parse ("http://a:8080/b/c/d;p?q=bar of soap#fragmented");
01328 }
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351 void testClient ()
01352 {
01353 Buffer buf = new Buffer(1024);
01354 InternetAddress addr = new InternetAddress("127.0.0.1", 80);
01355
01356 for (int i=50000; --i >= 0;)
01357 {
01358
01359 SocketConduit socket = new SocketConduit ();
01360 socket.connect (addr);
01361
01362
01363 socket.setLingerPeriod (0);
01364
01365
01366 buf.clear ();
01367
01368
01369
01370
01371
01372 buf.append ("GET / HTTP/1.1\n\n");
01373 /+
01374 buf.append("POST /RPC2 HTTP/1.1\n"
01375 "Content-Length: 157\n"
01376 "Content-Type: text/xml\n"
01377 "Cache-Control: no-cache\n"
01378 "Pragma: no-cache\n"
01379 "User-Agent: Java/1.4.2_05\n"
01380 "Host: localhost:8181\n"
01381 "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\n"
01382 "Connection: keep-alive\n\n"
01383 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><methodCall>"
01384 "<methodName>nnCore.getNode</methodName><params><param>"
01385 "<value>1@1</value></param></params></methodCall>");
01386 +/
01387 socket.write (buf);
01388
01389
01390 socket.read (buf);
01391
01392
01393
01394
01395
01396 socket.shutdown ();
01397
01398
01399 socket.close ();
01400 delete socket;
01401 }
01402 }
01403
01404
01405
01406
01407
01408
01409
01410
01411 void testServer (IProvider provider)
01412 {
01413
01414 InternetAddress addr = new InternetAddress (80);
01415
01416
01417 HttpServer server = new HttpServer (provider, addr, 1);
01418
01419
01420 server.start ();
01421
01422
01423 Stdout << "hit return to start the client test ...";
01424 Stdin.wait ();
01425
01426
01427 long time = System.getMillisecs;
01428 testClient ();
01429 Stdout.put (System.getMillisecs - time).cr();
01430 }
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440 void testHttpServer ()
01441 {
01442 class Provider : HttpProvider
01443 {
01444 void service (HttpRequest request, HttpResponse response)
01445 {
01446 response.sendError (HttpResponses.OK);
01447 }
01448 }
01449
01450
01451 testServer (new Provider());
01452 }
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 void testServletEngine ()
01463 {
01464
01465
01466
01467
01468
01469
01470 class FileServlet : MethodServlet
01471 {
01472 void doGet (IServletRequest request, IServletResponse response)
01473 {
01474 response.copyFile (request.getContext(), request.getPathInfo());
01475 }
01476 }
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486 class MyServlet : Servlet
01487 {
01488 void service (IServletRequest request, IServletResponse response)
01489 {
01490 Uri uri = request.getUri();
01491
01492
01493 Stdout.put ("------------------------")
01494 .cr ()
01495 .put ("Uri: ")
01496 .put (uri)
01497 .cr ()
01498 .put ("------------------------")
01499 .cr ()
01500 .put ("Headers:")
01501 .cr ()
01502 .put (request.getHeaders())
01503 .put ("------------------------")
01504 .cr ()
01505 .put ("Cookies:")
01506 .cr ()
01507 .put (request.getCookies())
01508 .put ("------------------------")
01509 .cr ()
01510 .put ("Parameters:")
01511 .cr ()
01512 .put (request.getParameters())
01513 .put ("------------------------")
01514 .cr ();
01515
01516
01517 Stdout.put("encoding: ")
01518 .put(request.getCharacterEncoding())
01519 .cr ()
01520 .put("content length: ").put(request.getContentLength())
01521 .cr ()
01522 .put("content type: ").put(request.getContentType())
01523 .cr ()
01524 .put("protocol: ").put(request.getProtocol())
01525 .cr ()
01526 .put("scheme: ").put(uri.getScheme())
01527 .cr ()
01528 .put("method: ").put(request.getMethod())
01529 .cr ()
01530 .put("host name: ").put(request.getServerName())
01531 .cr ()
01532 .put("host port: ").put(request.getServerPort())
01533 .cr ()
01534
01535
01536 .put("path info: ").put(request.getPathInfo())
01537 .cr ()
01538 .put("query: ").put(uri.getQuery())
01539 .cr ()
01540 .put("path: ").put(uri.getPath())
01541 .cr ()
01542 .put("context path: ").put(request.getContextPath())
01543 .cr ()
01544 .cr ()
01545 .cr ();
01546
01547 int i = request.getContentLength();
01548
01549 if (i > 0)
01550 {
01551 byte[] content = new byte[i];
01552
01553 request.getReader.getPostData (content);
01554 printf ("Content:\n>>%.*s<<\n\n\n", content);
01555 }
01556
01557
01558 response.getCookies().add (new Cookie ("fu", "'bar of soap'"));
01559
01560
01561 IWriter writer = response.getWriter();
01562 writer.put ("<HTML><HEAD><TITLE>Form</TITLE></HEAD>")
01563 .put ("<BODY><FORM method=POST action=\"/context/test\">")
01564 .put ("Enter a POST parameter: ")
01565 .put ("<INPUT type=text name=\"name\"><P>")
01566 .put ("<INPUT type=hidden name=\"hidden\" value=\"test\"><P>")
01567 .put ("<INPUT type=submit>")
01568 .put ("<?FORM></BODY></HTML>")
01569 .cr ();
01570
01571 }
01572 }
01573
01574
01575
01576 ServletProvider sp = new ServletProvider();
01577
01578
01579 IRegisteredServlet files = sp.addServlet (new FileServlet(), "files");
01580 sp.addMapping ("*.html", files);
01581 sp.addMapping ("*.htm", files);
01582
01583
01584 IRegisteredServlet test = sp.addServlet (new MyServlet(), "test");
01585 sp.addMapping ("/", test);
01586
01587
01588 testServer (sp);
01589 }
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599 void testHttpClient ()
01600 {
01601
01602
01603
01604
01605
01606
01607 void readBulk (IConduit conduit)
01608 {
01609
01610 Stdio.stdout.copy (conduit);
01611 }
01612
01613
01614
01615
01616
01617
01618
01619
01620 void readBulkExplicit (IConduit conduit)
01621 {
01622
01623 IBuffer buffer = conduit.createBuffer ();
01624
01625
01626
01627 while (conduit.read (buffer) != conduit.Eof)
01628 Stdio.stdout.write (buffer);
01629
01630
01631 assert (Stdio.stdout.flush (buffer));
01632 }
01633
01634
01635
01636
01637
01638
01639
01640
01641 void readLines (IConduit conduit)
01642 {
01643
01644 CompositeToken line = new CompositeToken (Tokenizers.line, conduit);
01645
01646
01647
01648 while (line.get)
01649 Stdout.put(line).cr();
01650 }
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663 void readChars (IConduit conduit)
01664 {
01665
01666 Reader reader = new Reader (conduit);
01667
01668
01669
01670
01671 try {
01672 while (true)
01673 {
01674 char c;
01675 reader.get (c);
01676 Stdout.put (c);
01677 }
01678 } catch (IOException x){}
01679 }
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689 void readChunks (IConduit conduit)
01690 {
01691 IBuffer buffer = new Buffer(1024);
01692
01693 while (conduit.read (buffer) != conduit.Eof)
01694 {
01695 Stdout.put (buffer.toString);
01696 buffer.clear ();
01697 }
01698 }
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711 void readChunksExplicit (IConduit conduit)
01712 {
01713 char[1024] content;
01714
01715 IBuffer buffer = new Buffer (content);
01716
01717 while (conduit.read (buffer) != conduit.Eof)
01718 {
01719 Stdout.put (content[0..buffer.readable()]);
01720 buffer.clear ();
01721 }
01722 }
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732 SocketConduit sc = new SocketConduit();
01733 sc.connect (new InternetAddress("www.digitalmars.com", 80));
01734
01735
01736 IWriter w = new FlushWriter (sc);
01737
01738
01739 w.put ("GET /d/intro.html HTTP/1.1")
01740 .cr ()
01741 .put ("Host: www.digitalmars.com")
01742 .cr ()
01743 .cr ();
01744
01745
01746 sc.setTimeout (System.Interval.Second);
01747
01748
01749
01750
01751
01752
01753 readChunksExplicit(sc);
01754 }
01755
01756
01757
01758
01759
01760
01761
01762
01763 void testHttpClient2 ()
01764 {
01765
01766 SocketConduit sc = new SocketConduit;
01767 sc.connect (new InternetAddress("www.digitalmars.com", 80));
01768
01769
01770 IWriter w = new FlushWriter (sc);
01771
01772
01773 w.put ("GET /d/intro.html HTTP/1.1")
01774 .cr ()
01775 .put ("Host: www.digitalmars.com")
01776 .cr ()
01777 .cr ();
01778
01779
01780 sc.setTimeout (System.Interval.Second);
01781
01782
01783 IBuffer buffer = sc.createBuffer;
01784
01785
01786 HttpHeaders headers = new HttpHeaders;
01787 headers.parse (buffer);
01788
01789
01790 foreach (HeaderElement header; headers)
01791 Stdout.put (header.name.value)
01792 .put (header.value)
01793 .cr ();
01794
01795
01796 while (sc.read (buffer) != sc.Eof)
01797 {
01798 Stdout.put (buffer.toString);
01799 buffer.clear ();
01800 }
01801 }
01802
01803
01804
01805
01806
01807
01808
01809 void testHttpClient3()
01810 {
01811
01812 auto HttpClient client = new HttpClient (HttpClient.Get, "http://www.digitalmars.com/d/intro.html");
01813
01814
01815 client.getRequestHeaders.add (HttpHeader.Host, client.getUri.getHost);
01816
01817
01818 IBuffer b = client.open ();
01819
01820
01821 if (client.isResponseOK)
01822 {
01823
01824 int length = client.getResponseHeaders.getInt (HttpHeader.ContentLength);
01825 if (length < 0)
01826 length = int.max;
01827
01828
01829 Stdout.put (client.getResponseHeaders);
01830
01831
01832 client.read (delegate (char[] c){Stdout.put(c);}, length);
01833 }
01834 else
01835 Stderr.put (client.getResponse);
01836 }
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852 void testPlainCache()
01853 {
01854 PlainCache cache = new PlainCache (2);
01855
01856 cache.put ("a", new Payload);
01857 cache.put ("b", new Payload);
01858 cache.put ("c", new Payload);
01859 cache.put ("c", new Payload);
01860
01861 cache.extract ("b");
01862 assert (cache.get("a"));
01863 assert (cache.get("c"));
01864 assert (cache.get("b") is null);
01865 }
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883 void testQueuedCache()
01884 {
01885 QueuedCache cache = new QueuedCache (2);
01886
01887 cache.put ("a", new Payload);
01888 cache.put ("b", new Payload);
01889 cache.put ("c", new Payload);
01890 cache.put ("c", new Payload);
01891
01892 assert (cache.get("a") is null);
01893 assert (cache.get("c"));
01894 }
01895
01896
01897
01898
01899
01900
01901
01902 void testFileBucket()
01903 {
01904 char[] text = "this is a test";
01905
01906 FileBucket bucket = new FileBucket (new FilePath ("bucket.bin"), FileBucket.HalfK, 0);
01907
01908
01909 bucket.put ("a", text);
01910 char[] b = cast(char[]) bucket.get ("a");
01911
01912 assert (b == text);
01913 bucket.close();
01914 }
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926 void testVirtualCache()
01927 {
01928 FileBucket bucket = new FileBucket (new FilePath ("bucket.bin"), FileBucket.HalfK);
01929 VirtualCache cache = new VirtualCache (bucket, 2);
01930 PickleRegistry.enroll (new Payload);
01931
01932 cache.put ("a", new Payload);
01933 cache.put ("b", new Payload);
01934 cache.put ("c", new Payload);
01935
01936 assert (cache.get("a"));
01937 assert (cache.get("c"));
01938 assert (cache.get("b"));
01939 bucket.close();
01940 }
01941
01942
01943
01944
01945
01946
01947 void testProtocol()
01948 {
01949 class Protocol : Payload
01950 {
01951 char[] x;
01952 int y = 10;
01953 bool z = true;
01954
01955 this ()
01956 {
01957 x = "fred";
01958 }
01959
01960 static this()
01961 {
01962 PickleRegistry.enroll(new Protocol);
01963 }
01964
01965 void write (IWriter w)
01966 {
01967 super.write (w);
01968 w.put (x)
01969 .put (y)
01970 .put (z);
01971 }
01972
01973 void read (IReader r)
01974 {
01975 super.read (r);
01976 r.get (x)
01977 .get (y)
01978 .get (z);
01979
01980 assert (x == "fred");
01981 assert (y == 10);
01982 assert (z == true);
01983 }
01984
01985 Payload create ()
01986 {
01987 return new Protocol;
01988 }
01989
01990 char[] getGuid ()
01991 {
01992 return this.classinfo.name;
01993 }
01994 }
01995
01996 Protocol p = new Protocol;
01997
01998 Buffer b = new Buffer (1024);
01999 ProtocolWriter w = new ProtocolWriter (b);
02000 ProtocolReader r = new ProtocolReader (b);
02001
02002 w.put (w.Command.Exception, "mychannel", p);
02003
02004 ubyte cmd;
02005 char[] channel,
02006 element;
02007
02008 p = cast(Protocol) r.getPayload (channel, element, cmd);
02009 }
02010
02011
02012
02013
02014
02015
02016
02017 void testHashMap()
02018 {
02019 class AAPut
02020 {
02021 Object[char[]] aa;
02022
02023 synchronized void put (char[] k, Object v)
02024 {
02025 aa[k] = v;
02026 }
02027
02028 synchronized Object get (char[] k)
02029 {
02030 if (k in aa)
02031 return aa[k];
02032 return null;
02033 }
02034
02035 synchronized void del (char[] k)
02036 {
02037 delete aa[k];
02038 }
02039 }
02040
02041
02042 static const char[] key = "dkfsdflksdjf s;dklf kdfjf;lskdfjs d;flskdfjs dfl";
02043
02044 AAPut aa = new AAPut;
02045 HashMap map = new HashMap (1024);
02046
02047 map.put (key, Client.EmptyMessage);
02048 aa.put (key, Client.EmptyMessage);
02049
02050 map.put ("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf", Client.EmptyMessage);
02051 aa.put ("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf", Client.EmptyMessage);
02052
02053 map.put ("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf 34534 5345", Client.EmptyMessage);
02054 aa.put ("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf 3453453535", Client.EmptyMessage);
02055
02056 logger.info ("A");
02057 for (int i=5_000_000; --i;)
02058 {
02059 map.put (key, Client.EmptyMessage);
02060 map.remove (key);
02061
02062 }
02063
02064 logger.info ("B");
02065 for (int i=5_000_000; --i;)
02066 {
02067 aa.put (key, Client.EmptyMessage);
02068 aa.del (key);
02069
02070 }
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080 }
02081
02082
02083
02084
02085
02086
02087
02088 version (Mango)
02089 {
02090 void testRollingFileLog()
02091 {
02092 Logger l = Logger.getLogger ("test");
02093 l.addAppender (new RollingFileAppender (new FilePath (r"e:\test.log"), 3, 1024, new DateLayout));
02094
02095 for (int i=100; --i;)
02096 l.error ("weqwer er wer werqwer wer wer wer wr wqrwe qrw rwe rwqerw");
02097 }
02098 }
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114 void testMulticast()
02115 {
02116 class MyListener : SocketListener
02117 {
02118 this (ISocketReader reader, IBuffer buffer)
02119 {
02120 super (reader, buffer);
02121 }
02122
02123 void notify (IBuffer buffer)
02124 {
02125 printf ("listener received %d bytes\n", buffer.readable());
02126 }
02127
02128 void exception (char[] msg)
02129 {
02130 printf ("listener error: %.*s\n", msg);
02131 }
02132 }
02133
02134
02135 MulticastSocket ms = new MulticastSocket ();
02136 InternetAddress ia = new InternetAddress ("226.1.1.1", 4444);
02137
02138 ms.join (ia);
02139 MyListener s = new MyListener (ms, new Buffer (2000));
02140 s.start ();
02141
02142 Stdin.wait ();
02143
02144
02145
02146 byte[1000] xx;
02147 Buffer b = new Buffer (xx, xx.length);
02148
02149 ms.write (b, ia);
02150 Stdin.wait ();
02151
02152 }
02153
02154
02155
02156
02157
02158 void testClusterCache()
02159 {
02160
02161
02162
02163
02164
02165 Cluster cluster = new Cluster (logger, 4567);
02166
02167
02168 NetworkCache cc = new NetworkCache (cluster, "myChannel");
02169
02170 InvalidatorPayload p = new InvalidatorPayload;
02171
02172 cc.put ("key", p);
02173
02174 for (int i=100_000; i; --i)
02175 {
02176
02177
02178
02179 IPayload p = cc.get ("key");
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190 }
02191
02192
02193
02194
02195
02196 }
02197
02198
02199
02200
02201
02202
02203 void testClusterQueue()
02204 {
02205 class Listen : IEventListener
02206 {
02207 void notify (IEvent event, IPayload payload)
02208 {
02209 printf ("recieved queue entry from channel '%.*s'\n", event.getChannel.getName);
02210 }
02211 }
02212
02213
02214
02215
02216 Cluster cluster = new Cluster (logger, 4567);
02217 NetworkQueue queue = new NetworkQueue (cluster, "queue.channel");
02218
02219 queue.createConsumer (new Listen);
02220 queue.put (new InvalidatorPayload);
02221 queue.put (new InvalidatorPayload);
02222
02223 Stdin.wait ();
02224 }
02225
02226
02227
02228
02229
02230
02231 void testInvalidatee()
02232 {
02233 ICluster c = new Cluster (logger);
02234
02235 CacheInvalidatee dst = new CacheInvalidatee (c, "abc", new PlainCache);
02236 CacheInvalidator src = new CacheInvalidator (c, "abc");
02237
02238 src.invalidate ("key1");
02239
02240 Stdin.wait ();
02241 }
02242
02243
02244
02245
02246
02247
02248
02249 void testClusterServer()
02250 {
02251 ClusterServer cs = new ClusterServer (new InternetAddress(81), 1);
02252 SocketConduit sc = new SocketConduit ();
02253 cs.start();
02254
02255 sc.connect (new InternetAddress ("127.0.0.1", 81));
02256 Stdin.wait ();
02257 }
02258
02259
02260
02261
02262
02263
02264
02265
02266 void testClusterMessage()
02267 {
02268 class MessageListener : IEventListener
02269 {
02270 void notify (IEvent event, IPayload payload)
02271 {
02272 IMessage message = cast(IMessage) payload;
02273
02274 printf ("Replying to message\n");
02275 event.reply (message.getReply, new InvalidatorPayload);
02276 }
02277 }
02278
02279 class ReplyListener : IEventListener
02280 {
02281 void notify (IEvent event, IPayload payload)
02282 {
02283 printf ("Received reply\n");
02284 }
02285 }
02286
02287
02288
02289
02290
02291 Cluster cluster = new Cluster (logger, 4567);
02292
02293
02294 NetworkMessage msg = new NetworkMessage (cluster, "message.channel", new ReplyListener);
02295
02296
02297 msg.createConsumer (new MessageListener);
02298
02299
02300 msg.put (new NullMessage);
02301
02302
02303 Stdin.wait ();
02304 }
02305
02306
02307
02308
02309
02310
02311
02312 void testCacheLoader()
02313 {
02314 class CacheLoader : ICacheLoader
02315 {
02316 bool test (IPayload p)
02317 {
02318 return false;
02319 }
02320
02321 IPayload load (char[] key, long time)
02322 {
02323 printf ("loading local cache instance\n");
02324 return new NullMessage;
02325 }
02326 }
02327
02328 IMutableCache mc = new PlainCache;
02329 ICache c = mc.bind (new CacheLoader);
02330
02331 c.get ("abcde");
02332 }
02333
02334
02335
02336
02337
02338
02339
02340 void testRemoteCacheLoader()
02341 {
02342 class RemoteCacheLoader : Payload, IRemoteCacheLoader
02343 {
02344 bool test (IPayload p)
02345 {
02346 return false;
02347 }
02348
02349 IPayload load (char[] key, long time)
02350 {
02351 printf ("loading remote cache instance\n");
02352 return new NullMessage;
02353 }
02354
02355
02356
02357
02358
02359
02360
02361 void read (IReader reader)
02362 {
02363 super.read (reader);
02364 }
02365
02366
02367
02368
02369
02370
02371
02372 void write (IWriter writer)
02373 {
02374 super.write (writer);
02375 }
02376
02377
02378
02379
02380
02381
02382
02383
02384 Object create (IReader reader)
02385 {
02386 Payload r = new RemoteCacheLoader;
02387 r.read (reader);
02388 return r;
02389 }
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400 char[] getGuid ()
02401 {
02402 return this.classinfo.name;
02403 }
02404
02405
02406 uint pause (uint wait)
02407 {
02408 return 100_000;
02409 }
02410 }
02411
02412 Cluster cluster = new Cluster (logger, 4567);
02413 NetworkCache nc = new NetworkCache (cluster, "my.channel");
02414 IRemoteCacheLoader cl = new RemoteCacheLoader;
02415 ICache c = nc.bind (cl);
02416
02417 c.get ("abcde");
02418 }
02419
02420 version (Mango)
02421 {
02422
02423
02424
02425
02426
02427 void testDisplay ()
02428 {
02429 IWriter w = new DisplayWriter (Stdio.stdout);
02430 w.setEncoder (new StringEncoder16 ("utf8"));
02431
02432 UString ss = new UString ("hello");
02433 w.put (ss);
02434
02435
02436 ubyte b = 129;
02437 uint ui = uint.max;
02438 int i = -3;
02439
02440 w.put (' ');
02441 w.put (1.12);
02442 w.put (' ');
02443
02444 w.put(b).put(' ')
02445 .put(ui).put(' ')
02446 .put(i).put(' ')
02447 .put("hello")
02448 .cr()
02449 .flush();
02450 }
02451
02452
02453
02454
02455
02456
02457
02458 void testStringLoader ()
02459 {
02460 Stdout.setEncoder (new StringEncoder16 ("utf8"));
02461
02462 Buffer b = new Buffer ("hello", 5);
02463 UString ss = new UString (b, b.readable(), new UConverter("utf8"));
02464 Stdout.put(ss).cr();
02465 }
02466
02467
02468
02469
02470
02471
02472
02473 void testDecoder ()
02474 {
02475 IWriter w = new Writer (new Buffer(100));
02476 IReader r = new Reader (w.getBuffer());
02477 r.setAllocator (new BufferAllocator);
02478
02479 UConverter cvt = new UConverter("utf16");
02480 w.setEncoder (new StringEncoder16 (cvt));
02481 r.setDecoder (new StringDecoder16 (cvt));
02482
02483 UString ss = new UString ("hello");
02484
02485 w.put (ss);
02486 r.get (ss);
02487
02488 Stdout.setEncoder (new StringEncoder16("utf8"));
02489 Stdout.put(ss).cr();
02490 }
02491 }
02492
02493
02494
02495
02496
02497
02498 void testTextWriter ()
02499 {
02500 IWriter w = new TextWriter (Stdout.getBuffer(), ", ");
02501
02502 ubyte b = 129;
02503 uint ui = uint.max;
02504 int i = -3;
02505
02506 w.put(b)
02507 .put(ui)
02508 .put(i)
02509 .put("hello")
02510 .cr();
02511 w.put("test");
02512 }
02513
02514
02515
02516
02517
02518 /+
02519 void testDOM ()
02520 {
02521 alias mango.xml.dom.model.Node.Node Node;
02522 Document doc = new DocumentImpl(null, null);
02523 Element root = doc.createElement(new UString("root"));
02524 Element text = doc.createElement(new UString("text"));
02525 root.appendChild(text);
02526 CDATASection data = doc.createCDATASection(new UString("this is my text"));
02527 text.appendChild(data);
02528 Element secText = doc.createElement(new UString("text"));
02529 assert (secText !== null);
02530 root.appendChild(secText);
02531 assert (root.childNodes.length == 2);
02532 assert (root.childNodes.item(0) === text);
02533 assert (root.childNodes.item(1) === secText);
02534 assert (cast(Element)secText.parentNode === root);
02535 assert (cast(Element)secText.previousSibling !== null);
02536 assert (cast(Element)text.nextSibling === secText);
02537
02538 Element top = doc.createElement(new UString("top"));
02539 root.insertBefore(top, text);
02540 assert (root.childNodes.length == 3);
02541 assert (root.childNodes.item(0) === top);
02542 assert (root.childNodes.item(1) === text);
02543 assert (root.childNodes.item(2) === secText);
02544 assert (text.previousSibling === top);
02545 }
02546 +/
02547
02548
02549
02550
02551
02552
02553 int main(char[][] args)
02554 {
02555 BasicConfigurator.configure ();
02556
02557 logger = Logger.getLogger ("mango.unittest");
02558
02559
02560
02561
02562
02563 try {
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618 logger.info ("Done");
02619 } catch (Object x)
02620 {
02621 logger.fatal (x.toString);
02622 }
02623
02624 return 0;
02625 }
02626