[slf4j-dev] svn commit: r14 - in slf4j/trunk/tests: . src src/java src/java/org src/java/org/slf4j src/java/org/slf4j/impl

ceki at slf4j.org ceki at slf4j.org
Fri Apr 22 16:40:14 CEST 2005


Author: ceki
Date: Fri Apr 22 16:40:13 2005
New Revision: 14

Added:
   slf4j/trunk/tests/
   slf4j/trunk/tests/build.xml
   slf4j/trunk/tests/src/
   slf4j/trunk/tests/src/java/
   slf4j/trunk/tests/src/java/org/
   slf4j/trunk/tests/src/java/org/slf4j/
   slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java
   slf4j/trunk/tests/src/java/org/slf4j/impl/
   slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java
Log:
added invocation tests

Added: slf4j/trunk/tests/build.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/tests/build.xml	Fri Apr 22 16:40:13 2005
@@ -0,0 +1,165 @@
+<project name="testing-SLF4J" default="usage" basedir="." >
+
+  <property name="tests.source.home" value="./src/java/"/>
+  <property name="tests.javac.dest" value="classes"/>
+
+  <property name="version" value="1.0"/>
+  <property name="deprecation" value="on"/>
+   
+  <path id="basic.classpath">
+    <pathelement location="${tests.source.home}"/>
+    <pathelement location="${tests.javac.dest}"/>
+    <pathelement location="${jakarta-oro.jar}"/>
+  </path>
+
+  <path id="compile.classpath">
+    <path refid="basic.classpath"/>
+    <pathelement location="../slf4j-simple.jar"/>
+  </path>
+  
+  <path id="nop.classpath">
+    <path refid="basic.classpath"/>
+    <pathelement location="../slf4j-nop.jar"/>
+  </path>
+
+  <path id="simple.classpath">
+    <path refid="basic.classpath"/>
+    <pathelement location="../slf4j-simple.jar"/>
+  </path>
+
+   <path id="jdk14.classpath">
+    <path refid="basic.classpath"/>
+    <pathelement location="../slf4j-jdk14.jar"/>
+  </path>
+
+   <path id="log4j.classpath">
+     <path refid="basic.classpath"/>
+     <fileset dir="..">
+       <include name="log4j-*.jar"/>
+     </fileset>
+  </path>
+
+
+
+  <!-- ================================================================= -->
+  <!-- Default target                                                    -->
+  <!-- ================================================================= -->
+  <target name="usage">
+    <echo>      
+      These are some of the targets supported by this ANT build scpript:
+      
+      build - compile all project files, if a certain library is missing, 
+              then the compilation of its dependents are skipped.
+
+      runAll - run all available tests
+      
+    </echo>
+  </target>
+
+  <target name="init">
+    <mkdir dir="${tests.javac.dest}"/>
+    <mkdir dir="output"/>
+  </target>
+
+  <target name="clean">
+    <delete>
+      <fileset dir="${tests.javac.dest}" includes="**"/>
+    </delete>
+  </target>
+
+  <target name="cleanOutputDir">
+    <delete>
+      <fileset dir="output" includes="**"/>
+    </delete>
+  </target>
+
+  <target name="build" depends="init, slf4j-simple.jar">
+    <javac srcdir="${tests.source.home}"
+           destdir="${tests.javac.dest}" 
+           includes="**/*.java"
+	   deprecation="${deprecation}"
+	   debug="on">
+      <classpath refid="compile.classpath"/>
+    </javac>
+  </target>
+
+  <target name="slf4j-nop.jar">
+    <!-- Invoke build.xml located one directory up -->
+    <ant  dir=".." antfile="build.xml" target="slf4j-nop.jar"/> 
+  </target>
+
+  <target name="slf4j-simple.jar">
+    <!-- Invoke build.xml located one directory up -->
+    <ant  dir=".." antfile="build.xml" target="slf4j-simple.jar"/> 
+  </target>
+
+  <target name="slf4j-jdk14.jar">
+    <ant  dir=".." antfile="build.xml" target="slf4j-jdk14.jar"/> 
+  </target>
+
+  <target name="log4j.jar">
+    <!-- The main build is big enough to have its own properties -->
+    <ant  dir=".." antfile="build.xml" target="log4j.jar" inheritAll="false"/> 
+  </target>
+  
+  <!-- ================================================================= -->
+  <!-- Run all tests                                                     -->
+  <!-- ================================================================= -->  
+  <target name="runAll" depends="regression"/>
+  
+
+  <target name="regression" depends="MessageFormatter,
+                                     InvokeNOP,
+                                     InvokeSimple,
+                                     InvokeJDK14"
+                                     />
+
+  <target name="MessageFormatter" depends="build, cleanOutputDir">
+    <junit printsummary="yes" fork="yes" haltonfailure="yes">
+      <classpath refid="compile.classpath"/>
+      <formatter type="plain" usefile="false"/>
+      <test name="org.slf4j.impl.MessageFormatterTest" />
+    </junit>
+  </target> 
+
+  <target name="InvokeNOP" depends="build, slf4j-nop.jar, cleanOutputDir">
+    <junit printsummary="yes" fork="yes" haltonfailure="yes">
+      <classpath refid="nop.classpath"/>
+      <formatter type="plain" usefile="false"/>
+      <test name="org.slf4j.InvokingSLF4J" />
+    </junit>
+  </target>
+
+  <target name="InvokeSimple" depends="build, slf4j-simple.jar, cleanOutputDir">
+    <junit printsummary="yes" fork="yes" haltonfailure="yes">
+      <classpath refid="simple.classpath"/>
+      <formatter type="plain" usefile="false"/>
+      <test name="org.slf4j.InvokingSLF4J" />
+    </junit>
+  </target>
+
+  <target name="InvokeJDK14" depends="build, slf4j-jdk14.jar, cleanOutputDir">
+    <junit printsummary="yes" fork="yes" haltonfailure="yes">
+      <classpath refid="jdk14.classpath"/>
+      <formatter type="plain" usefile="false"/>
+      <test name="org.slf4j.InvokingSLF4J" />
+    </junit>
+  </target>
+
+
+  <target name="InvokeLog4j" depends="build, log4j.jar, cleanOutputDir">
+    
+    <copy file="input/slf4j/basic.xml" tofile="${tests.javac.dest}/log4j.xml"/>
+
+    <junit printsummary="yes" fork="yes" haltonfailure="yes">
+      <classpath refid="log4j.classpath"/>
+      <formatter type="plain" usefile="false"/>
+      <test name="org.slf4j.InvokingSLF4" />
+    </junit>
+
+    <delete file="${tests.javac.dest}/log4j.xml"/>
+
+  </target>
+
+
+</project>

Added: slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java	Fri Apr 22 16:40:13 2005
@@ -0,0 +1,75 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * Copyright (c) 2004-2005 QOS.CH
+ * 
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to  deal in  the Software without  restriction, including
+ * without limitation  the rights to  use, copy, modify,  merge, publish,
+ * distribute, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+ * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test whether invoking the SLF4J API causes problems or not.
+ * 
+ * @author Ceki Gulcu
+ *
+ */
+public class InvokingSLF4J extends TestCase {
+
+  public InvokingSLF4J (String arg0) {
+    super(arg0);
+  }
+
+  /*
+   * @see TestCase#setUp()
+   */
+  protected void setUp() throws Exception {
+    super.setUp();
+  }
+
+  /*
+   * @see TestCase#tearDown()
+   */
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+  
+  public void test1() {
+    ULogger logger = LoggerFactory.getLogger("test1");
+    logger.debug("Hello world.");
+  }
+  
+  public void test2() {
+    ULogger logger = LoggerFactory.getLogger("test2");
+    logger.debug("Hello world 1.");
+    logger.info("Hello world 2.");
+  }
+}

Added: slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java	Fri Apr 22 16:40:13 2005
@@ -0,0 +1,95 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * Copyright (c) 2004-2005 QOS.CH
+ * 
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to  deal in  the Software without  restriction, including
+ * without limitation  the rights to  use, copy, modify,  merge, publish,
+ * distribute, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+ * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.impl;
+
+import org.slf4j.impl.MessageFormatter;
+
+import junit.framework.TestCase;
+
+
+/**
+ * @author Ceki Gulcu
+ *
+ */
+public class MessageFormatterTest extends TestCase {
+  
+  public void test1Param() {
+    String result;
+    Integer i3 = new Integer(3);
+    
+    result = MessageFormatter.format("Value is {}.", i3);
+    assertEquals("Value is 3.", result);
+
+    result = MessageFormatter.format("Value is {", i3);
+    assertEquals("Value is {", result);
+    
+    result = MessageFormatter.format("Value is {}.", null);
+    assertEquals("Value is null.", result);
+
+    result = MessageFormatter.format("{} is larger than 2.", i3);
+    assertEquals("3 is larger than 2.", result);
+
+    result = MessageFormatter.format("No subst", i3);
+    assertEquals("No subst", result);
+    
+    result = MessageFormatter.format("Incorrect {subst", i3);
+    assertEquals("Incorrect {subst", result);
+    
+    result = MessageFormatter.format("Escaped \\{} subst", i3);
+    assertEquals("Escaped \\{} subst", result);
+
+    result = MessageFormatter.format("\\{Escaped", i3);
+    assertEquals("\\{Escaped", result);
+
+    result = MessageFormatter.format("\\{}Escaped", i3);
+    assertEquals("\\{}Escaped", result);
+  }
+  
+  public void test2Param() {
+    String result;
+    Integer i1 = new Integer(1);
+    Integer i2 = new Integer(2);
+    
+    result = MessageFormatter.format("Value {} is larger than {}.", i1, i2);
+    assertEquals("Value 1 is larger than 2.", result);
+    
+    result = MessageFormatter.format("Value {} is larger than {}", i1, i2);
+    assertEquals("Value 1 is larger than 2", result);
+    
+    result = MessageFormatter.format("{}{}", i1, i2);
+    assertEquals("12", result);
+    result = MessageFormatter.format("Val1={}, Val2={", i1, i2);
+    assertEquals("Val1=1, Val2={", result);
+  }
+}



More information about the slf4j-dev mailing list