Index: lutinutil/src/test/org/codelutin/util/StringUtilTest.java diff -u lutinutil/src/test/org/codelutin/util/StringUtilTest.java:1.2 lutinutil/src/test/org/codelutin/util/StringUtilTest.java:1.3 --- lutinutil/src/test/org/codelutin/util/StringUtilTest.java:1.2 Fri Jan 14 16:09:10 2005 +++ lutinutil/src/test/org/codelutin/util/StringUtilTest.java Thu Aug 25 21:16:51 2005 @@ -23,9 +23,9 @@ * Created: 7 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2005/01/14 16:09:10 $ + * Mise a jour: $Date: 2005/08/25 21:16:51 $ * par : $Author: bpoussin $ */ @@ -66,6 +66,33 @@ }catch(StringUtilException eee){ assertNull(c); } + } + + public void testConvert() throws Exception { + assertEquals("365d", StringUtil.convertTime(31536000000000000L)); + assertEquals("2d", StringUtil.convertTime(172800000000000L)); + assertEquals("2h", StringUtil.convertTime(7200000000000L)); + assertEquals("2m", StringUtil.convertTime(120000000000L)); + assertEquals("2,02s", StringUtil.convertTime(2020000002L)); + assertEquals("2s", StringUtil.convertTime(2000000002L)); + assertEquals("2s", StringUtil.convertTime(2000000000L)); + assertEquals("2ms", StringUtil.convertTime(2000000L)); + assertEquals("2ns", StringUtil.convertTime(2L)); + assertEquals("0ns", StringUtil.convertTime(0L)); + + assertEquals("0o", StringUtil.convertMemory(0L)); + assertEquals("2o", StringUtil.convertMemory(2L)); + assertEquals("2Ko", StringUtil.convertMemory(2048L)); + assertEquals("2Mo", StringUtil.convertMemory(2097152L)); + assertEquals("2Mo", StringUtil.convertMemory(2097154L)); + assertEquals("2,09Mo", StringUtil.convertMemory(2196152L)); + assertEquals("2Go", StringUtil.convertMemory(2147483648L)); + assertEquals("2To", StringUtil.convertMemory(2199023255552L)); + assertEquals("2000To", StringUtil.convertMemory(2199023255552000L)); + + assertEquals("-2Mo", StringUtil.convertMemory(-2097152L)); + assertEquals("-2Mo", StringUtil.convertMemory(-2097154L)); + assertEquals("-2,09Mo", StringUtil.convertMemory(-2196152L)); } } // StringUtilTest Index: lutinutil/src/test/org/codelutin/util/CallAnalyseTest.java diff -u /dev/null lutinutil/src/test/org/codelutin/util/CallAnalyseTest.java:1.1 --- /dev/null Thu Aug 25 21:16:56 2005 +++ lutinutil/src/test/org/codelutin/util/CallAnalyseTest.java Thu Aug 25 21:16:51 2005 @@ -0,0 +1,85 @@ +/* *##% + * Copyright (C) 2005 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * CallAnalyseTest.java + * + * Created: 25 août 2005 21:03:50 CEST + * + * @author Benjamin POUSSIN + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2005/08/25 21:16:51 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.util.ArrayList; +import java.util.List; +import junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class CallAnalyseTest extends TestCase { // CallAnalyseTest + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(CallAnalyseTest.class); + + protected List memoryConsume = new ArrayList(); + + public void testCall() throws Exception { + CallAnalyse.activate(); + for(int i=0; i<10; i++){ + eatMemory(); + freeMemory(); + } + + assertEquals(10, CallAnalyse.getThreadStatistics().get("eatMemory").getCalls()); + assertEquals(10, CallAnalyse.getThreadStatistics().get("freeMemory").getCalls()); + + System.out.println(CallAnalyse.getThreadStatistics()); + } + + protected void eatMemory(){ + CallAnalyse.enter("eatMemory"); + try{ + for(int i=0; i<100; i++){ + memoryConsume.add(new ArrayList(100)); + } + }catch(Exception eee){ + // do nothing + } finally { + CallAnalyse.exit("eatMemory"); + } + } + + protected void freeMemory(){ + CallAnalyse.enter("freeMemory"); + try{ + memoryConsume.clear(); + }catch(Exception eee){ + // do nothing + } finally { + CallAnalyse.exit("freeMemory"); + } + } + +} // CallAnalyseTest +