add a simple unit test harness based on xpcshell; add two tests for PBE and to load all the modules; add some hacks to the component's makefile to make tests work correctly

This commit is contained in:
Dan Mills 2008-04-30 13:01:17 -07:00
Родитель 3184c97820
Коммит e8ea45e9de
5 изменённых файлов: 79 добавлений и 1 удалений

Просмотреть файл

@ -40,7 +40,7 @@ idl = IWeaveCrypto.idl
cpp_sources = WeaveCrypto.cpp WeaveCryptoModule.cpp
target = WeaveCrypto # will have .so / .dylib / .dll appended
sdkdir =
sdkdir ?= ${MOZSDKDIR}
destdir = ..
platformdir = $(destdir)/platform/$(platform)
@ -147,6 +147,8 @@ so_target = $(target:=.$(so))
######################################################################
.PHONY: all build install test-install clean
all: build # default target
build: $(so_target) $(idl_typelib)
@ -157,6 +159,14 @@ install: build
cp $(idl_typelib) $(destdir)/components
cp $(so_target) $(platformdir)/components
# gross hack to get around component registration for xpcshell tests
test-install: install
ln -sf `pwd`/$(destdir)/defaults/preferences/sync.js $(sdkdir)/bin/defaults/pref/sync.js # fixme!!
ln -sf `pwd`/$(destdir)/components/$(idl_typelib) $(sdkdir)/bin/components/$(idl_typelib)
ln -sf `pwd`/$(platformdir)/components/$(so_target) $(sdkdir)/bin/components/$(so_target)
rm -f $(sdkdir)/bin/components/compreg.dat
rm -f $(sdkdir)/bin/components/xpti.dat
clean:
rm -f $(so_target) $(cpp_objects) $(idl_typelib) $(idl_headers)

Просмотреть файл

@ -0,0 +1 @@
../harness/Makefile

Просмотреть файл

@ -0,0 +1,28 @@
version(180);
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
let ds = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
let provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ExtPrefDL") {
return [ds.get("CurProcD", Ci.nsIFile)];
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
ds.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
do_bind_resource(do_get_file("modules"), "weave");

Просмотреть файл

@ -0,0 +1,15 @@
function run_test() {
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://weave/constants.js");
Components.utils.import("resource://weave/log4moz.js");
Components.utils.import("resource://weave/util.js");
Components.utils.import("resource://weave/async.js");
Components.utils.import("resource://weave/crypto.js");
Components.utils.import("resource://weave/identity.js");
Components.utils.import("resource://weave/dav.js");
Components.utils.import("resource://weave/wrap.js");
Components.utils.import("resource://weave/stores.js");
Components.utils.import("resource://weave/syncCores.js");
Components.utils.import("resource://weave/engines.js");
Components.utils.import("resource://weave/service.js");
}

Просмотреть файл

@ -0,0 +1,24 @@
function run_test() {
// initialize nss
let ch = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
let pbe = Cc["@labs.mozilla.com/Weave/Crypto;1"].getService(Ci.IWeaveCrypto);
pbe.algorithm = pbe.DES_EDE3_CBC;
let cipherTxt = pbe.encrypt("passphrase", "my very secret message!");
do_check_true(cipherTxt != "my very secret message!");
let clearTxt = pbe.decrypt("passphrase", cipherTxt);
do_check_true(clearTxt == "my very secret message!");
// The following check with wrong password must cause decryption to fail
// beuase of used padding-schema cipher, RFC 3852 Section 6.3
let failure = false;
try {
pbe.decrypt("wrongpassphrase", cipherTxt);
} catch (e) {
failure = true;
}
do_check_true(failure);
}