001: /*
002: * @(#)LogTPLog.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Part of the GroboUtils package at:
009: * http://groboutils.sourceforge.net
010: *
011: * Permission is hereby granted, free of charge, to any person obtaining a
012: * copy of this software and associated documentation files (the "Software"),
013: * to deal in the Software without restriction, including without limitation
014: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
015: * and/or sell copies of the Software, and to permit persons to whom the
016: * Software is furnished to do so, subject to the following conditions:
017: *
018: * The above copyright notice and this permission notice shall be included in
019: * all copies or substantial portions of the Software.
020: *
021: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
022: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
024: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
025: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
026: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
027: * DEALINGS IN THE SOFTWARE.
028: */
029: package net.sourceforge.groboutils.tp.v1.log;
030:
031: import net.sourceforge.groboutils.autodoc.v1.AutoDocTP;
032:
033: import java.io.PrintWriter;
034: import java.io.File;
035: import java.io.FileWriter;
036: import java.io.IOException;
037:
038: /**
039: * Test Procedure entry point. Generates Test Procedure documentation.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2003/02/10 22:52:29 $
043: * @since July 21, 2002
044: */
045: public class LogTP implements AutoDocTP {
046: private PrintWriter out;
047:
048: private int overalCount = 0;
049: private int stepCount = 0;
050: private int setupCount = 0;
051: private int teardownCount = 0;
052:
053: public LogTP(String baseDir, Class owner) {
054: PrintWriter pw = null;
055: if (baseDir != null && owner != null) {
056: try {
057: pw = new PrintWriter(new FileWriter(new File(baseDir,
058: "TP-" + owner.getName() + ".log")));
059: } catch (IOException ioe) {
060: pw = null;
061: }
062: }
063: if (pw == null) {
064: pw = new PrintWriter(System.out);
065: }
066: setOutput(pw);
067: }
068:
069: /**
070: * Defines a step which occurs during the test setup phase.
071: *
072: * @param description the text describing the step.
073: */
074: public synchronized void setupStep(String description) {
075: printStep("setup", description, ++this .setupCount);
076: }
077:
078: /**
079: * Defines a step which occurs during the test tear-down phase.
080: *
081: * @param description the text describing the step.
082: */
083: public synchronized void teardownStep(String description) {
084: printStep("teardown", description, ++this .teardownCount);
085: }
086:
087: /**
088: * Defines a step which occurs during the test proper.
089: *
090: * @param description the text describing the step.
091: */
092: public synchronized void step(String description) {
093: printStep("test step", description, ++this .stepCount);
094: }
095:
096: protected synchronized void printStep(String stepDesc, String text,
097: int this StepCount) {
098: ++this .overalCount;
099: this .out.println(this .overalCount + ". " + stepDesc + ": "
100: + this StepCount + ". " + text);
101: }
102:
103: protected void setOutput(PrintWriter pw) {
104: this.out = pw;
105: }
106: }
|