| 1 28 29 package com.idaremedia.antx.solo.tests; 30 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 33 34 import junit.framework.TestSuite; 35 import org.apache.tools.ant.BuildException; 36 37 import com.idaremedia.antx.ut.HTC; 38 import com.idaremedia.antx.ut.HTCUtils; 39 40 import com.idaremedia.antx.helpers.InnerString; 41 import com.idaremedia.antx.ownhelpers.LocalTk; 42 import com.idaremedia.antx.solo.StringList; 43 44 53 54 public final class StringListTest extends HTC 55 { 56 57 public static final String TEST_CATEGORY="CLASS"; 58 59 60 63 public StringListTest(String methodName) 64 { 65 super("StringList::",methodName); 66 } 67 68 69 72 public static TestSuite suite() 73 { 74 return new TestSuite(StringListTest.class); 75 } 76 77 78 81 public static TestSuite baseline() 82 { 83 return suite(); 84 } 85 86 87 90 public static void main(String [] argv) 91 { 92 HTCUtils.quickCheck(suite()); 93 } 94 95 99 final static String PFX="CALL("; 100 final static String SFX=")"; 101 102 protected void setUp() throws Exception  103 { 104 configureProjectFromResource("lists.xml"); 105 } 106 107 private void addABCStrings(StringList out) 108 { 109 InnerString i= new InnerString(); 110 i.setValue("a"); 111 out.addConfiguredString(i); 112 i.setValue("b"); 113 out.addConfiguredString(i); 114 i.setValue("c"); 115 out.addConfiguredString(i); 116 assertFalse(out.isEmpty()); 117 } 118 119 private void verifyABCStrings(StringList out, Iterator itr, String who) 120 { 121 assertNotNil(itr); 122 ArrayList sl= new ArrayList (); 123 while (itr.hasNext()) { 124 sl.add(itr.next()); 125 try {itr.remove();} catch(UnsupportedOperationException igx) {} 126 } 127 assertEqual(sl.size(),3); 128 assertEqual(sl.get(0),"a",who+".item@1"); 129 assertEqual(sl.get(1),"b",who+".item@2"); 130 assertEqual(sl.get(2),"c",who+".item@3"); 131 assertEqual(out.toString(),"a,b,c"); } 133 134 private void verifyABCStrings(StringList out, String who) 135 { 136 verifyABCStrings(out,out.readonlyIterator(),who); 137 verifyABCStrings(out,out.readonlyStringIterator(),who); 138 } 139 140 private void verifyABCStrings(StringList out, Iterator itr, 141 String pfx, String sfx,String who) 142 { 143 assertNotNil(itr); 144 ArrayList sl= new ArrayList (); 145 while (itr.hasNext()) { 146 sl.add(itr.next()); 147 try {itr.remove();} catch(UnsupportedOperationException igx) {} 148 } 149 assertEqual(sl.size(),3); 150 assertEqual(sl.get(0),pfx+"a"+sfx,who+".item@1"); 151 assertEqual(sl.get(1),pfx+"b"+sfx,who+".item@2"); 152 assertEqual(sl.get(2),pfx+"c"+sfx,who+".item@3"); 153 String X= pfx+"a"+sfx+","+pfx+"b"+sfx+","+pfx+"c"+sfx; 154 assertEqual(out.toString(),X); } 156 157 private void verifyABCStrings(StringList out, String pfx, String sfx,String who) 158 { 159 verifyABCStrings(out,out.readonlyIterator(),pfx,sfx,who); 160 verifyABCStrings(out,out.readonlyStringIterator(),pfx,sfx,who); 161 } 162 163 167 public void checkBaseline() 168 { 169 } 171 172 public void testBaseline() 173 { 174 checkBaseline(); 175 } 176 177 178 public void testEmptyStringListOK_AntX03() 179 { 180 runTarget("testEmptyStringListOK_AntX03"); 181 } 182 183 184 public void testConstructor_AntX03() 185 { 186 StringList out = new StringList("a,b,c"); 187 verifyABCStrings(out,"ctor(orig)"); 188 StringList copy = (StringList)out.clone(); 189 verifyABCStrings(copy,"ctor(copy)"); 190 } 191 192 193 public void testAddingStrings_AntX03() 194 { 195 StringList out = new StringList(); 196 assertTrue(out.isEmpty()); 197 addABCStrings(out); 198 verifyABCStrings(out,"add(orig)"); 199 StringList copy = (StringList)out.clone(); 200 verifyABCStrings(copy,"add(copy)"); 201 } 202 203 204 public void testPrefixSuffix_AntX03() 205 { 206 StringList out = new StringList(); 207 out.setPrefix(PFX); 208 out.setSuffix(SFX); 209 addABCStrings(out); 210 verifyABCStrings(out,PFX,SFX,"pfxsfx(orig.a)"); 211 StringList copy = (StringList)out.clone(); 212 verifyABCStrings(copy,PFX,SFX,"pfxsfx(copy.a)"); 213 copy.setPrefix("BLABLABLA"); 214 verifyABCStrings(out,PFX,SFX,"pfxsfx(orig.b)"); 215 verifyABCStrings(copy,"BLABLABLA",SFX,"pfxsfx(copy.b)"); 216 } 217 218 219 public void testStringListDelim_AntX03() 220 { 221 runTarget("testStringListDelim_AntX03"); 222 } 223 224 225 226 public void testStringListReferences_AntX03() 227 { 228 runTarget("testStringListReferences_AntX03"); 229 230 Object o = getProject().getReference("abcstrings"); 233 assertNotNil(o); 234 StringList out = new StringList(); 235 out.setRefid(LocalTk.referenceFor("abcstrings",getProject())); 236 assertTrue(out.isReference()); 237 try { out.setPrefix("phffht"); } 238 catch(BuildException bx) {} 239 try { out.setSuffix("phffht"); } 240 catch(BuildException bx) {} 241 } 242 243 244 245 public void testStringListFromFiles_AntX04() 246 { 247 runTarget("testStringListFromFiles_AntX04"); 248 } 249 250 251 252 public void testIncludeOtherStringList_AntX05() 253 { 254 runTarget("testIncludeOtherStringList_AntX05"); 255 } 256 } 257 258 259 260 | Popular Tags |