1 | /*
|
---|
2 | * module: pip/java/packing -- Strategy objects for converting
|
---|
3 | * Java objects to and from stored data.
|
---|
4 | * class: TestQuotedVectorPacking -- Test harness for QuotedVectorPacking
|
---|
5 | *
|
---|
6 | * Copyright (C) 1997 Pharos IP Pty Ltd
|
---|
7 | * $Id: TestQuotedVectorPacking.java 10737 2005-10-19 03:06:40Z kjdon $
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
22 | */
|
---|
23 |
|
---|
24 | package au.com.pharos.packing;
|
---|
25 |
|
---|
26 | import java.util.Vector;
|
---|
27 |
|
---|
28 | // TODO: Perhaps make this into a more general-purpose test harness
|
---|
29 | // for testing any Packing strategy? -- mbp 19971021
|
---|
30 |
|
---|
31 | /** Test harness for the QuotedVectorPacking strategy class.
|
---|
32 | *
|
---|
33 | * <P><B>Usage:</B>
|
---|
34 | * <UL><P><CODE>java TestQuotedVectorPacking -[de] ARGS</CODE><UL>
|
---|
35 | *
|
---|
36 | * <P><B>Options</B>
|
---|
37 | * <DL>
|
---|
38 | * <P><DT><CODE>-d</CODE><DD>Print the results of decoding
|
---|
39 | * the each of the command-
|
---|
40 | * line arguments as QuotedVectorPacking encoding strings
|
---|
41 | *
|
---|
42 | * <P><DT><CODE>-e</CODE><DD>Print the results of encoding
|
---|
43 | * a vector containing
|
---|
44 | * all of the command-line arguments
|
---|
45 | * </DL>
|
---|
46 | *
|
---|
47 | * @author Martin Pool
|
---|
48 | * @version $Revision: 10737 $ $Date: 2005-10-19 03:06:40 +0000 (Wed, 19 Oct 2005) $
|
---|
49 | **/
|
---|
50 | public class TestQuotedVectorPacking {
|
---|
51 | private TestQuotedVectorPacking() {}
|
---|
52 |
|
---|
53 | public static void main(String[] argv) {
|
---|
54 | Packing strat = new QuotedVectorPacking();
|
---|
55 | final String usage = "usage: TestQuotedVectorPacking -[ed] ARGS";
|
---|
56 |
|
---|
57 | if (argv.length == 0) {
|
---|
58 | System.err.println(usage);
|
---|
59 | return;
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (argv[0].equals("-e")) {
|
---|
63 | Vector encode = new Vector(argv.length - 1);
|
---|
64 | for (int i = 1; i < argv.length; i++) {
|
---|
65 | System.out.println(argv[i]);
|
---|
66 | encode.addElement(argv[i]);
|
---|
67 | }
|
---|
68 | byte[] packed = strat.toBytes(encode);
|
---|
69 | System.out.print("\t");
|
---|
70 | System.out.println(new String(packed));
|
---|
71 | } else if (argv[0].equals("-d")) {
|
---|
72 | for (int i = 1; i < argv.length; i++) {
|
---|
73 | Vector decode = (Vector) strat.fromBytes(argv[i].getBytes());
|
---|
74 | System.out.println(argv[i]);
|
---|
75 | for (int j = 0; j < decode.size(); j++) {
|
---|
76 | System.out.print("\t");
|
---|
77 | System.out.println(decode.elementAt(j));
|
---|
78 | }
|
---|
79 | }
|
---|
80 | } else {
|
---|
81 | System.err.println(usage);
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|