chg: replaced ant with gradle
This commit is contained in:
parent
cee0be52e0
commit
5cbeb9f01d
609 changed files with 87626 additions and 638 deletions
1
modules/jala/tests/1meg.reference-win.torrent
Normal file
1
modules/jala/tests/1meg.reference-win.torrent
Normal file
|
@ -0,0 +1 @@
|
|||
d8:announce30:http://tracker.orf.at/announce13:creation datei1172497604e4:infod6:lengthi1048576e4:name4:1meg12:piece lengthi262144e6:pieces80:. §èWYÇôÂTÔÙÃ>ô<>äY§. §èWYÇôÂTÔÙÃ>ô<>äY§. §èWYÇôÂTÔÙÃ>ô<>äY§. §èWYÇôÂTÔÙÃ>ô<>äY§ee
|
BIN
modules/jala/tests/1meg.reference.torrent
Normal file
BIN
modules/jala/tests/1meg.reference.torrent
Normal file
Binary file not shown.
65
modules/jala/tests/AsyncRequest.js
Normal file
65
modules/jala/tests/AsyncRequest.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
|
||||
var result = undefined;
|
||||
|
||||
/**
|
||||
* A simple test of jala.AsyncRequest. It constructs a new AsyncRequest
|
||||
* with a test function defined below that sets various properties
|
||||
* of the global result object above. After evaluating the async request
|
||||
* the current thread sleeps for a short period of time to wait for
|
||||
* the other request to finish, and then does the testing of the result.
|
||||
*/
|
||||
var testAsyncRequest = function() {
|
||||
var r = new jala.AsyncRequest(global, "testFunction");
|
||||
r.run("jala");
|
||||
// wait until the async request started above has finished
|
||||
// before testing the result, but no longer than 1 second.
|
||||
var elapsed = 0;
|
||||
var interval = 5;
|
||||
while (result === undefined && elapsed < 1000) {
|
||||
elapsed += interval;
|
||||
java.lang.Thread.sleep(interval);
|
||||
}
|
||||
assertNotUndefined(result);
|
||||
assertEqual(result.name, "jala");
|
||||
assertEqual(result.request, req);
|
||||
assertEqual(result.response, res);
|
||||
assertFalse(r.isAlive());
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple test function that assigns an object to the global
|
||||
* property "result".
|
||||
* @param {String} name A string to use as name
|
||||
*/
|
||||
var testFunction = function(name) {
|
||||
result = {
|
||||
name: name,
|
||||
request: req,
|
||||
response: res
|
||||
};
|
||||
return;
|
||||
};
|
59
modules/jala/tests/BitTorrent.js
Normal file
59
modules/jala/tests/BitTorrent.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* A simple test of jala.BitTorrent.
|
||||
* FIXME: Needs resolution of issue #33
|
||||
*/
|
||||
var testBitTorrent = function() {
|
||||
var size = 1024 * 1024; // 1 meg
|
||||
var file = new java.io.File(jala.Test.getTestFile("1meg"));
|
||||
var fos = new java.io.FileOutputStream(file, false);
|
||||
var channel = fos.getChannel();
|
||||
var iterations = 0;
|
||||
while (channel.size() < size) {
|
||||
channel.write(java.nio.ByteBuffer.allocate(1024));
|
||||
}
|
||||
channel.close();
|
||||
fos.close();
|
||||
|
||||
var torrent = new jala.BitTorrent(file);
|
||||
// Testing against file generated with BitTorrent.app (OS X)
|
||||
torrent.set("announce", "http://tracker.orf.at/announce");
|
||||
// S3 defines a multitracker list with a single tracker item
|
||||
//torrent.set("announce-list", [["http://tracker.amazonaws.com:6969/announce"]]);
|
||||
torrent.setCreationDate(new Date(2007, 1, 26, 14, 46, 44));
|
||||
torrent.save();
|
||||
file["delete"]();
|
||||
|
||||
try {
|
||||
var torrentFile = torrent.getTorrentFile();
|
||||
var refFile = new helma.File(jala.Test.getTestFile("1meg.reference.torrent"));
|
||||
assertEqual(torrentFile.readAll().trim(), refFile.readAll().trim());
|
||||
} catch (x) {
|
||||
throw(x);
|
||||
} finally {
|
||||
torrentFile.remove();
|
||||
}
|
||||
return;
|
||||
};
|
163
modules/jala/tests/Database.js
Normal file
163
modules/jala/tests/Database.js
Normal file
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* Contains the system's temporary directory
|
||||
* @type helma.File
|
||||
* @private
|
||||
*/
|
||||
var tmpDir = new helma.File(java.lang.System.getProperty("java.io.tmpdir"));
|
||||
|
||||
/**
|
||||
* Contains the server created in testServer method
|
||||
* @private
|
||||
*/
|
||||
var server = null;
|
||||
|
||||
/**
|
||||
* Basic tests for jala.db.RamDatabase. All of these tests are
|
||||
* valid for jala.db.FileDatabase too.
|
||||
*/
|
||||
var testRamDatabase = function() {
|
||||
var db = new jala.db.RamDatabase("test");
|
||||
assertNotNull(db);
|
||||
assertEqual(db.getName(), "test");
|
||||
assertEqual(db.getDatabasePath(), "mem:test");
|
||||
assertEqual(db.getUrl(), "jdbc:h2:mem:test");
|
||||
// test connection to database
|
||||
var conn = db.getConnection();
|
||||
assertNotNull(conn);
|
||||
assertTrue(conn instanceof helma.Database);
|
||||
|
||||
// create a table
|
||||
db.createTable("test", [
|
||||
{
|
||||
name: "id",
|
||||
type: java.sql.Types.INTEGER,
|
||||
nullable: false,
|
||||
unique: true
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
type: java.sql.Types.VARCHAR,
|
||||
length: 255
|
||||
}
|
||||
], "id");
|
||||
|
||||
// test if the table exists
|
||||
assertTrue(db.tableExists("test"));
|
||||
|
||||
// dump database
|
||||
var dumpFile = new helma.File(tmpDir, "backup.test.sql");
|
||||
assertTrue(db.dump(dumpFile));
|
||||
assertTrue(dumpFile.exists());
|
||||
assertTrue(dumpFile.getLength() > 0);
|
||||
// remove dump file again
|
||||
dumpFile.remove();
|
||||
|
||||
// drop table
|
||||
db.dropTable("test");
|
||||
assertFalse(db.tableExists("test"));
|
||||
|
||||
// test db shutdown
|
||||
db.shutdown();
|
||||
assertThrows(function() {
|
||||
conn.query("select 1 = 1");
|
||||
}, Packages.org.h2.jdbc.JdbcSQLException);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Basic tests for jala.db.FileDatabase that are different to
|
||||
* jala.db.RamDatabase
|
||||
*/
|
||||
var testFileDatabase = function() {
|
||||
var db = new jala.db.FileDatabase("test", tmpDir);
|
||||
assertNotNull(db);
|
||||
assertEqual(db.getName(), "test");
|
||||
assertEqual(db.getDirectory(), tmpDir);
|
||||
|
||||
var dbDir = new helma.File(tmpDir, "test");
|
||||
assertEqual(db.getDatabasePath(), "file:" + dbDir.getAbsolutePath());
|
||||
assertEqual(db.getUrl(), "jdbc:h2:file:" + dbDir.getAbsolutePath());
|
||||
|
||||
// execute sql script (need to do that, otherwise the backup won't
|
||||
// work because the database is empty)
|
||||
var sqlFile = jala.Test.getTestFile("Database.script.sql");
|
||||
assertTrue(db.runScript(sqlFile));
|
||||
assertTrue(db.tableExists("test"));
|
||||
|
||||
// test backup
|
||||
var backupFile = new helma.File(tmpDir, "backup.zip");
|
||||
assertTrue(db.backup(backupFile));
|
||||
assertTrue(backupFile.exists());
|
||||
assertTrue(backupFile.getLength() > 0);
|
||||
|
||||
// remove the database
|
||||
db.remove();
|
||||
assertFalse((new helma.File(db.getDirectory(), db.getName() + ".data.db")).exists());
|
||||
assertFalse((new helma.File(db.getDirectory(), db.getName() + ".index.db")).exists());
|
||||
assertFalse((new helma.File(db.getDirectory(), db.getName() + ".trace.db")).exists());
|
||||
|
||||
// test restore
|
||||
assertTrue(db.restore(backupFile));
|
||||
assertTrue(db.tableExists("test"));
|
||||
|
||||
// remove backup file and database
|
||||
backupFile.remove();
|
||||
db.remove();
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
var testServer = function() {
|
||||
server = new jala.db.Server(tmpDir);
|
||||
// test default config
|
||||
assertEqual(tmpDir, server.getDirectory());
|
||||
assertEqual(server.getPort(), 9092);
|
||||
assertFalse(server.useSsl());
|
||||
assertFalse(server.isPublic());
|
||||
assertFalse(server.createOnDemand());
|
||||
|
||||
// test setting config properties
|
||||
server.useSsl(true);
|
||||
assertTrue(server.useSsl());
|
||||
server.isPublic(true);
|
||||
assertTrue(server.isPublic());
|
||||
server.createOnDemand(true);
|
||||
assertTrue(server.createOnDemand());
|
||||
|
||||
// reset back some of them
|
||||
server.useSsl(false);
|
||||
assertFalse(server.useSsl());
|
||||
server.isPublic(false);
|
||||
assertFalse(server.isPublic());
|
||||
|
||||
// start the server
|
||||
assertTrue(server.start());
|
||||
|
||||
// test connection properties (this also includes testing
|
||||
// of server.getUrl())
|
||||
var props = server.getProperties("test", "test", "1111");
|
||||
assertEqual(props.getProperty("test.url"), "jdbc:h2:tcp://localhost:9092/test");
|
||||
assertEqual(props.getProperty("test.driver"), "org.h2.Driver");
|
||||
assertEqual(props.getProperty("test.user"), "test");
|
||||
assertEqual(props.getProperty("test.password"), "1111");
|
||||
|
||||
var conn = server.getConnection("test", "test", "1111");
|
||||
assertNotNull(conn);
|
||||
|
||||
// stop the server
|
||||
assertTrue(server.stop());
|
||||
// and remove the file database created above
|
||||
var db = new jala.db.FileDatabase("test", tmpDir, "test", "1111");
|
||||
db.remove();
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stuff to do on cleanup
|
||||
*/
|
||||
var cleanup = function() {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
return;
|
||||
};
|
4
modules/jala/tests/Database.script.sql
Normal file
4
modules/jala/tests/Database.script.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(255), PRIMARY KEY (id));
|
||||
INSERT INTO test (id, name) VALUES (1, 'jala');
|
||||
INSERT INTO test (id, name) VALUES (2, 'Database');
|
||||
INSERT INTO test (id, name) VALUES (3, 'Test');
|
66
modules/jala/tests/DnsClient.js
Normal file
66
modules/jala/tests/DnsClient.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
|
||||
var dnsClient = new jala.DnsClient("68.12.16.25");
|
||||
var result;
|
||||
|
||||
/**
|
||||
* Testing default mode (A records)
|
||||
*/
|
||||
var testAQuery = function() {
|
||||
result = dnsClient.query("nomatic.org");
|
||||
assertEqual(result.length, 1);
|
||||
assertEqual(result[0].ipAddress, "213.129.249.34");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Testing SOA record queries
|
||||
*/
|
||||
var testSoaQuery = function() {
|
||||
result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_SOA);
|
||||
assertEqual(result.length, 1);
|
||||
assertEqual(result[0].email, "hostmaster.nomatic.org");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Testing MX record queries
|
||||
*/
|
||||
var testMxQuery = function() {
|
||||
result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_MX);
|
||||
assertEqual(result.length, 1);
|
||||
assertEqual(result[0].mx, "grace.nomatic.org");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Testing NS record queries
|
||||
*/
|
||||
var testNsQuery = function() {
|
||||
result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_NS);
|
||||
assertEqual(result.length, 3);
|
||||
// can't test single records as their order changes unpredictably
|
||||
return;
|
||||
};
|
BIN
modules/jala/tests/Form.fileupload.doc
Normal file
BIN
modules/jala/tests/Form.fileupload.doc
Normal file
Binary file not shown.
BIN
modules/jala/tests/Form.imageupload.jpg
Normal file
BIN
modules/jala/tests/Form.imageupload.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
460
modules/jala/tests/Form.js
Normal file
460
modules/jala/tests/Form.js
Normal file
|
@ -0,0 +1,460 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* a global variable containing the form instance
|
||||
* @type jala.Form
|
||||
*/
|
||||
var form;
|
||||
|
||||
|
||||
/**
|
||||
* Create and configure the form object
|
||||
*/
|
||||
var setup = function() {
|
||||
form = jala.Form.create(getConfig(), new DataObject());
|
||||
// form.render(); // show the test form
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Test the form rendering mechanism
|
||||
*/
|
||||
var testFormRender = function() {
|
||||
var html = new jala.HtmlDocument(form.renderAsString());
|
||||
var list = html.getAll("*");
|
||||
|
||||
var idx = 2;
|
||||
assertEqual(list[idx].name, "form");
|
||||
assertAttribute(list[idx].attributes, "id", "test");
|
||||
assertAttribute(list[idx].attributes, "class", "form");
|
||||
assertAttribute(list[idx].attributes, "name", "test");
|
||||
assertAttribute(list[idx].attributes, "enctype", "multipart/form-data");
|
||||
assertAttribute(list[idx].attributes, "method", "post");
|
||||
|
||||
|
||||
// alias / input
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testAlias");
|
||||
assertAttribute(list[idx].attributes, "class", "component require");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testAliasControl");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testAliasControl");
|
||||
assertAttribute(list[idx].attributes, "class", "input");
|
||||
assertAttribute(list[idx].attributes, "type", "text");
|
||||
assertAttribute(list[idx].attributes, "maxlength", "10");
|
||||
assertAttribute(list[idx].attributes, "name", "alias");
|
||||
assertAttribute(list[idx].attributes, "size", "20");
|
||||
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertEqual(list[idx].value, "Enter alias.");
|
||||
assertAttribute(list[idx].attributes, "class", "helpText");
|
||||
|
||||
|
||||
// desc / textarea
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testDesc");
|
||||
assertAttribute(list[idx].attributes, "class", "component require");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testDescControl");
|
||||
|
||||
assertEqual(list[++idx].name, "textarea");
|
||||
assertAttribute(list[idx].attributes, "id", "testDescControl");
|
||||
assertAttribute(list[idx].attributes, "class", "textarea");
|
||||
assertAttribute(list[idx].attributes, "name", "desc");
|
||||
assertAttribute(list[idx].attributes, "cols", "30");
|
||||
assertAttribute(list[idx].attributes, "rows", "3");
|
||||
|
||||
|
||||
|
||||
// pushdate / date
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testPushdate");
|
||||
assertAttribute(list[idx].attributes, "class", "component require");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testPushdateControl");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testPushdateControl");
|
||||
assertAttribute(list[idx].attributes, "class", "date");
|
||||
assertAttribute(list[idx].attributes, "type", "text");
|
||||
assertAttribute(list[idx].attributes, "name", "pushdate");
|
||||
|
||||
|
||||
// isonline / checkbox
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testIsonline");
|
||||
assertAttribute(list[idx].attributes, "class", "component optional");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testIsonlineControl");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testIsonlineControl");
|
||||
assertAttribute(list[idx].attributes, "type", "checkbox");
|
||||
assertAttribute(list[idx].attributes, "class", "checkbox");
|
||||
assertAttribute(list[idx].attributes, "name", "isonline");
|
||||
assertAttribute(list[idx].attributes, "value", "1");
|
||||
|
||||
|
||||
// category / select
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testCategory");
|
||||
assertAttribute(list[idx].attributes, "class", "component optional");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testCategoryControl");
|
||||
|
||||
assertEqual(list[++idx].name, "select");
|
||||
assertAttribute(list[idx].attributes, "id", "testCategoryControl");
|
||||
assertAttribute(list[idx].attributes, "class", "select");
|
||||
assertAttribute(list[idx].attributes, "name", "category");
|
||||
assertAttribute(list[idx].attributes, "size", "1");
|
||||
|
||||
assertEqual(list[++idx].name, "option");
|
||||
assertAttribute(list[idx].attributes, "value", "cat0");
|
||||
|
||||
assertEqual(list[++idx].name, "option");
|
||||
assertAttribute(list[idx].attributes, "value", "cat1");
|
||||
|
||||
assertEqual(list[++idx].name, "option");
|
||||
assertAttribute(list[idx].attributes, "value", "cat2");
|
||||
|
||||
assertEqual(list[++idx].name, "option");
|
||||
assertAttribute(list[idx].attributes, "value", "cat3");
|
||||
|
||||
|
||||
// fieldset
|
||||
assertEqual(list[++idx].name, "fieldset");
|
||||
|
||||
assertEqual(list[++idx].name, "legend");
|
||||
assertEqual(list[idx].value, "a fieldset");
|
||||
|
||||
|
||||
// fileupload
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testFileupload");
|
||||
assertAttribute(list[idx].attributes, "class", "component optional");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testFileuploadControl");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testFileuploadControl");
|
||||
assertAttribute(list[idx].attributes, "class", "file");
|
||||
assertAttribute(list[idx].attributes, "type", "file");
|
||||
assertAttribute(list[idx].attributes, "accept", "application/msword");
|
||||
assertAttribute(list[idx].attributes, "name", "fileupload");
|
||||
|
||||
|
||||
// imageupload
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testImageupload");
|
||||
assertAttribute(list[idx].attributes, "class", "component optional");
|
||||
|
||||
assertEqual(list[++idx].name, "label");
|
||||
assertAttribute(list[idx].attributes, "for", "testImageuploadControl");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testImageuploadControl");
|
||||
assertAttribute(list[idx].attributes, "class", "image");
|
||||
assertAttribute(list[idx].attributes, "type", "file");
|
||||
assertAttribute(list[idx].attributes, "name", "imageupload");
|
||||
|
||||
|
||||
// submit
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testSubmit");
|
||||
assertAttribute(list[idx].attributes, "class", "component");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testSubmitControl");
|
||||
assertAttribute(list[idx].attributes, "class", "submit");
|
||||
assertAttribute(list[idx].attributes, "name", "submit");
|
||||
assertAttribute(list[idx].attributes, "value", "Submit this form");
|
||||
assertAttribute(list[idx].attributes, "type", "submit");
|
||||
|
||||
|
||||
// cancel
|
||||
assertEqual(list[++idx].name, "div");
|
||||
assertAttribute(list[idx].attributes, "id", "testCancel");
|
||||
assertAttribute(list[idx].attributes, "class", "component");
|
||||
|
||||
assertEqual(list[++idx].name, "input");
|
||||
assertAttribute(list[idx].attributes, "id", "testCancelControl");
|
||||
assertAttribute(list[idx].attributes, "class", "button");
|
||||
assertAttribute(list[idx].attributes, "name", "cancel");
|
||||
assertAttribute(list[idx].attributes, "value", "Cancel edit");
|
||||
assertAttribute(list[idx].attributes, "type", "button");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the form validation mechanism
|
||||
*/
|
||||
var testFormValidate = function() {
|
||||
var reqData = getRequestData();
|
||||
|
||||
// default userinput values that should validate
|
||||
var tracker = form.validate(reqData);
|
||||
assertFalse(tracker.hasError());
|
||||
|
||||
// now try invalid values in userinput:
|
||||
reqData["alias"] = "a";
|
||||
reqData["desc"] = "";
|
||||
reqData["pushdate"] = "17.5.2007";
|
||||
reqData["category"] = "invalidOption";
|
||||
tracker = form.validate(reqData);
|
||||
assertTrue(tracker.hasError());
|
||||
assertEqual(tracker.errors["alias"], "Alias is too short.");
|
||||
assertEqual(tracker.errors["desc"], "Please enter text into this field.");
|
||||
assertEqual(tracker.errors["pushdate"], "This date cannot be parsed.");
|
||||
assertEqual(tracker.errors["category"], "Please select a valid option.");
|
||||
|
||||
// reset to default userinput:
|
||||
reqData = getRequestData();
|
||||
// require a smaller image:
|
||||
form.components.uploadfieldset.components.imageupload.require("maxwidth", 100, "Maximum width exceeded.");
|
||||
tracker = form.validate(reqData);
|
||||
assertTrue(tracker.hasError());
|
||||
assertEqual(tracker.errors["imageupload"], "Maximum width exceeded.");
|
||||
// undo image restriction:
|
||||
form.components.uploadfieldset.components.imageupload.require("maxwidth", 200, "Maximum width exceeded.");
|
||||
tracker = form.validate(reqData);
|
||||
assertFalse(tracker.hasError());
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Test the form rendering mechanism in the case of an error
|
||||
*/
|
||||
var testFormRenderWithError = function() {
|
||||
var reqData = getRequestData();
|
||||
reqData["alias"] = "a";
|
||||
var tracker = form.validate(reqData);
|
||||
|
||||
var html = new jala.HtmlDocument(form.renderAsString());
|
||||
var list = html.getAll("*");
|
||||
assertEqual(list[4].name, "div");
|
||||
assertEqual(list[4].value, "Alias is too short.");
|
||||
assertAttribute(list[4].attributes, "class", "errorText");
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Test the form save mechanism
|
||||
*/
|
||||
var testFormSave = function() {
|
||||
var dataObj = form.getDataObject();
|
||||
|
||||
var reqData = getRequestData();
|
||||
var tracker = form.validate(reqData);
|
||||
assertFalse(tracker.hasError());
|
||||
form.save();
|
||||
assertEqual(dataObj.alias, "aliasValue");
|
||||
assertEqual(dataObj.getProperty("desc"), "descriptionValue");
|
||||
assertEqual(dataObj.pushdate.toString(), new Date(2007, 4, 17, 11, 32, 0).toString());
|
||||
assertEqual(dataObj.isonline, 1);
|
||||
assertEqual(dataObj.getProperty("category"), "cat2");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to dump an html element to the response
|
||||
* @param {Object} el
|
||||
*/
|
||||
var debugElement = function(el) {
|
||||
res.write("<b>" + el.name + "</b> (" + el.value + ")<br/>");
|
||||
if (el.attributes) {
|
||||
var attrList = el.attributes;
|
||||
for (var i=0; i<attrList.length; i++) {
|
||||
res.write(attrList[i].name + " = " + attrList[i].value + "<br/>");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to assert that a given attribute exists
|
||||
* in an element
|
||||
* @param {Array} attrList Array with attribute objects
|
||||
* @param {String} name Name of attribute
|
||||
* @param {String} value Value of attribute
|
||||
*/
|
||||
var assertAttribute = function(attrList, name, value) {
|
||||
for (var i=0; i<attrList.length; i++) {
|
||||
if (attrList[i].name == name) {
|
||||
if (attrList[i].value != value) {
|
||||
throw new jala.Test.TestException("",
|
||||
"assertAttribute: Expected value of attribute \"" + name + "\" to be equal to \"" + value + "\" (but it is \"" + attrList[i].value + "\" instead).");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new jala.Test.TestException("", "assertAttribute: Attribute " + name + " not included in attributes.");
|
||||
};
|
||||
|
||||
|
||||
var DataObject = function() {
|
||||
var props = {};
|
||||
this.setProperty = function (name, value) {
|
||||
props[name] = value;
|
||||
};
|
||||
this.getProperty = function(name) {
|
||||
return props[name];
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
var getRequestData = function() {
|
||||
var fileupload = "Form.fileupload.doc";
|
||||
var imageupload = "Form.imageupload.jpg";
|
||||
return {
|
||||
alias: "aliasValue",
|
||||
desc: "descriptionValue",
|
||||
pushdate: "17.5.2007 11:32",
|
||||
category: "cat2",
|
||||
isonline: "1",
|
||||
test_submit: "Submit",
|
||||
imageupload: new Packages.helma.util.MimePart(
|
||||
imageupload,
|
||||
jala.Test.getTestFile(imageupload).toByteArray(),
|
||||
"image/jpeg"
|
||||
),
|
||||
fileupload: new Packages.helma.util.MimePart(
|
||||
fileupload,
|
||||
jala.Test.getTestFile(fileupload).toByteArray(),
|
||||
"application/msword"
|
||||
)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var getConfig = function() {
|
||||
return {
|
||||
name: "test",
|
||||
className: "form",
|
||||
components:[
|
||||
{
|
||||
// name: "alias", deliberately left out, should construct name from label
|
||||
label: "Alias",
|
||||
help: "Enter alias.",
|
||||
minlength: 4,
|
||||
maxlength: 10,
|
||||
require: true,
|
||||
messages: {
|
||||
require: "Alias is required.",
|
||||
maxlength: "Alias is too long.",
|
||||
minlength: "Alias is too short."
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "desc",
|
||||
type: "textarea",
|
||||
rows: 3,
|
||||
cols: 30,
|
||||
require: true,
|
||||
getter: function(name) {
|
||||
return this.getProperty(name);
|
||||
},
|
||||
setter: function(name, val) {
|
||||
return this.setProperty(name, val);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "pushdate",
|
||||
type: "date",
|
||||
dateFormat: "d.M.yyyy H:m",
|
||||
require: true
|
||||
},
|
||||
{
|
||||
name: "isonline",
|
||||
type: "checkbox"
|
||||
},
|
||||
{ name: "category",
|
||||
type: "select",
|
||||
options: function() {
|
||||
var arr = [];
|
||||
for (var i=0; i<4; i++) {
|
||||
arr[arr.length] = {
|
||||
value: "cat" + i,
|
||||
display: "Category " + i
|
||||
};
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
getter: function(name) {
|
||||
return this.getProperty("category");
|
||||
},
|
||||
setter: function(name, value) {
|
||||
this.setProperty("category", value);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "uploadfieldset",
|
||||
type: "fieldset",
|
||||
legend: "a fieldset",
|
||||
components:[
|
||||
{
|
||||
name: "fileupload",
|
||||
type: "file",
|
||||
maxlength: 500000,
|
||||
contenttype: "application/msword",
|
||||
},
|
||||
{
|
||||
name: "imageupload",
|
||||
type: "image",
|
||||
minwidth: 10,
|
||||
maxwidth: 200,
|
||||
minheight: 10,
|
||||
maxheight: 200
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "submit",
|
||||
type: "submit",
|
||||
value: "Submit this form"
|
||||
},
|
||||
{
|
||||
name: "cancel",
|
||||
type: "button",
|
||||
value: "Cancel edit"
|
||||
}
|
||||
]};
|
||||
};
|
||||
|
53
modules/jala/tests/HopObject.js
Normal file
53
modules/jala/tests/HopObject.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
var result = undefined;
|
||||
|
||||
/**
|
||||
* Unit test for {@link #HopObject.getAccessName}.
|
||||
*/
|
||||
var testGetAccessName = function() {
|
||||
var name = "foobar";
|
||||
var collection = new HopObject();
|
||||
|
||||
assertEqual(collection.getAccessName(name), name);
|
||||
// Test alias with the same name as a default HopObject method
|
||||
assertNotEqual(collection.getAccessName("get"), "get");
|
||||
assertEqual(collection.getAccessName("get"), "get-1");
|
||||
// Set a custom property of the collection and test it
|
||||
collection[name] = true;
|
||||
assertNotEqual(collection.getAccessName(name), name);
|
||||
assertEqual(collection.getAccessName(name), name + "-1");
|
||||
|
||||
// Set custom properties equally to the method's numbering
|
||||
collection[name + "-1"] = true;
|
||||
collection[name + "-12"] = true;
|
||||
assertNotEqual(collection.getAccessName(name), name + "1");
|
||||
assertNotEqual(collection.getAccessName(name), name + "12");
|
||||
assertEqual(collection.getAccessName(name), name + "-2");
|
||||
|
||||
assertNotEqual(collection.getAccessName(name, name.length), name);
|
||||
assertEqual(collection.getAccessName(name, name.length), "foob-1");
|
||||
return;
|
||||
};
|
||||
|
77
modules/jala/tests/HtmlDocument.js
Normal file
77
modules/jala/tests/HtmlDocument.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
var source = '<html><head><title>Test</title></head><body>' +
|
||||
'<h1>Hello, World!</h1>' +
|
||||
'<a href="http://localhost/1">foo</a>' +
|
||||
'<div><a href="http://localhost/2">bar</a></div>' +
|
||||
'<a href="http://localhost/3">foobar</a>' +
|
||||
'</body></html>';
|
||||
|
||||
/**
|
||||
* Simple test of the HtmlDocument.getLinks method.
|
||||
* An instance of HtmlDocument is created from a very
|
||||
* simple HTML source. The result of getLinks is then
|
||||
* evaluated and tested.
|
||||
*/
|
||||
var testGetLinks = function() {
|
||||
var html = new jala.HtmlDocument(source);
|
||||
var links = html.getLinks();
|
||||
assertEqual(links.constructor, Array);
|
||||
assertEqual(links.length, 3);
|
||||
assertEqual(links[0].constructor, Object);
|
||||
for (var i in links) {
|
||||
assertNotUndefined(links[i].url);
|
||||
assertNotUndefined(links[i].text);
|
||||
}
|
||||
assertEqual(links[0].url, "http://localhost/1");
|
||||
assertEqual(links[0].text, "foo");
|
||||
assertEqual(links[1].url, "http://localhost/2");
|
||||
assertEqual(links[1].text, "bar");
|
||||
assertEqual(links[2].url, "http://localhost/3");
|
||||
assertEqual(links[2].text, "foobar");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple test of the HtmlDocument.geAll method.
|
||||
* An instance of HtmlDocument is created from a very
|
||||
* simple HTML source. The result of getAll is then
|
||||
* evaluated and tested.
|
||||
*/
|
||||
var testGetAll = function() {
|
||||
var names = ["html", "head", "title", "body", "h1", "a", "div", "a", "a"];
|
||||
var html = new jala.HtmlDocument(source);
|
||||
var list = html.getAll("*");
|
||||
for (var i in list) {
|
||||
assertNotUndefined(list[i].name);
|
||||
assertEqual(list[i].name, names[i]);
|
||||
}
|
||||
assertEqual(list[2].value, "Test");
|
||||
assertEqual(list[4].value, "Hello, World!");
|
||||
assertEqual(list[5].value, "foo");
|
||||
assertEqual(list[7].value, "bar");
|
||||
assertEqual(list[8].value, "foobar");
|
||||
assertEqual(html.getAll("h1")[0].value, "Hello, World!");
|
||||
return;
|
||||
};
|
136
modules/jala/tests/I18n.js
Normal file
136
modules/jala/tests/I18n.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Declare which test methods should be run in which order
|
||||
* @type Array
|
||||
* @final
|
||||
*/
|
||||
|
||||
var oldMessages;
|
||||
|
||||
/**
|
||||
* Called before running the tests
|
||||
*/
|
||||
var setup = function() {
|
||||
// save any currently used message bundle before
|
||||
// creating the one for this test
|
||||
oldMessages = jala.i18n.getMessages();
|
||||
// setup the test message bundle
|
||||
var messages = {};
|
||||
messages.de_AT = {
|
||||
"Hello, World!": "Hallo, Welt!",
|
||||
"This is {0}.": "Das ist {0}.",
|
||||
"You've got one new mail.": "Du hast eine neue E-Mail.",
|
||||
"You've got {0} new mails.": "Du hast {0} neue E-Mails."
|
||||
};
|
||||
// tell jala where to find the messages
|
||||
jala.i18n.setMessages(messages);
|
||||
// assign a method for retrieving the locale for translation
|
||||
jala.i18n.setLocaleGetter(new Function("return res.meta.locale;"));
|
||||
// set the locale to use by jala.i18n
|
||||
res.meta.locale = new java.util.Locale("de", "AT");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Called after tests have finished. This method will be called
|
||||
* regarless whether the test succeeded or failed.
|
||||
*/
|
||||
var cleanup = function() {
|
||||
// restore any previous message set
|
||||
jala.i18n.setMessages(oldMessages);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests for formatMessage
|
||||
*/
|
||||
var testFormatMessage = function() {
|
||||
var msg = "Es ist jetzt {0,date,EEEE, dd. MMMM yyyy, HH:mm} Uhr.";
|
||||
var args = [new Date(2007, 1, 8, 17, 58)];
|
||||
var result = jala.i18n.formatMessage(msg, args);
|
||||
var expected = "Es ist jetzt Donnerstag, 08. Februar 2007, 17:58 Uhr.";
|
||||
assertEqual(expected, result);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests for gettext()
|
||||
*/
|
||||
var testGettext = function() {
|
||||
assertEqual("Hallo, Welt!", gettext("Hello, World!"));
|
||||
// test not found message key
|
||||
assertEqual("Hello You!", gettext("Hello You!"));
|
||||
// test gettext with additional replacement value
|
||||
assertEqual("Das ist Jala I18n.", gettext("This is {0}.", "Jala I18n"));
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests for ngettext()
|
||||
*/
|
||||
var testNgettext = function() {
|
||||
// zero
|
||||
assertEqual("Du hast 0 neue E-Mails.",
|
||||
ngettext("You've got one new mail.",
|
||||
"You've got {0} new mails.",
|
||||
0));
|
||||
// one
|
||||
assertEqual("Du hast eine neue E-Mail.",
|
||||
ngettext("You've got one new mail.",
|
||||
"You've got {0} new mails.",
|
||||
1));
|
||||
// more
|
||||
assertEqual("Du hast 23 neue E-Mails.",
|
||||
ngettext("You've got one new mail.",
|
||||
"You've got {0} new mails.",
|
||||
23));
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests for message macro
|
||||
*/
|
||||
var testMessageMacro = function() {
|
||||
// singular
|
||||
var skin = createSkin('<% message text="You\'ve got one new mail." %>');
|
||||
assertEqual("Du hast eine neue E-Mail.", renderSkinAsString(skin));
|
||||
|
||||
res.handlers.testHandler = {value: 0};
|
||||
// value replacement using testHandler
|
||||
skin = createSkin('<% message text="You\'ve got {0} new mails." values="testHandler.value" %>');
|
||||
assertEqual("Du hast 0 neue E-Mails.", renderSkinAsString(skin));
|
||||
// plural including replacement using testHandler
|
||||
res.handlers.testHandler.value = 23;
|
||||
skin = createSkin('<% message text="You\'ve got one new mail." plural="You\'ve got {0} new mails." values="testHandler.value" %>');
|
||||
assertEqual("Du hast 23 neue E-Mails.", renderSkinAsString(skin));
|
||||
// using a value of the param object passed to the skin
|
||||
// FIXME: appearently this doesn't work, but why?
|
||||
/*
|
||||
skin = createSkin('<% message text="You\'ve got one new mail." plural="You\'ve got {0} new mails." values="param.spam" %>');
|
||||
assertEqual("Du hast 45 neue E-Mails.", renderSkinAsString(skin, {spam: 45}));
|
||||
*/
|
||||
};
|
100
modules/jala/tests/ImageFilter.js
Normal file
100
modules/jala/tests/ImageFilter.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* Called after tests have finished. This method will be called
|
||||
* regarless whether the test succeeded or failed.
|
||||
*/
|
||||
var cleanup = function() {
|
||||
var tempDir = new helma.File(java.lang.System.getProperty("java.io.tmpdir"));
|
||||
var names = ["sharpen", "unsharpMask", "gaussianBlur"];
|
||||
var file;
|
||||
for (var i=0; i<names.length; i++) {
|
||||
file = new helma.File(tempDir, names[i] + ".temp.jpg");
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper method to test jala.ImageFilter. The argument
|
||||
* specifies the desired method which will be applied to a
|
||||
* source image. Then, the result is compared with a corresponding
|
||||
* reference image which was created by the same method beforehand.
|
||||
* Because comparing binary images is generally questionable, test
|
||||
* errors do not necessarily mean there are flaws in the Jala code
|
||||
* but of course can hint changes in the underlying Java code.
|
||||
*/
|
||||
var doTestImageFilter = function(methodName) {
|
||||
var testsDir = jala.Test.getTestsDirectory() + "/";
|
||||
var tempDir = new helma.File(java.lang.System.getProperty("java.io.tmpdir"));
|
||||
var tempPath = tempDir + "/" + methodName + ".temp.jpg";
|
||||
|
||||
// Define source and reference images
|
||||
var sourceImage = new jala.ImageFilter(testsDir + "test.jpg");
|
||||
var reference = new jala.ImageFilter(testsDir + methodName + ".reference.jpg");
|
||||
|
||||
// Apply the image filter and save the result as file
|
||||
sourceImage[methodName]();
|
||||
sourceImage.getImage().saveAs(tempPath);
|
||||
|
||||
// Define the result as jala.ImageFilter object again
|
||||
// (Necessary because byte data in the file differs generally.)
|
||||
var img = new jala.ImageFilter(tempPath);
|
||||
|
||||
// Compare the byte data of the result with those of the reference
|
||||
var imgBytes = img.getBytes();
|
||||
var refBytes = reference.getBytes();
|
||||
assertEqual(imgBytes.length, refBytes.length);
|
||||
|
||||
for (var i=0; i<imgBytes.length; i+=1) {
|
||||
assertEqual(imgBytes[i], refBytes[i]);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple test of the sharpen method of jala.ImageFilter.
|
||||
*/
|
||||
var testSharpen = function() {
|
||||
doTestImageFilter("sharpen");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple test of the unsharpMask method of jala.ImageFilter.
|
||||
*/
|
||||
var testUnsharpMask = function() {
|
||||
doTestImageFilter("unsharpMask");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple test of the gaussianBlur method of jala.ImageFilter.
|
||||
*/
|
||||
var testGaussianBlur = function() {
|
||||
doTestImageFilter("gaussianBlur");
|
||||
return;
|
||||
};
|
260
modules/jala/tests/IndexManager.js
Normal file
260
modules/jala/tests/IndexManager.js
Normal file
|
@ -0,0 +1,260 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* Contains the index manager to test
|
||||
* @type jala.IndexManager
|
||||
*/
|
||||
var index;
|
||||
|
||||
/**
|
||||
* Contains the queue of the index manager
|
||||
*/
|
||||
var queue;
|
||||
|
||||
/**
|
||||
* A global id "counter"
|
||||
*/
|
||||
var idCounter;
|
||||
|
||||
/**
|
||||
* Called before running the tests
|
||||
*/
|
||||
var setup = function() {
|
||||
// create the index to test
|
||||
var dir = new java.io.File(java.lang.System.getProperty("java.io.tmpdir"));
|
||||
index = new jala.IndexManager("test", dir, "de");
|
||||
queue = index.getQueue();
|
||||
idCounter = 0;
|
||||
index.start();
|
||||
index.add(createDocumentObject());
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called after tests have finished. This method will be called
|
||||
* regarless whether the test succeeded or failed.
|
||||
*/
|
||||
var cleanup = function() {
|
||||
if (index) {
|
||||
// clear the index before removing the index directory itself
|
||||
index.getIndex().create();
|
||||
var dir = new java.io.File(java.lang.System.getProperty("java.io.tmpdir"), "test");
|
||||
if (dir.exists()) {
|
||||
var segments = new java.io.File(dir, "segments");
|
||||
if (segments.exists()) {
|
||||
segments["delete"]();
|
||||
}
|
||||
dir["delete"]();
|
||||
}
|
||||
index.stop();
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test adding a document object immediately
|
||||
*/
|
||||
var testAdd = function() {
|
||||
index.add(createDocumentObject());
|
||||
// check queue and job
|
||||
assertEqual("q size", queue.size(), 2);
|
||||
assertEqual("q 0th type", queue.get(0).type, jala.IndexManager.Job.ADD);
|
||||
// check if the document was added correctly
|
||||
// but give the index manager time to process
|
||||
java.lang.Thread.currentThread().sleep(500);
|
||||
assertEqual("index size", index.getIndex().size(), 2);
|
||||
assertEqual("new q size", queue.size(), 0);
|
||||
// check if the index has been optimized
|
||||
var reader = null;
|
||||
try {
|
||||
reader = index.getIndex().getReader();
|
||||
assertTrue(reader.isOptimized());
|
||||
} finally {
|
||||
if (reader !== null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test removing a document object immediately
|
||||
*/
|
||||
var testRemove = function() {
|
||||
var id = 0;
|
||||
index.remove(id);
|
||||
// check queue and job
|
||||
assertEqual("queue size", queue.size(), 2);
|
||||
assertEqual("type is remove", queue.get(1).type, jala.IndexManager.Job.REMOVE);
|
||||
// check if the document was added correctly
|
||||
// but give the index manager time to process
|
||||
java.lang.Thread.currentThread().sleep(500);
|
||||
assertEqual("empty index", index.getIndex().size(), 0);
|
||||
assertEqual("empty queue", queue.size(), 0);
|
||||
// check if the index has been optimized
|
||||
var reader = null;
|
||||
try {
|
||||
reader = index.getIndex().getReader();
|
||||
assertTrue("is optimized", reader.isOptimized());
|
||||
} finally {
|
||||
if (reader !== null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test immediate index optimization
|
||||
*/
|
||||
var testOptimize = function() {
|
||||
index.optimize();
|
||||
// check queue and job
|
||||
assertEqual(queue.size(), 2);
|
||||
assertEqual(queue.get(1).type, jala.IndexManager.Job.OPTIMIZE);
|
||||
// give the index manager time to process
|
||||
java.lang.Thread.currentThread().sleep(300);
|
||||
assertFalse(index.hasOptimizingJob());
|
||||
// check if the index has been optimized
|
||||
var reader = null;
|
||||
try {
|
||||
reader = index.getIndex().getReader();
|
||||
assertTrue(reader.isOptimized());
|
||||
} finally {
|
||||
if (reader !== null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new document object to be put into the index
|
||||
* @returns A newly created document object containing test data
|
||||
* @type helma.Search.Document
|
||||
*/
|
||||
var createDocumentObject = function() {
|
||||
var id = idCounter;
|
||||
var doc = new helma.Search.Document();
|
||||
doc.addField("id", id, {store: "yes", index: "unTokenized"});
|
||||
doc.addField("name", "Document " + id, {store: "yes", index: "tokenized"});
|
||||
doc.addField("createtime", (new Date()).format("yyyyMMddHHmm"), {store: "yes", index: "unTokenized"});
|
||||
idCounter += 1;
|
||||
return doc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test query parsing
|
||||
*/
|
||||
var testParseQuery = function() {
|
||||
assertThrows(function() {
|
||||
index.parseQuery();
|
||||
});
|
||||
assertThrows(function() {
|
||||
index.parseQuery("test");
|
||||
});
|
||||
var query;
|
||||
query = index.parseQuery("test", ["title"]);
|
||||
assertTrue(query instanceof Packages.org.apache.lucene.search.TermQuery);
|
||||
assertEqual(query.getTerm().field(), "title");
|
||||
query = index.parseQuery("test again", ["title"]);
|
||||
assertTrue(query instanceof Packages.org.apache.lucene.search.BooleanQuery);
|
||||
assertEqual(query.getClauses().length, 2);
|
||||
|
||||
// test with more than one field
|
||||
query = index.parseQuery("test", ["title", "body"]);
|
||||
assertTrue(query instanceof Packages.org.apache.lucene.search.BooleanQuery);
|
||||
assertEqual(query.getClauses().length, 2);
|
||||
assertEqual(query.getClauses()[0].getQuery().getTerm().field(), "title");
|
||||
assertEqual(query.getClauses()[1].getQuery().getTerm().field(), "body");
|
||||
|
||||
// test boostmap
|
||||
query = index.parseQuery("test", ["title", "body", "creator"], {title: 10, body: 5});
|
||||
assertEqual(query.getClauses()[0].getQuery().getBoost(), 10);
|
||||
assertEqual(query.getClauses()[1].getQuery().getBoost(), 5);
|
||||
// default boost factor is 1
|
||||
assertEqual(query.getClauses()[2].getQuery().getBoost(), 1);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test query filter parsing
|
||||
*/
|
||||
var testParseQueryFilter = function() {
|
||||
assertNull(index.parseQueryFilter());
|
||||
var query;
|
||||
query = index.parseQueryFilter("title:test");
|
||||
assertTrue(query instanceof Packages.org.apache.lucene.search.CachingWrapperFilter);
|
||||
// FIXME: can't reach the wrapped query filter, therefor this stupid assertion
|
||||
assertEqual(query.toString(), "CachingWrapperFilter(QueryWrapperFilter(title:test))");
|
||||
query = index.parseQueryFilter(["title:test", "body:test"]);
|
||||
assertTrue(query instanceof Packages.org.apache.lucene.search.CachingWrapperFilter);
|
||||
assertEqual(query.toString(), "CachingWrapperFilter(QueryWrapperFilter(+title:test +body:test))");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test searching the index
|
||||
*/
|
||||
var testSearch = function() {
|
||||
for (var i = 0; i < 10; i += 1) {
|
||||
index.add(createDocumentObject());
|
||||
}
|
||||
// check if the documents was added correctly
|
||||
// but give the index manager time to process
|
||||
java.lang.Thread.currentThread().sleep(300);
|
||||
// check if the index has been optimized
|
||||
var reader = null;
|
||||
try {
|
||||
reader = index.getIndex().getReader();
|
||||
assertTrue("is optimized", reader.isOptimized());
|
||||
} finally {
|
||||
if (reader !== null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
var query = index.parseQuery("doc*", ["name"]);
|
||||
var hits, filter, sortFields;
|
||||
// test basic search
|
||||
hits = index.search(query);
|
||||
assertNotNull("non null hits", hits);
|
||||
assertEqual("hit count", hits.size(), 11);
|
||||
// test (stupid) filtering
|
||||
filter = index.parseQueryFilter("id:1");
|
||||
hits = index.search(query, filter);
|
||||
assertEqual("1 hit", hits.size(), 1);
|
||||
assertEqual("first hit id", parseInt(hits.get(0).getField("id").value, 10), 1);
|
||||
// test range filtering
|
||||
filter = index.parseQueryFilter("id:[2 TO 6]");
|
||||
hits = index.search(query, filter);
|
||||
assertEqual("5 hits", hits.size(), 5);
|
||||
// test sorting
|
||||
sortFields = [new Packages.org.apache.lucene.search.SortField("id", true)];
|
||||
hits = index.search(query, null, sortFields);
|
||||
assertEqual("new hit count", hits.size(), 11);
|
||||
assertEqual("first hit id", parseInt(hits.get(0).getField("id").value, 10), 10);
|
||||
assertEqual("last hit id", parseInt(hits.get(9).getField("id").value, 10), 1);
|
||||
return;
|
||||
};
|
197
modules/jala/tests/ListRenderer.js
Normal file
197
modules/jala/tests/ListRenderer.js
Normal file
|
@ -0,0 +1,197 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* Construct different collections as basis for the tests
|
||||
*/
|
||||
// 1. ArrayList
|
||||
var arrayList = new jala.ListRenderer.ArrayList((function() {
|
||||
var coll = [];
|
||||
for (var i=0; i<19; i++) {
|
||||
coll[i] = {id: i, title: "Object Nr. " + i};
|
||||
}
|
||||
return coll;
|
||||
})());
|
||||
|
||||
// 2. HopObject
|
||||
var hopObject = new HopObject();
|
||||
var obj;
|
||||
for (var i=0; i<19; i++) {
|
||||
obj = new HopObject();
|
||||
obj.title = "HopObject Nr. " + i;
|
||||
hopObject.add(obj);
|
||||
}
|
||||
|
||||
// 3. Array
|
||||
var array = [];
|
||||
for (var i=0; i<19; i++) {
|
||||
array[i] = {id: i, title: "Object Nr. " + i};
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor
|
||||
*/
|
||||
var testConstructor = function() {
|
||||
// should throw an exception when called without or with invalid arguments
|
||||
assertThrows(function() {
|
||||
new jala.ListRenderer(true);
|
||||
});
|
||||
assertThrows(function() {
|
||||
new jala.ListRenderer();
|
||||
});
|
||||
// test constructor with arrayList
|
||||
var list = new jala.ListRenderer(arrayList);
|
||||
assertEqual(list.getCollection(), arrayList);
|
||||
// test constructor with hopObjectCollection
|
||||
list = new jala.ListRenderer(hopObject);
|
||||
assertEqual(list.getCollection(), hopObject);
|
||||
// test constructor with an array
|
||||
list = new jala.ListRenderer(array);
|
||||
assertEqual(list.getCollection().constructor, jala.ListRenderer.ArrayList);
|
||||
|
||||
// test backwards compatibility
|
||||
var listParam = {
|
||||
collection: hopObject,
|
||||
href: "http://localhost/test",
|
||||
urlParams: "one=two&three=four",
|
||||
urlParamName: "seite",
|
||||
itemsPerPage: 5,
|
||||
maxPages: 3,
|
||||
itemSkin: "preview",
|
||||
};
|
||||
var list = new jala.ListRenderer(listParam);
|
||||
assertEqual(list.getCollection(), listParam.collection);
|
||||
assertEqual(list.getBaseHref(), listParam.href);
|
||||
assertEqual(list.getUrlParameters(), listParam.urlParams);
|
||||
assertEqual(list.getUrlParameterName(), listParam.urlParamName);
|
||||
assertEqual(list.getPageSize(), listParam.itemsPerPage);
|
||||
assertEqual(list.getMaxPages(), listParam.maxPages);
|
||||
assertEqual(list.getItemSkin(), listParam.itemSkin);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the calculation of the page number under various circumstances
|
||||
*/
|
||||
var testPageCalculation = function() {
|
||||
var list = new jala.ListRenderer(arrayList);
|
||||
list.setPageSize(3);
|
||||
assertEqual(list.getTotalPages(), 7);
|
||||
// after setting maxPages, getTotalPages() should return this value
|
||||
list.setMaxPages(3);
|
||||
assertEqual(list.getTotalPages(), 3);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the start and end index calculation
|
||||
*/
|
||||
var testIndexCalculation = function() {
|
||||
var list = new jala.ListRenderer(arrayList);
|
||||
list.setPageSize(5);
|
||||
req.data.page = "456";
|
||||
assertEqual(list.getStartIndex(), 15);
|
||||
assertEqual(list.getEndIndex(), 18);
|
||||
// test the appropriate macros too
|
||||
assertEqual(list.currentStart_macro(), 16);
|
||||
assertEqual(list.currentEnd_macro(), 19);
|
||||
assertEqual(list.size_macro(), 19);
|
||||
// limit the number of pages - the size_macro() should return the correct value
|
||||
list.setMaxPages(2);
|
||||
assertEqual(list.size_macro(), 10);
|
||||
// reset req.data.page
|
||||
delete req.data.page;
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the construction of page hrefs
|
||||
*/
|
||||
var testHrefs = function() {
|
||||
var baseHref = "http://localhost/test/list";
|
||||
var list = new jala.ListRenderer(arrayList);
|
||||
list.setBaseHref(baseHref);
|
||||
assertEqual(list.getBaseHref(), baseHref);
|
||||
// getPageHref without argument should return the href of the first page
|
||||
assertEqual(list.getPageHref(), baseHref + "?page=1");
|
||||
// tweak req.data to simulate a request for a certain page
|
||||
req.data.page = "2";
|
||||
assertEqual(list.getPageHref(), baseHref + "?page=2");
|
||||
// getPageHref with page number as argument
|
||||
assertEqual(list.getPageHref(10), baseHref + "?page=10");
|
||||
// invalid page arguments
|
||||
req.data.page = "nada";
|
||||
assertEqual(list.getPageHref(), baseHref + "?page=1");
|
||||
// for page numbers < 0 return the href of the first page
|
||||
req.data.page = "-10";
|
||||
assertEqual(list.getPageHref(), baseHref + "?page=1");
|
||||
// for page numbers exceeding the max. number of pages, return
|
||||
// the href of the last page
|
||||
req.data.page = "300";
|
||||
assertEqual(list.getPageHref(), baseHref + "?page=2");
|
||||
|
||||
// now test changing the page url parameter name
|
||||
list.setUrlParameterName("seite");
|
||||
assertEqual(list.getPageHref(2), baseHref + "?seite=2");
|
||||
|
||||
// add additional url parameters
|
||||
var params = "one=two&three=four";
|
||||
list.setUrlParameters(params);
|
||||
assertEqual(list.getPageHref(3), baseHref + "?" + params + "&seite=3");
|
||||
|
||||
// reset req.data.page
|
||||
delete req.data.page;
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test custom renderer
|
||||
*/
|
||||
var testRenderer = function() {
|
||||
// a pseudo renderer to check if overriding default renderer works
|
||||
var renderer = {
|
||||
"list": {
|
||||
"custom": function() {
|
||||
return;
|
||||
},
|
||||
"default": function() {
|
||||
return;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// use default renderer
|
||||
var list = new jala.ListRenderer(arrayList);
|
||||
assertEqual(list.getRenderFunction("list"),
|
||||
jala.ListRenderer.defaultRenderer.list["default"]);
|
||||
assertEqual(list.getRenderFunction("list", "nonexisting"),
|
||||
jala.ListRenderer.defaultRenderer.list["default"]);
|
||||
assertNull(list.getRenderFunction("nonexisting"));
|
||||
|
||||
// use custom renderer
|
||||
list = new jala.ListRenderer(arrayList, renderer);
|
||||
assertEqual(list.getRenderFunction("list", "custom"), renderer.list["custom"]);
|
||||
assertEqual(list.getRenderFunction("list", "nonexisting"), renderer.list["default"]);
|
||||
assertEqual(list.getRenderFunction("list"), renderer.list["default"]);
|
||||
return;
|
||||
};
|
184
modules/jala/tests/Mp3.js
Normal file
184
modules/jala/tests/Mp3.js
Normal file
|
@ -0,0 +1,184 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* a global variable containing the mp3 file to write to and read from
|
||||
* @type helma.File
|
||||
*/
|
||||
var mp3File, mp3Filev2, mp3FileNoTags;
|
||||
|
||||
var setup = function() {
|
||||
var srcFile = jala.Test.getTestFile("Mp3.test.mp3");
|
||||
mp3File = new helma.File(java.lang.System.getProperty("java.io.tmpdir"), "test.mp3");
|
||||
mp3Filev2 = new helma.File(java.lang.System.getProperty("java.io.tmpdir"), "testv2.mp3");
|
||||
mp3FileNoTags = new helma.File(java.lang.System.getProperty("java.io.tmpdir"), "test_notags.mp3");
|
||||
srcFile.hardCopy(mp3File);
|
||||
srcFile.hardCopy(mp3Filev2);
|
||||
srcFile.hardCopy(mp3FileNoTags);
|
||||
// create some mp3 v1 tags
|
||||
var mp3 = new jala.Mp3(mp3File);
|
||||
var tag = mp3.createV1Tag();
|
||||
tag.setArtist("v1 - jala.Mp3");
|
||||
tag.setTitle("v1 - Test");
|
||||
tag.setAlbum("v1 - Jala JavaScript Library");
|
||||
tag.setGenre("Electronic");
|
||||
tag.setComment("v1 - Play it loud!");
|
||||
tag.setTrackNumber("1");
|
||||
tag.setYear("2006");
|
||||
mp3.save();
|
||||
// crate mp3 v2 tags
|
||||
var mp3v2 = new jala.Mp3(mp3Filev2);
|
||||
var tagv2 = mp3v2.createV2Tag();
|
||||
tagv2.setArtist("v2 - jala.Mp3");
|
||||
tagv2.setTitle("v2 - Test");
|
||||
tagv2.setAlbum("v2 - Jala JavaScript Library");
|
||||
tagv2.setGenre("Electronic");
|
||||
tagv2.setComment("v2 - Play it loud!");
|
||||
tagv2.setTrackNumber("2");
|
||||
tagv2.setYear("2007");
|
||||
tagv2.setAuthor("SP");
|
||||
tagv2.setCopyright("ORF Online und Teletext GmbH");
|
||||
tagv2.setUrl("http://www.orf.at/");
|
||||
var imgFile = jala.Test.getTestFile("Mp3.test.jpg");
|
||||
tagv2.setImage(3, "image/jpeg", imgFile.toByteArray());
|
||||
mp3v2.save();
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write a v1 tag to the file
|
||||
*/
|
||||
var testId3v1Write = function() {
|
||||
var mp3 = new jala.Mp3(mp3FileNoTags);
|
||||
assertFalse(mp3.hasV1Tag());
|
||||
var tag = mp3.createV1Tag();
|
||||
assertNotNull(tag);
|
||||
tag.setArtist("v1 - jala.Mp3");
|
||||
tag.setTitle("v1 - Test");
|
||||
tag.setAlbum("v1 - Jala JavaScript Library");
|
||||
tag.setGenre("Electronic");
|
||||
tag.setComment("v1 - Play it loud!");
|
||||
tag.setTrackNumber("1");
|
||||
tag.setYear("2006");
|
||||
assertTrue(mp3.hasV1Tag());
|
||||
var oldsize = mp3.getSize();
|
||||
mp3.save();
|
||||
assertNotEqual(mp3.getSize(), oldsize);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a v1 tag from the file
|
||||
*/
|
||||
var testId3v1Read = function() {
|
||||
var mp3 = new jala.Mp3(mp3File);
|
||||
tag = mp3.getV1Tag();
|
||||
assertEqual(tag.getArtist(), "v1 - jala.Mp3");
|
||||
assertEqual(tag.getTitle(), "v1 - Test");
|
||||
assertEqual(tag.getAlbum(), "v1 - Jala JavaScript Library");
|
||||
assertEqual(tag.getGenre(), "Electronic");
|
||||
assertEqual(tag.getComment(), "v1 - Play it loud!");
|
||||
assertEqual(tag.getTrackNumber(), "1");
|
||||
assertEqual(tag.getYear(), "2006");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write a v2 tag to the file
|
||||
*/
|
||||
var testId3v2Write = function() {
|
||||
var mp3 = new jala.Mp3(mp3FileNoTags);
|
||||
assertFalse(mp3.hasV2Tag());
|
||||
var tag = mp3.createV2Tag();
|
||||
assertNotNull(tag);
|
||||
tag.setArtist("v2 - jala.Mp3");
|
||||
tag.setTitle("v2 - Test");
|
||||
tag.setAlbum("v2 - Jala JavaScript Library");
|
||||
tag.setGenre("Electronic");
|
||||
tag.setComment("v2 - Play it loud!");
|
||||
tag.setTrackNumber("2");
|
||||
tag.setYear("2007");
|
||||
|
||||
tag.setAuthor("SP");
|
||||
tag.setCopyright("ORF Online und Teletext GmbH");
|
||||
tag.setUrl("http://www.orf.at/");
|
||||
|
||||
var imgFile = jala.Test.getTestFile("Mp3.test.jpg");
|
||||
tag.setImage(3, "image/jpeg", imgFile.toByteArray());
|
||||
|
||||
var oldsize = mp3.getSize();
|
||||
mp3.save();
|
||||
assertNotEqual(mp3.getSize(), oldsize);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a v2 tag from the file
|
||||
*/
|
||||
var testId3v2Read = function() {
|
||||
var mp3 = new jala.Mp3(mp3Filev2);
|
||||
var tag = mp3.getV2Tag();
|
||||
assertEqual(tag.getArtist(), "v2 - jala.Mp3");
|
||||
assertEqual(tag.getTitle(), "v2 - Test");
|
||||
assertEqual(tag.getAlbum(), "v2 - Jala JavaScript Library");
|
||||
assertEqual(tag.getGenre(), "Electronic");
|
||||
assertEqual(tag.getComment(), "v2 - Play it loud!");
|
||||
assertEqual(tag.getTrackNumber(), "2");
|
||||
assertEqual(tag.getYear(), "2007");
|
||||
|
||||
assertEqual(tag.getAuthor(), "SP");
|
||||
assertEqual(tag.getCopyright(), "ORF Online und Teletext GmbH");
|
||||
assertEqual(tag.getUrl(), "http://www.orf.at/");
|
||||
|
||||
var mimeObj = tag.getImage();
|
||||
var imgFile = jala.Test.getTestFile("Mp3.test.jpg");
|
||||
assertEqual(mimeObj.contentLength, imgFile.getLength());
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A test of jala.Mp3
|
||||
*/
|
||||
var testMp3Read = function() {
|
||||
var mp3 = new jala.Mp3(mp3Filev2);
|
||||
assertEqual(mp3.artist, "v2 - jala.Mp3");
|
||||
assertEqual(mp3.title, "v2 - Test");
|
||||
assertEqual(mp3.album, "v2 - Jala JavaScript Library");
|
||||
assertEqual(mp3.genre, "Electronic");
|
||||
assertEqual(mp3.comment, "v2 - Play it loud!");
|
||||
assertEqual(mp3.trackNumber, "2");
|
||||
assertEqual(mp3.year, "2007");
|
||||
|
||||
assertEqual(mp3.getChannelMode(), "Stereo");
|
||||
assertEqual(mp3.getBitRate(), 192);
|
||||
assertEqual(mp3.getDuration(), 7);
|
||||
assertEqual(mp3.getSize(), 173704); // This is after writing tags!
|
||||
assertEqual(mp3.getFrequency(), 44.1);
|
||||
assertEqual(mp3.parseDuration(), 7);
|
||||
return;
|
||||
};
|
BIN
modules/jala/tests/Mp3.test.jpg
Normal file
BIN
modules/jala/tests/Mp3.test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
modules/jala/tests/Mp3.test.mp3
Normal file
BIN
modules/jala/tests/Mp3.test.mp3
Normal file
Binary file not shown.
131
modules/jala/tests/Utilities.js
Normal file
131
modules/jala/tests/Utilities.js
Normal file
|
@ -0,0 +1,131 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
/**
|
||||
* Unit test for #jala.util.createPassword.
|
||||
*/
|
||||
var testCreatePassword = function() {
|
||||
assertMatch(jala.util.createPassword(), /^[^\d]{8}$/);
|
||||
assertMatch(jala.util.createPassword(100), /^[^\d]{100}$/);
|
||||
assertMatch(jala.util.createPassword(null, 0), /^[^\d]{8}$/);
|
||||
assertMatch(jala.util.createPassword(100, 0), /^[^\d]{100}$/);
|
||||
assertMatch(jala.util.createPassword(null, 1), /^[\d\w]{8}$/);
|
||||
assertMatch(jala.util.createPassword(100, 1), /^[\d\w]{100}$/);
|
||||
assertEqual(jala.util.createPassword(null, 2).length, 8);
|
||||
assertEqual(jala.util.createPassword(100, 2).length, 100);
|
||||
return;
|
||||
};
|
||||
|
||||
var o1 = {a: 1, b: 2, d: 4, e: {f: 6, g: 7}, h: {i: 9}};
|
||||
var o2 = {a: 2, c: 3, d: 4, e: {f: 7, h: 8}, i: {j: 10}};
|
||||
var diff;
|
||||
|
||||
/**
|
||||
* Unit test for #jala.util.diffObjects.
|
||||
*/
|
||||
var testDiffObjects = function() {
|
||||
// diffing various simple objects
|
||||
diff = jala.util.diffObjects({}, {a: 1});
|
||||
assertNotNull(diff);
|
||||
assertEqual(diff.a.status, jala.Utilities.VALUE_ADDED);
|
||||
|
||||
diff = jala.util.diffObjects({a: 1}, {});
|
||||
assertNotNull(diff);
|
||||
assertEqual(diff.a.status, jala.Utilities.VALUE_REMOVED);
|
||||
|
||||
diff = jala.util.diffObjects({a: {b: 1}}, {a: 1});
|
||||
assertNotNull(diff);
|
||||
assertEqual(diff.a.status, jala.Utilities.VALUE_MODIFIED);
|
||||
|
||||
diff = jala.util.diffObjects({a: {b: 1}}, {a: {b: 1, c: 1}});
|
||||
assertNotNull(diff);
|
||||
assertEqual(diff.a.c.status, jala.Utilities.VALUE_ADDED);
|
||||
|
||||
diff = jala.util.diffObjects({a: {b: 1}}, {a: {c: 1}});
|
||||
assertNotNull(diff);
|
||||
assertEqual(diff.a.b.status, jala.Utilities.VALUE_REMOVED);
|
||||
assertEqual(diff.a.c.status, jala.Utilities.VALUE_ADDED);
|
||||
|
||||
// diffing pre-defined objects
|
||||
diff = jala.util.diffObjects(o1, o2);
|
||||
|
||||
assertNotNull(diff);
|
||||
assertNotUndefined(diff);
|
||||
assertEqual(diff.constructor, Object);
|
||||
|
||||
assertNotUndefined(diff.a);
|
||||
assertNotUndefined(diff.b);
|
||||
assertNotUndefined(diff.c);
|
||||
assertUndefined(diff.d);
|
||||
|
||||
assertNotNull(diff.a);
|
||||
assertNotNull(diff.b);
|
||||
assertNotNull(diff.c);
|
||||
|
||||
assertEqual(diff.a.value, o2.a);
|
||||
assertUndefined(diff.b.value);
|
||||
assertEqual(diff.c.value, o2.c);
|
||||
|
||||
assertEqual(diff.a.status, jala.Utilities.VALUE_MODIFIED);
|
||||
assertEqual(diff.b.status, jala.Utilities.VALUE_REMOVED);
|
||||
assertEqual(diff.c.status, jala.Utilities.VALUE_ADDED);
|
||||
assertEqual(diff.e.f.status, jala.Utilities.VALUE_MODIFIED);
|
||||
assertEqual(diff.e.g.status, jala.Utilities.VALUE_REMOVED);
|
||||
assertEqual(diff.e.h.status, jala.Utilities.VALUE_ADDED);
|
||||
assertEqual(diff.h.status, jala.Utilities.VALUE_REMOVED);
|
||||
assertEqual(diff.i.status, jala.Utilities.VALUE_ADDED);
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unit test for #jala.util.patchObject.
|
||||
*/
|
||||
var testPatchObject = function() {
|
||||
diff = jala.util.diffObjects(o1, o2);
|
||||
jala.util.patchObject(o1, diff);
|
||||
|
||||
assertNotNull(o1);
|
||||
assertNotUndefined(o1);
|
||||
assertEqual(o1.constructor, Object);
|
||||
|
||||
assertNotUndefined(o1.a);
|
||||
assertUndefined(o1.b);
|
||||
assertNotUndefined(o1.c);
|
||||
assertNotUndefined(o1.d);
|
||||
|
||||
assertNotNull(o1.a);
|
||||
assertNotNull(o1.c);
|
||||
assertNotNull(o1.d);
|
||||
|
||||
assertEqual(o1.a, o2.a);
|
||||
assertEqual(o1.c, o2.c);
|
||||
assertEqual(o1.d, o2.d);
|
||||
|
||||
assertEqual(o1.e.f, o2.e.f);
|
||||
assertUndefined(o1.e.g);
|
||||
assertEqual(o1.e.h, o2.e.h);
|
||||
assertUndefined(o1.h);
|
||||
assertEqual(o1.i.j, o2.i.j);
|
||||
return;
|
||||
};
|
BIN
modules/jala/tests/gaussianBlur.reference.jpg
Normal file
BIN
modules/jala/tests/gaussianBlur.reference.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
modules/jala/tests/sharpen.reference.jpg
Normal file
BIN
modules/jala/tests/sharpen.reference.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
BIN
modules/jala/tests/test.jpg
Normal file
BIN
modules/jala/tests/test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
modules/jala/tests/test.mp3
Normal file
BIN
modules/jala/tests/test.mp3
Normal file
Binary file not shown.
BIN
modules/jala/tests/unsharpMask.reference.jpg
Normal file
BIN
modules/jala/tests/unsharpMask.reference.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
Loading…
Add table
Add a link
Reference in a new issue