[Aceunit-commit] SF.net SVN: aceunit:[559] trunk/src/native
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2011-02-14 01:17:51
|
Revision: 559
http://aceunit.svn.sourceforge.net/aceunit/?rev=559&view=rev
Author: christianhujer
Date: 2011-02-14 01:17:44 +0000 (Mon, 14 Feb 2011)
Log Message:
-----------
Move Loggers to a directory of their own.
Added Paths:
-----------
trunk/src/native/loggers/
trunk/src/native/loggers/FullPlainLogger.c
trunk/src/native/loggers/JUnitXmlLogger.c
trunk/src/native/loggers/MiniRamLogger.c
Removed Paths:
-------------
trunk/src/native/FullPlainLogger.c
trunk/src/native/JUnitXmlLogger.c
trunk/src/native/MiniRamLogger.c
Deleted: trunk/src/native/FullPlainLogger.c
===================================================================
--- trunk/src/native/FullPlainLogger.c 2011-02-14 01:17:19 UTC (rev 558)
+++ trunk/src/native/FullPlainLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -1,69 +0,0 @@
-/* Copyright (c) 2007, Christian Hujer
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the AceUnit developers nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Full Logger implementation that logs plain text messages.
- * The format of the messages is suitable for processing in popular text editors like EMacs or Vim.
- * It is the same as that of error messages yielded by most popular compilers like gcc or javac.
- * The format is:
- * <p><code><var>filename</var>:<var>linenumber</var>: error: in <var>symbolnname</var>: <var>message</var></p>
- * For example:
- * <p><samp>foo.c:30: error: Expected X to be 15 but was 13.</samp></p>
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @file FullPlainLogger.c
- */
-
-#include <stdio.h>
-
-#include "AceUnit.h"
-#include "AceUnitLogging.h"
-
-/** Logs a message using this logger.
- * @param recentError Error to log.
- */
-void FullPlainLoggerLog(const AssertionError_t *const recentError) {
-#ifdef ACEUNIT_EMBEDDED
-#error "FullPlainLogger does not support embedded AceUnit."
-#else
- printf("%d:%d: error: in %d: %s\n", recentError->fixtureId, recentError->assertionId.lineNumber, recentError->testId, recentError->assertionId.message);
-#endif
-}
-
-/** This Logger. */
-AceUnitNewLogger(
- FullPlainLogger,
- NULL,
- NULL,
- NULL,
- NULL,
- FullPlainLoggerLog,
- NULL,
- NULL,
- NULL,
- NULL
-);
-
-TestLogger_t *globalLogger = &FullPlainLogger; /* XXX Hack. Remove. */
Deleted: trunk/src/native/JUnitXmlLogger.c
===================================================================
--- trunk/src/native/JUnitXmlLogger.c 2011-02-14 01:17:19 UTC (rev 558)
+++ trunk/src/native/JUnitXmlLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -1,216 +0,0 @@
-/* Copyright (c) 2007, Christian Hujer
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the AceUnit developers nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** The JUnitXmlLogger is a {@link TestLogger_t} implementation that writes a test log that is compatible with that of JUnit when using XML log format.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @file JUnitXmlLogger.c
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "AceUnit.h"
-#include "AceUnitLogging.h"
-
-/** Returns the host name of the host this test is executed on.
- * @return Host name
- */
-static char *getHostname() {
- char *hostname;
- hostname = getenv("HOSTNAME");
- if (NULL == hostname) {
- hostname = getenv("COMPUTERNAME");
- }
- if (NULL == hostname) {
- hostname = "unknown";
- }
- return hostname;
-}
-
-/** The name of the global file.
- * Do not change this without really thinking about: It is intentionally the same as that of JUnit / the JUnit Ant task.
- */
-#define GLOBAL_FILE_NAME "TESTS-TestSuites.xml"
-
-/** The file TESTS-TestSuites.xml which contains the accumulated log information of all test suites. */
-static FILE *globalFile = NULL;
-
-/** The global information recorded by this logger. */
-static struct {
- char *hostname;
- int suiteId;
-} globalInfo = {
- 0
-};
-
-/** The information about the current suite. */
-static struct {
- int errors;
- int failures;
- int id;
- char *name;
- char *package;
- char *fullname;
- int tests;
- float time;
- char *timestamp;
-} suiteInfo = {
- 0,
-};
-
-/** Initializes all global variables and prepares global log file output.
- * @see TestLogger_t#runnerStarted()}
- */
-static void runnerStarted() {
- globalFile = fopen(GLOBAL_FILE_NAME, "w");
- fprintf(globalFile, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- fprintf(globalFile, "<testsuites>\n");
- fflush(globalFile);
- globalInfo.hostname = getHostname();
- globalInfo.suiteId = 0;
-}
-
-/** Initializes suite-specific variables.
- * @see TestLogger_t#suiteStarted()}
- */
-static void suiteStarted(SuiteId_t const suiteId) {
- suiteInfo.errors = 0;
- suiteInfo.failures = 0;
- suiteInfo.id = globalInfo.suiteId++;
-}
-
-/** Initializes fixture-specific variables.
- * @see TestLogger_t#fixtureStarted()}
- */
-static void fixtureStarted(const FixtureId_t fixture) {
- suiteInfo.package = NULL; /* TODO */
- suiteInfo.name = NULL; /* TODO */
- suiteInfo.tests = 0; /* TODO */
- suiteInfo.timestamp = NULL; /* TODO */
-}
-
-/** @see TestLogger_t#testCaseStarted()} */
-static void testCaseStarted(TestCaseId_t testCase) {
-}
-
-/** @see TestLogger_t#testCaseFailed()} */
-static void testCaseFailed(const AssertionError_t *assertion) {
-}
-
-/** @see TestLogger_t#testCaseEnded()} */
-static void testCaseEnded(TestCaseId_t testCase) {
-}
-
-/** @see TestLogger_t#fixtureEnded()} */
-static void fixtureEnded(FixtureId_t fixture) {
-}
-
-/** Prints the environment as properties XML element to the specified file.
- * @param file File to print to
- */
-static void printEnvAsProperties(FILE *file) {
-#ifdef ACEUNIT_JUNITXMLLOGGER_ENVIRONMENT
- extern char **environ;
- char **env = environ;
- size_t i;
- if (NULL == *env) {
-#endif
- fprintf(globalFile, " <properties/>\n");
-#ifdef ACEUNIT_JUNITXMLLOGGER_ENVIRONMENT
- } else {
- fprintf(globalFile, " <properties>\n");
- for (; NULL != *env; env++) {
- char *ptr = *env;
- fprintf(globalFile, " <property name=\"");
- for (i = 0; i < strlen(ptr); i++) {
- if ('=' == ptr[i]) {
- break;
- }
- }
- fwrite(*ptr, sizeof(char), i, globalFile);
- ptr += i + 1;
- fprintf(globalFile, "\" value=\"");
- fwrite(*ptr, sizeof(char), strlen(ptr), globalFile);
- fprintf(globalFile, "\" />\n");
- }
- fprintf(globalFile, " </properties>\n");
- }
-#endif
-}
-
-/** @see TestLogger_t#suiteEnded()} */
-static void suiteEnded(SuiteId_t const suiteId) {
- int i;
- FILE *localFile;
- /* <testsuite errors="0" failures="0" hostname="riedquat" id="1" name="BasicCommandTest" package="test.net.sf.japi.io.args" tests="10" time="0.105" timestamp="2007-11-06T20:15:24"> */
- fprintf(globalFile, " <testsuite errors=\"%d\" failures=\"%d\" hostname=\"%s\" id=\"%d\" name=\"%s\" package=\"%s\" tests=\"%d\" time=\"%f\" timestamp=\"%s\">\n", 0/*TODO*/, 0/*TODO*/, globalInfo.hostname, 0/*TODO*/, ""/*TODO*/, ""/*TODO*/, 0/*TODO*/, 0.0/*TODO*/, ""/*TODO*/);
- printEnvAsProperties(globalFile);
- for (i = 0; i < suiteInfo.tests; i++) {
- /*<testcase classname="test.net.sf.japi.io.args.BasicCommandTest" name="testHelp" time="0.0090" />*/
- fprintf(globalFile, " <testcase classname=\"%s\" name=\"%s\" time=\"%f\" />\n", ""/*TODO*/, ""/*TODO*/, 0.0/*TODO*/);
- }
- fprintf(globalFile, " <system-out/>\n");
- fprintf(globalFile, " <system-err/>\n");
- fprintf(globalFile, " </testsuite>\n");
- fflush(globalFile);
-
- localFile = fopen("TEST-test.net.sf.japi.io.args.ArgParserTest.xml", "w"); /* TODO: configure filename */
- /* <testsuite errors="0" failures="0" hostname="riedquat" name="test.net.sf.japi.io.args.ArgParserTest" tests="19" time="3.463" timestamp="2007-11-06T20:15:21"> */
- fprintf(localFile, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- fprintf(localFile, "<testsuite errors=\"%d\" failures=\"%d\" hostname=\"%s\" name=\"%s\" tests=\"%d\" time=\"%f\" timestamp=\"%s\">\n", 0/*TODO*/, 0/*TODO*/, globalInfo.hostname, ""/*TODO*/, 0/*TODO*/, 0.0/*TODO*/, ""/*TODO*/);
- fprintf(localFile, " <properties/>\n"); /* TODO: encode environment as properties? */
- for (i = 0; i < suiteInfo.tests; i++) {
- /* <testcase classname="test.net.sf.japi.io.args.ArgParserTest" name="testSimpleParseAndRun" time="0.0080" /> */
- fprintf(localFile, " <testcase classname=\"%s\" name=\"%s\" time=\"%f\" />\n", ""/*TODO*/, ""/*TODO*/, 0.0/*TODO*/);
- }
- fprintf(localFile, " <system-out/>\n");
- fprintf(localFile, " <system-err/>\n");
- fprintf(localFile, "</testsuite>\n");
- fclose(localFile);
-}
-
-/** @see TestLogger_t#runnerEnded()} */
-static void runnerEnded() {
- fprintf(globalFile, "</testsuites>\n");
- fclose(globalFile);
-}
-
-/** This Logger. */
-AceUnitNewLogger(
- JUnitXmlLogger,
- runnerStarted,
- suiteStarted,
- fixtureStarted,
- testCaseStarted,
- testCaseFailed,
- testCaseEnded,
- fixtureEnded,
- suiteEnded,
- runnerEnded
-);
-
-TestLogger_t *globalLogger = &JUnitXmlLogger; /* XXX Hack. Remove. */
Deleted: trunk/src/native/MiniRamLogger.c
===================================================================
--- trunk/src/native/MiniRamLogger.c 2011-02-14 01:17:19 UTC (rev 558)
+++ trunk/src/native/MiniRamLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -1,99 +0,0 @@
-/* Copyright (c) 2007, Christian Hujer
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the AceUnit developers nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Mini Ram Logger implementation that logs messages to RAM with as little memory consumption as possible.
- * The format of the messages is suitable for postprocessing to convert it into the same format as that of {@link FullPlainLogger.c}.
- * This Logger also could serve as a template if you want to create your own logger that e.g. logs by writing to a NVM like EEPROM or Flash.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @file MiniRamLogger.c
- */
-
-#include "AceUnit.h"
-#include "AceUnitLogging.h"
-#ifndef ACEUNIT_EMBEDDED
-#error "MiniRamLogger can only be used for ACEUNIT_EMBEDDED."
-#endif
-
-#ifdef ACEUNIT_MINIRAMLOGGER_SAVE
-#include <stdio.h>
-#endif
-#include <string.h>
-
-#ifndef ACEUNIT_MINIRAM_LOGGER_BUFSIZE
-/** The size of the buffer that's used for the Mini Ram Logger. */
-#define ACEUNIT_MINIRAM_LOGGER_BUFSIZE 32
-#endif
-
-/** The number of valid logging elements in #data. */
-size_t elementCount;
-
-/** AceUnit Mini Ram Logger data buffer. */
-AssertionError_t data[ACEUNIT_MINIRAM_LOGGER_BUFSIZE];
-
-/** Initializes the Mini Ram Logger. */
-void MiniRamLoggerInit() {
- elementCount = 0;
- memset(data, 0, sizeof(data));
-}
-
-/** Logs a message using this logger.
- * @param recentError Error to log.
- */
-void MiniRamLoggerLog(const AssertionError_t *const recentError) {
- data[elementCount++] = *recentError;
-}
-
-#ifdef ACEUNIT_MINIRAMLOGGER_SAVE
-/** Writes contents of the Mini Ram Logger to a file.
- * @param file File to write to.
- */
-void MiniRamLoggerSave(FILE *file) {
- /* The file will first contain a BOM (byte order mark).
- * That enables tools that read this file to find out whether it was written in Big Endian or Little Endian.
- */
- uint16_t bom = 0xFFFE;
- fwrite(&bom, sizeof(uint16_t), 1, file);
-
- /* Now write the data. */
- fwrite(data, sizeof(AssertionError_t), elementCount, file);
-}
-#endif
-
-/** This Logger. */
-AceUnitNewLogger(MiniRamLogger,
- NULL,
- NULL,
- NULL,
- NULL,
- MiniRamLoggerLog,
- NULL,
- NULL,
- NULL,
- NULL
-);
-
-TestLogger_t *globalLogger = &MiniRamLogger; /* XXX Hack. Remove. */
Copied: trunk/src/native/loggers/FullPlainLogger.c (from rev 556, trunk/src/native/FullPlainLogger.c)
===================================================================
--- trunk/src/native/loggers/FullPlainLogger.c (rev 0)
+++ trunk/src/native/loggers/FullPlainLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -0,0 +1,69 @@
+/* Copyright (c) 2007, Christian Hujer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the AceUnit developers nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** Full Logger implementation that logs plain text messages.
+ * The format of the messages is suitable for processing in popular text editors like EMacs or Vim.
+ * It is the same as that of error messages yielded by most popular compilers like gcc or javac.
+ * The format is:
+ * <p><code><var>filename</var>:<var>linenumber</var>: error: in <var>symbolnname</var>: <var>message</var></p>
+ * For example:
+ * <p><samp>foo.c:30: error: Expected X to be 15 but was 13.</samp></p>
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @file FullPlainLogger.c
+ */
+
+#include <stdio.h>
+
+#include "AceUnit.h"
+#include "AceUnitLogging.h"
+
+/** Logs a message using this logger.
+ * @param recentError Error to log.
+ */
+void FullPlainLoggerLog(const AssertionError_t *const recentError) {
+#ifdef ACEUNIT_EMBEDDED
+#error "FullPlainLogger does not support embedded AceUnit."
+#else
+ printf("%d:%d: error: in %d: %s\n", recentError->fixtureId, recentError->assertionId.lineNumber, recentError->testId, recentError->assertionId.message);
+#endif
+}
+
+/** This Logger. */
+AceUnitNewLogger(
+ FullPlainLogger,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ FullPlainLoggerLog,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+);
+
+TestLogger_t *globalLogger = &FullPlainLogger; /* XXX Hack. Remove. */
Copied: trunk/src/native/loggers/JUnitXmlLogger.c (from rev 556, trunk/src/native/JUnitXmlLogger.c)
===================================================================
--- trunk/src/native/loggers/JUnitXmlLogger.c (rev 0)
+++ trunk/src/native/loggers/JUnitXmlLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -0,0 +1,216 @@
+/* Copyright (c) 2007, Christian Hujer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the AceUnit developers nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** The JUnitXmlLogger is a {@link TestLogger_t} implementation that writes a test log that is compatible with that of JUnit when using XML log format.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @file JUnitXmlLogger.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "AceUnit.h"
+#include "AceUnitLogging.h"
+
+/** Returns the host name of the host this test is executed on.
+ * @return Host name
+ */
+static char *getHostname() {
+ char *hostname;
+ hostname = getenv("HOSTNAME");
+ if (NULL == hostname) {
+ hostname = getenv("COMPUTERNAME");
+ }
+ if (NULL == hostname) {
+ hostname = "unknown";
+ }
+ return hostname;
+}
+
+/** The name of the global file.
+ * Do not change this without really thinking about: It is intentionally the same as that of JUnit / the JUnit Ant task.
+ */
+#define GLOBAL_FILE_NAME "TESTS-TestSuites.xml"
+
+/** The file TESTS-TestSuites.xml which contains the accumulated log information of all test suites. */
+static FILE *globalFile = NULL;
+
+/** The global information recorded by this logger. */
+static struct {
+ char *hostname;
+ int suiteId;
+} globalInfo = {
+ 0
+};
+
+/** The information about the current suite. */
+static struct {
+ int errors;
+ int failures;
+ int id;
+ char *name;
+ char *package;
+ char *fullname;
+ int tests;
+ float time;
+ char *timestamp;
+} suiteInfo = {
+ 0,
+};
+
+/** Initializes all global variables and prepares global log file output.
+ * @see TestLogger_t#runnerStarted()}
+ */
+static void runnerStarted() {
+ globalFile = fopen(GLOBAL_FILE_NAME, "w");
+ fprintf(globalFile, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+ fprintf(globalFile, "<testsuites>\n");
+ fflush(globalFile);
+ globalInfo.hostname = getHostname();
+ globalInfo.suiteId = 0;
+}
+
+/** Initializes suite-specific variables.
+ * @see TestLogger_t#suiteStarted()}
+ */
+static void suiteStarted(SuiteId_t const suiteId) {
+ suiteInfo.errors = 0;
+ suiteInfo.failures = 0;
+ suiteInfo.id = globalInfo.suiteId++;
+}
+
+/** Initializes fixture-specific variables.
+ * @see TestLogger_t#fixtureStarted()}
+ */
+static void fixtureStarted(const FixtureId_t fixture) {
+ suiteInfo.package = NULL; /* TODO */
+ suiteInfo.name = NULL; /* TODO */
+ suiteInfo.tests = 0; /* TODO */
+ suiteInfo.timestamp = NULL; /* TODO */
+}
+
+/** @see TestLogger_t#testCaseStarted()} */
+static void testCaseStarted(TestCaseId_t testCase) {
+}
+
+/** @see TestLogger_t#testCaseFailed()} */
+static void testCaseFailed(const AssertionError_t *assertion) {
+}
+
+/** @see TestLogger_t#testCaseEnded()} */
+static void testCaseEnded(TestCaseId_t testCase) {
+}
+
+/** @see TestLogger_t#fixtureEnded()} */
+static void fixtureEnded(FixtureId_t fixture) {
+}
+
+/** Prints the environment as properties XML element to the specified file.
+ * @param file File to print to
+ */
+static void printEnvAsProperties(FILE *file) {
+#ifdef ACEUNIT_JUNITXMLLOGGER_ENVIRONMENT
+ extern char **environ;
+ char **env = environ;
+ size_t i;
+ if (NULL == *env) {
+#endif
+ fprintf(globalFile, " <properties/>\n");
+#ifdef ACEUNIT_JUNITXMLLOGGER_ENVIRONMENT
+ } else {
+ fprintf(globalFile, " <properties>\n");
+ for (; NULL != *env; env++) {
+ char *ptr = *env;
+ fprintf(globalFile, " <property name=\"");
+ for (i = 0; i < strlen(ptr); i++) {
+ if ('=' == ptr[i]) {
+ break;
+ }
+ }
+ fwrite(*ptr, sizeof(char), i, globalFile);
+ ptr += i + 1;
+ fprintf(globalFile, "\" value=\"");
+ fwrite(*ptr, sizeof(char), strlen(ptr), globalFile);
+ fprintf(globalFile, "\" />\n");
+ }
+ fprintf(globalFile, " </properties>\n");
+ }
+#endif
+}
+
+/** @see TestLogger_t#suiteEnded()} */
+static void suiteEnded(SuiteId_t const suiteId) {
+ int i;
+ FILE *localFile;
+ /* <testsuite errors="0" failures="0" hostname="riedquat" id="1" name="BasicCommandTest" package="test.net.sf.japi.io.args" tests="10" time="0.105" timestamp="2007-11-06T20:15:24"> */
+ fprintf(globalFile, " <testsuite errors=\"%d\" failures=\"%d\" hostname=\"%s\" id=\"%d\" name=\"%s\" package=\"%s\" tests=\"%d\" time=\"%f\" timestamp=\"%s\">\n", 0/*TODO*/, 0/*TODO*/, globalInfo.hostname, 0/*TODO*/, ""/*TODO*/, ""/*TODO*/, 0/*TODO*/, 0.0/*TODO*/, ""/*TODO*/);
+ printEnvAsProperties(globalFile);
+ for (i = 0; i < suiteInfo.tests; i++) {
+ /*<testcase classname="test.net.sf.japi.io.args.BasicCommandTest" name="testHelp" time="0.0090" />*/
+ fprintf(globalFile, " <testcase classname=\"%s\" name=\"%s\" time=\"%f\" />\n", ""/*TODO*/, ""/*TODO*/, 0.0/*TODO*/);
+ }
+ fprintf(globalFile, " <system-out/>\n");
+ fprintf(globalFile, " <system-err/>\n");
+ fprintf(globalFile, " </testsuite>\n");
+ fflush(globalFile);
+
+ localFile = fopen("TEST-test.net.sf.japi.io.args.ArgParserTest.xml", "w"); /* TODO: configure filename */
+ /* <testsuite errors="0" failures="0" hostname="riedquat" name="test.net.sf.japi.io.args.ArgParserTest" tests="19" time="3.463" timestamp="2007-11-06T20:15:21"> */
+ fprintf(localFile, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+ fprintf(localFile, "<testsuite errors=\"%d\" failures=\"%d\" hostname=\"%s\" name=\"%s\" tests=\"%d\" time=\"%f\" timestamp=\"%s\">\n", 0/*TODO*/, 0/*TODO*/, globalInfo.hostname, ""/*TODO*/, 0/*TODO*/, 0.0/*TODO*/, ""/*TODO*/);
+ fprintf(localFile, " <properties/>\n"); /* TODO: encode environment as properties? */
+ for (i = 0; i < suiteInfo.tests; i++) {
+ /* <testcase classname="test.net.sf.japi.io.args.ArgParserTest" name="testSimpleParseAndRun" time="0.0080" /> */
+ fprintf(localFile, " <testcase classname=\"%s\" name=\"%s\" time=\"%f\" />\n", ""/*TODO*/, ""/*TODO*/, 0.0/*TODO*/);
+ }
+ fprintf(localFile, " <system-out/>\n");
+ fprintf(localFile, " <system-err/>\n");
+ fprintf(localFile, "</testsuite>\n");
+ fclose(localFile);
+}
+
+/** @see TestLogger_t#runnerEnded()} */
+static void runnerEnded() {
+ fprintf(globalFile, "</testsuites>\n");
+ fclose(globalFile);
+}
+
+/** This Logger. */
+AceUnitNewLogger(
+ JUnitXmlLogger,
+ runnerStarted,
+ suiteStarted,
+ fixtureStarted,
+ testCaseStarted,
+ testCaseFailed,
+ testCaseEnded,
+ fixtureEnded,
+ suiteEnded,
+ runnerEnded
+);
+
+TestLogger_t *globalLogger = &JUnitXmlLogger; /* XXX Hack. Remove. */
Copied: trunk/src/native/loggers/MiniRamLogger.c (from rev 556, trunk/src/native/MiniRamLogger.c)
===================================================================
--- trunk/src/native/loggers/MiniRamLogger.c (rev 0)
+++ trunk/src/native/loggers/MiniRamLogger.c 2011-02-14 01:17:44 UTC (rev 559)
@@ -0,0 +1,99 @@
+/* Copyright (c) 2007, Christian Hujer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the AceUnit developers nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** Mini Ram Logger implementation that logs messages to RAM with as little memory consumption as possible.
+ * The format of the messages is suitable for postprocessing to convert it into the same format as that of {@link FullPlainLogger.c}.
+ * This Logger also could serve as a template if you want to create your own logger that e.g. logs by writing to a NVM like EEPROM or Flash.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @file MiniRamLogger.c
+ */
+
+#include "AceUnit.h"
+#include "AceUnitLogging.h"
+#ifndef ACEUNIT_EMBEDDED
+#error "MiniRamLogger can only be used for ACEUNIT_EMBEDDED."
+#endif
+
+#ifdef ACEUNIT_MINIRAMLOGGER_SAVE
+#include <stdio.h>
+#endif
+#include <string.h>
+
+#ifndef ACEUNIT_MINIRAM_LOGGER_BUFSIZE
+/** The size of the buffer that's used for the Mini Ram Logger. */
+#define ACEUNIT_MINIRAM_LOGGER_BUFSIZE 32
+#endif
+
+/** The number of valid logging elements in #data. */
+size_t elementCount;
+
+/** AceUnit Mini Ram Logger data buffer. */
+AssertionError_t data[ACEUNIT_MINIRAM_LOGGER_BUFSIZE];
+
+/** Initializes the Mini Ram Logger. */
+void MiniRamLoggerInit() {
+ elementCount = 0;
+ memset(data, 0, sizeof(data));
+}
+
+/** Logs a message using this logger.
+ * @param recentError Error to log.
+ */
+void MiniRamLoggerLog(const AssertionError_t *const recentError) {
+ data[elementCount++] = *recentError;
+}
+
+#ifdef ACEUNIT_MINIRAMLOGGER_SAVE
+/** Writes contents of the Mini Ram Logger to a file.
+ * @param file File to write to.
+ */
+void MiniRamLoggerSave(FILE *file) {
+ /* The file will first contain a BOM (byte order mark).
+ * That enables tools that read this file to find out whether it was written in Big Endian or Little Endian.
+ */
+ uint16_t bom = 0xFFFE;
+ fwrite(&bom, sizeof(uint16_t), 1, file);
+
+ /* Now write the data. */
+ fwrite(data, sizeof(AssertionError_t), elementCount, file);
+}
+#endif
+
+/** This Logger. */
+AceUnitNewLogger(MiniRamLogger,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ MiniRamLoggerLog,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+);
+
+TestLogger_t *globalLogger = &MiniRamLogger; /* XXX Hack. Remove. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|