Skip to content

Commit

Permalink
Unify necko and content test harnesses. Create common versions of tes…
Browse files Browse the repository at this point in the history
…t harness

files in tools/test-harness/xpcshell-simple, and modify the existing
instances to use the common files.  Bug 322894, r=darin,bzbarsky,
sr=benjamin
  • Loading branch information
davel%mozilla.com committed Jan 27, 2006
1 parent e437fdb commit da85bb1
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 220 deletions.
5 changes: 5 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ tier_99_dirs += \
$(NULL)
endif

# test harnesses
ifdef ENABLE_TESTS
tier_99_dirs += tools/test-harness
endif

default alldep all:: $(SUBMAKEFILES)
$(RM) -rf $(DIST)/sdk
$(RM) -rf $(DIST)/include
Expand Down
1 change: 1 addition & 0 deletions client.mk
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ MODULES_core := \
mozilla/db/sqlite3 \
mozilla/db/morkreader \
mozilla/tools/cross-commit \
mozilla/tools/test-harness \
$(NULL)

LOCALES_core := \
Expand Down
10 changes: 3 additions & 7 deletions content/test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ MODULE = test_content

include $(topsrcdir)/config/rules.mk

_UNIT_FILES = unit/test_all.sh \
unit/head.js \
unit/tail.js \
unit/test_xml_parser.js \
unit/test_xml_serializer.js \
$(NULL)
_UNIT_FILES := $(wildcard $(srcdir)/unit/*.js)

libs:: $(_UNIT_FILES)
$(INSTALL) $^ $(DIST)/bin/content_unit_tests

check::
$(RUN_TEST_PROGRAM) $(DIST)/bin/content_unit_tests/test_all.sh
$(RUN_TEST_PROGRAM) $(DIST)/bin/test_all.sh \
$(DIST)/bin/content_unit_tests
99 changes: 1 addition & 98 deletions content/test/unit/head.js → content/test/unit/head_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
*
* ***** END LICENSE BLOCK ***** */

// This file contains common code that is loaded with each test file.
const I = Components.interfaces;
const C = Components.classes;
const nsIEventQueueService = I.nsIEventQueueService;
const nsIEventQueue = I.nsIEventQueue;

const nsILocalFile = I.nsILocalFile;
const nsIProperties = I.nsIProperties;
const nsIFileInputStream = I.nsIFileInputStream;
Expand All @@ -56,97 +54,6 @@ const nsIDOMCharacterData = I.nsIDOMCharacterData;
const nsIDOMAttr = I.nsIDOMAttr;
const nsIDOMProcessingInstruction = I.nsIDOMProcessingInstruction;

var _eqs;
var _quit = false;
var _fail = false;
var _running_event_loop = false;
var _tests_pending = 0;

function _TimerCallback(expr) {
this._expr = expr;
}
_TimerCallback.prototype = {
_expr: "",
QueryInterface: function(iid) {
if (iid.Equals(Components.interfaces.nsITimerCallback) ||
iid.Equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
notify: function(timer) {
eval(this._expr);
}
};

function do_timeout(delay, expr) {
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.initWithCallback(new _TimerCallback(expr), delay, timer.TYPE_ONE_SHOT);
}

function do_main() {
if (_quit)
return;

dump("*** running event loop\n");
var eq = _eqs.getSpecialEventQueue(_eqs.CURRENT_THREAD_EVENT_QUEUE);

_running_event_loop = true;
eq.eventLoop(); // unblocked via interrupt from do_quit()
_running_event_loop = false;

// process any remaining events before exiting
eq.processPendingEvents();
eq.stopAcceptingEvents();
eq.processPendingEvents();
}

function do_quit() {
dump("*** exiting\n");

_quit = true;

if (_running_event_loop) {
// interrupt the current thread to make eventLoop return.
var thr = Components.classes["@mozilla.org/thread;1"]
.createInstance(Components.interfaces.nsIThread);
thr.currentThread.interrupt();
}
}

function do_throw(text) {
_fail = true;
do_quit();
dump("*** CHECK FAILED: " + text + "\n");
var frame = Components.stack;
while (frame != null) {
dump(frame + "\n");
frame = frame.caller;
}
throw Components.results.NS_ERROR_ABORT;
}

function do_check_neq(_left, _right) {
if (_left == _right)
do_throw(_left + " != " + _right);
}

function do_check_eq(_left, _right) {
if (_left != _right)
do_throw(_left + " == " + _right);
}

function do_test_pending() {
dump("*** test pending\n");
_tests_pending++;
}

function do_test_finished() {
dump("*** test finished\n");
if (--_tests_pending == 0)
do_quit();
}

function DOMParser() {
return C["@mozilla.org/xmlextras/domparser;1"].createInstance(nsIDOMParser);
}
Expand Down Expand Up @@ -257,7 +164,3 @@ function do_check_serialize(dom) {
do_check_equiv(dom, roundtrip(dom));
}

// setup the main thread event queue
_eqs = Components.classes["@mozilla.org/event-queue-service;1"]
.getService(nsIEventQueueService);
_eqs.createMonitoredThreadEventQueue();
14 changes: 3 additions & 11 deletions netwerk/test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,14 @@ DEFINES += $(TK_CFLAGS)

include $(topsrcdir)/config/rules.mk

_UNIT_FILES = unit/test_all.sh \
unit/head.js \
unit/tail.js \
unit/test_protocolproxyservice.js \
unit/test_http_headers.js \
unit/test_cookie_header.js \
unit/test_parse_content_type.js \
unit/test_localstreams.js \
unit/test_file_protocol.js \
$(NULL)
_UNIT_FILES := $(wildcard $(srcdir)/unit/*.js)

libs:: $(_UNIT_FILES)
$(INSTALL) $^ $(DIST)/bin/necko_unit_tests

check::
$(RUN_TEST_PROGRAM) $(DIST)/bin/TestCookie
$(RUN_TEST_PROGRAM) $(DIST)/bin/necko_unit_tests/test_all.sh
$(RUN_TEST_PROGRAM) $(DIST)/bin/test_all.sh $(DIST)/bin/necko_unit_tests

_RES_FILES = urlparse.dat \
urlparse_unx.dat \
Expand Down
52 changes: 0 additions & 52 deletions netwerk/test/unit/tail.js

This file was deleted.

50 changes: 50 additions & 0 deletions tools/test-harness/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# David Liebreich <[email protected]> (Original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

MODULE = test_harness
DIRS = xpcshell-simple

include $(topsrcdir)/config/rules.mk

49 changes: 23 additions & 26 deletions content/test/unit/test_all.sh → .../test-harness/xpcshell-simple/Makefile.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/sh
#
# vim:set ts=2 sw=2 sts=2 et:
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
Expand All @@ -17,16 +14,17 @@
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Google Inc.
# The Initial Developer of the Original Code is
# Mozilla.org.
# Portions created by the Initial Developer are Copyright (C) 2005
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Darin Fisher <[email protected]>
# Boris Zbarsky <[email protected]> (Original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
Expand All @@ -36,27 +34,26 @@
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK ***** */
# ***** END LICENSE BLOCK *****

DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

# allow core dumps
ulimit -c 20480 2> /dev/null
MODULE = test_harness_xpcshell_simple

dir=`dirname $0`
bin="$dir/.."
include $(topsrcdir)/config/rules.mk

exit_status=0
_TEST_FILES = test_all.sh
_UNIT_FILES = head.js \
tail.js \
$(NULL)

for t in $dir/test_*.js
do
echo -n "$t: "
$bin/xpcshell -f $dir/head.js -f $t -f $dir/tail.js 2> $t.log 1>&2
if [ `grep -c '\*\*\* PASS' $t.log` = 0 ]
then
echo "FAIL (see $t.log)"
exit_status=1
else
echo "PASS"
fi
done
libs:: $(_UNIT_FILES)
$(INSTALL) $^ $(DIST)/bin/test-harness/xpcshell-simple

exit $exit_status
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DIST)/bin/
6 changes: 6 additions & 0 deletions tools/test-harness/xpcshell-simple/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Simple xpcshell-based test harness

converted from netwerk/test/unit

current project page at http://wiki.mozilla.org/SoftwareTesting:Tools:Simple_xpcshell_test_harness

Loading

0 comments on commit da85bb1

Please sign in to comment.