1   package test16;
2   
3   import java.io.PrintStream;
4   import java.util.ArrayList;
5   import java.util.HashMap;
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   import junit.ParamSetTestCase;
10  import junit.framework.Test;
11  import junit.framework.TestSuite;
12  import net.sourceforge.jparam.JParam;
13  import net.sourceforge.jparam.JParamException;
14  import net.sourceforge.jparam.paramset.Param;
15  import net.sourceforge.jparam.paramset.ioParam;
16  import net.sourceforge.jparam.typename.TypeNameRegistry;
17  
18  public class test16 {
19  
20  	public static Test suite() {
21  		TestSuite suite = new TestSuite("Test for test16");
22  		//$JUnit-BEGIN$
23  		suite.addTestSuite(t1.class);
24  		suite.addTestSuite(t2.class);
25  		//$JUnit-END$
26  		return suite;
27  	}
28  
29  	public static class Pair {
30  		public Object o1, o2;
31  
32  		public Pair(Object o1, Object o2) {
33  			this.o1 = o1;
34  			this.o2 = o2;
35  		}
36  	}
37  
38  	public static class Gooseberry {
39  		int n;
40  
41  		public Gooseberry() {
42  		}
43  
44  		public Gooseberry(int i) {
45  			n = i;
46  		}
47  
48  		int num() {
49  			return n;
50  		}
51  	};
52  
53  	public static class Goose {
54  		int n;
55  
56  		public Goose() {
57  		}
58  
59  		public Goose(int i) {
60  			n = i;
61  		}
62  
63  		public Goose(Gooseberry d) {
64  			n = d.num() * 2;
65  		}
66  
67  		int num() {
68  			return n;
69  		}
70  
71  		public int hashCode() {
72  			return 0;
73  		}
74  
75  		public boolean equals(Object obj) {
76  			return (obj instanceof Goose) && (((Goose) obj).n == n);
77  		}
78  	};
79  
80  	public static class Bottle {
81  		String message;
82  
83  		public Bottle() {
84  			this("No message");
85  		}
86  
87  		public Bottle(int i) {
88  			this("" + i);
89  		}
90  
91  		public Bottle(String message) {
92  			this.message = message;
93  		}
94  	}
95  
96  	public static class Serializers {
97  		public static void serialize(Pair pair, PrintStream out)
98  				throws JParamException {
99  			Class o1Type = pair.o1.getClass();
100 			Class o2Type = pair.o2.getClass();
101 			TypeNameRegistry tnr = TypeNameRegistry.getInstance();
102 			String o1TypeName = tnr.getJParamTypeName(o1Type);
103 			String o2TypeName = tnr.getJParamTypeName(o2Type);
104 
105 			out.print("pair");
106 			if ((o1TypeName != null) && (o2TypeName != null)) {
107 				out.print("<" + o1TypeName + "," + o2TypeName + ">");
108 			}
109 			out.print("(");
110 			JParam.writeObject(pair.o1, out);
111 			out.print(",");
112 			JParam.writeObject(pair.o2, out);
113 			out.print(")");
114 		}
115 
116 		public static List output(Goose goose) {
117 			List subObjects = new LinkedList();
118 			subObjects.add(new Integer(goose.n));
119 			return subObjects;
120 		}
121 
122 		public static List output(Bottle bottle) {
123 			List subObjects = new LinkedList();
124 			subObjects.add(bottle.message);
125 			return subObjects;
126 		}
127 	}
128 
129 	public static class test16_base extends ParamSetTestCase {
130 		String[] inputStrings;
131 
132 		protected void setUp() throws Exception {
133 			super.setUp();
134 			JParam.registerClass("pair", Pair.class);
135 			JParam.registerClass("goose", Goose.class);
136 			JParam.registerClass("gooseberry", Gooseberry.class);
137 			JParam.registerClass("bottle", Bottle.class);
138 			JParam.registerHelperClass(Serializers.class);
139 			JParam.registerConstant("groucho", new Goose(15));
140 
141 			DEBUG = true;
142 		}
143 
144 		/*
145 		 * map <goose,bottle> bot_map; map <goose,bottle*> bot_ptr_map; map
146 		 * <goose,const bottle*> bot_cptr_map;
147 		 *  
148 		 */
149 		public Param[] getInitParams() throws Exception {
150 			return new Param[] { new ioParam("p", Pair.class),
151 					new ioParam("v", ArrayList.class),
152 					new ioParam("vp", ArrayList.class),
153 					new ioParam("vcp", ArrayList.class),
154 					new ioParam("l", LinkedList.class),
155 					new ioParam("lp", LinkedList.class),
156 					new ioParam("lcp", LinkedList.class),
157 					new ioParam("str_map", HashMap.class),
158 					new ioParam("bot_map", HashMap.class),
159 					new ioParam("bot_ptr_map", HashMap.class),
160 					new ioParam("bot_cptr_map", HashMap.class), };
161 		}
162 
163 		public String[] getInput() {
164 			return inputStrings;
165 		}
166 
167 		public Object[] getExpectedParameterValues() {
168 			//return new Param[]{a, b, c, d};
169 			return null;
170 		}
171 	}
172 
173 	public static class t1 extends test16_base {
174 		public t1() {
175 			inputStrings = new String[] { "p=pair<goose,double>(groucho,3.1) "
176 					+ "v=[goose(0), goose(3), goose(4)] "
177 					+ "vp=[1, groucho] "
178 					+ "vcp=[goose(0), goose(5)] "
179 					+ "l=goose(1), goose(2), goose(3) "
180 					+ "lp=goose(0), goose(4) ,goose(5) "
181 					+ "lcp=[goose(11)] "
182 					+ "str_map={ groucho => one, goose(5) => two} "
183 					+ "bot_map={ goose(0) => bottle(three) } "
184 					+ "bot_ptr_map= { goose(4) => bottle(4), goose(5) => bottle(5) } "
185 					+ "bot_cptr_map = {goose(6)=>bottle(6), goose(7)=>bottle(7)}" };
186 		}
187 	};
188 
189 	public static class t2 extends test16_base {
190 		public t2() {
191 			inputStrings = new String[] { "p=pair<goose,double>(groucho,3.1) "
192 					+ "v=vector<goose>(3,goose(3)) "
193 					+ "vp=vector<goose*>(1,goose(1)) "
194 					+ "vcp=vector<const goose*>(0,0) "
195 					+ "l=list<goose>(0,0) "
196 					+ "lp=list<goose*>(3,NULL) "
197 					+ "lcp=list<const goose*>(4,goose(1)) "
198 					+ "str_map=map<goose,string>({ groucho => one, goose(5) => two}) "
199 					+ "bot_map={} "
200 					+ "bot_ptr_map= { goose(4) => bottle(NULL), goose(5) => bottle(NULL) } "
201 					+ "bot_cptr_map = {goose(6)=>bottle(6), goose(7)=>bottle(7)}" };
202 		}
203 	};
204 
205 }