зеркало из https://github.com/mozilla/pluotsorbet.git
Merge branch 'master' into fs-perf
Conflicts: tests/automation.js
This commit is contained in:
Коммит
e2b10044c2
|
@ -30,6 +30,7 @@ public class DataDecoder {
|
|||
public native boolean getBoolean() throws IOException;
|
||||
|
||||
public byte[] getByteArray() throws IOException {
|
||||
throw new RuntimeException("DataDecoder::getByteArray() not implemented");
|
||||
System.out.println("DataDecoder::getByteArray() not implemented");
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,56 @@ NokiaMessagingLocalMsgConnection.prototype.sendMessageToServer = function(messag
|
|||
});
|
||||
}
|
||||
|
||||
var NokiaSASrvRegLocalMsgConnection = function() {
|
||||
LocalMsgConnection.call(this);
|
||||
};
|
||||
|
||||
NokiaSASrvRegLocalMsgConnection.prototype = Object.create(LocalMsgConnection.prototype);
|
||||
|
||||
NokiaSASrvRegLocalMsgConnection.prototype.sendMessageToServer = function(message) {
|
||||
var decoder = new DataDecoder(message.data, message.offset, message.length);
|
||||
|
||||
decoder.getStart(DataType.STRUCT);
|
||||
var name = decoder.getValue(DataType.METHOD);
|
||||
|
||||
var encoder = new DataEncoder();
|
||||
|
||||
switch (name) {
|
||||
case "Common":
|
||||
encoder.putStart(DataType.STRUCT, "event");
|
||||
encoder.put(DataType.METHOD, "name", "Common");
|
||||
encoder.putStart(DataType.STRUCT, "message");
|
||||
encoder.put(DataType.METHOD, "name", "ProtocolVersion");
|
||||
encoder.put(DataType.STRING, "version", "2.0");
|
||||
encoder.putEnd(DataType.STRUCT, "message");
|
||||
encoder.putEnd(DataType.STRUCT, "event");
|
||||
break;
|
||||
case "Discovery":
|
||||
encoder.putStart(DataType.STRUCT, "event");
|
||||
encoder.put(DataType.METHOD, "name", "Discovery");
|
||||
encoder.put(DataType.BYTE, "unknown_byte_1", 1);
|
||||
encoder.put(DataType.STRING, "unknown_string_1", "");
|
||||
encoder.putStart(DataType.ARRAY, "services");
|
||||
encoder.putStart(DataType.STRUCT, "service");
|
||||
encoder.put(DataType.STRING, "ServiceName", "file_ui");
|
||||
encoder.put(DataType.URI, "ServiceURI", "nokia.file-ui");
|
||||
encoder.put(DataType.STRING, "unknown_string_2", "");
|
||||
encoder.put(DataType.WSTRING, "unknown_string_3", "");
|
||||
encoder.put(DataType.STRING, "unknown_string_4", "");
|
||||
encoder.putEnd(DataType.STRUCT, "service");
|
||||
encoder.putEnd(DataType.ARRAY, "services");
|
||||
encoder.putEnd(DataType.STRUCT, "event");
|
||||
break;
|
||||
}
|
||||
|
||||
var data = new TextEncoder().encode(encoder.getData());
|
||||
this.sendMessageToClient({
|
||||
data: data,
|
||||
length: data.length,
|
||||
offset: 0,
|
||||
});
|
||||
};
|
||||
|
||||
var NokiaPhoneStatusLocalMsgConnection = function() {
|
||||
LocalMsgConnection.call(this);
|
||||
};
|
||||
|
@ -696,6 +746,7 @@ MIDP.LocalMsgConnections["nokia.messaging"] = new NokiaMessagingLocalMsgConnecti
|
|||
MIDP.LocalMsgConnections["nokia.phone-status"] = new NokiaPhoneStatusLocalMsgConnection();
|
||||
MIDP.LocalMsgConnections["nokia.file-ui"] = new NokiaFileUILocalMsgConnection();
|
||||
MIDP.LocalMsgConnections["nokia.image-processing"] = new NokiaImageProcessingLocalMsgConnection();
|
||||
MIDP.LocalMsgConnections["nokia.sa.service-registry"] = new NokiaSASrvRegLocalMsgConnection();
|
||||
|
||||
Native.create("org/mozilla/io/LocalMsgConnection.init.(Ljava/lang/String;)V", function(jName) {
|
||||
var name = util.fromJavaString(jName);
|
||||
|
|
|
@ -41,9 +41,9 @@ var gfxTests = [
|
|||
];
|
||||
|
||||
var expectedUnitTestResults = [
|
||||
{ name: "pass", number: 71104 },
|
||||
{ name: "pass", number: 71126 },
|
||||
{ name: "fail", number: 0 },
|
||||
{ name: "known fail", number: 179 },
|
||||
{ name: "known fail", number: 180 },
|
||||
{ name: "unknown pass", number: 0 }
|
||||
];
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package javax.microedition.media;
|
||||
|
||||
import gnu.testlet.TestHarness;
|
||||
import gnu.testlet.Testlet;
|
||||
import javax.microedition.io.*;
|
||||
import javax.microedition.io.file.*;
|
||||
import java.io.*;
|
||||
|
||||
public class TestAudioPlayer implements Testlet, PlayerListener {
|
||||
TestHarness th;
|
||||
|
||||
private static final long TIME_TOLERANCE = 50;
|
||||
|
||||
/**
|
||||
* PlayerListener interface's method.
|
||||
*/
|
||||
public void playerUpdate(Player player, String event, Object eventData) {
|
||||
System.out.println("playerUpdate event: " + event + " " + eventData);
|
||||
}
|
||||
|
||||
public void test(TestHarness th) {
|
||||
this.th = th;
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/midlets/MediaSampler/res/laser.wav");
|
||||
|
||||
// Test player with input stream.
|
||||
try {
|
||||
Player player = Manager.createPlayer(is, "audio/x-wav");
|
||||
testPlay(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
th.fail("Unexpected exception: " + e);
|
||||
}
|
||||
|
||||
// Test player with file URL.
|
||||
try {
|
||||
String url = "file:///laser.wav";
|
||||
FileConnection file = (FileConnection)Connector.open(url, Connector.READ_WRITE);
|
||||
if (!file.exists()) {
|
||||
file.create();
|
||||
}
|
||||
OutputStream os = file.openDataOutputStream();
|
||||
os.write(read(is));
|
||||
os.close();
|
||||
|
||||
Player player = Manager.createPlayer(url);
|
||||
testPlay(player);
|
||||
|
||||
file.delete();
|
||||
file.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Bug #651
|
||||
th.todo(false, "Unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] read(InputStream is) throws IOException {
|
||||
int l = is.available();
|
||||
byte[] buffer = new byte[l+1];
|
||||
int length = 0;
|
||||
|
||||
while ((l = is.read(buffer, length, buffer.length - length)) != -1) {
|
||||
length += l;
|
||||
if (length == buffer.length) {
|
||||
byte[] b = new byte[buffer.length + 4096];
|
||||
System.arraycopy(buffer, 0, b, 0, length);
|
||||
buffer = b;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private void testPlay(Player player) {
|
||||
try {
|
||||
player.addPlayerListener(this);
|
||||
|
||||
// Start playing.
|
||||
player.realize();
|
||||
player.prefetch();
|
||||
player.start();
|
||||
|
||||
// Check content type.
|
||||
th.check(player.getContentType(), "audio/x-wav");
|
||||
|
||||
// Sleep 100 mili seconds and check if the media time is around the
|
||||
// time interval slept.
|
||||
Thread.sleep(100);
|
||||
long mediaTime = player.getMediaTime() / 1000;
|
||||
th.check(Math.abs(mediaTime - 100) < TIME_TOLERANCE);
|
||||
|
||||
// Pause
|
||||
player.stop();
|
||||
mediaTime = player.getMediaTime() / 1000;
|
||||
Thread.sleep(200);
|
||||
th.check(player.getMediaTime() / 1000, mediaTime);
|
||||
|
||||
// Resume
|
||||
player.start();
|
||||
Thread.sleep(100);
|
||||
long m = player.getMediaTime() / 1000;
|
||||
th.check(Math.abs(m - mediaTime - 100) < TIME_TOLERANCE);
|
||||
|
||||
player.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
th.fail("Unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package javax.microedition.media.control;
|
||||
|
||||
import gnu.testlet.TestHarness;
|
||||
import gnu.testlet.Testlet;
|
||||
import java.io.*;
|
||||
import javax.microedition.media.*;
|
||||
|
||||
public class TestVolumeControl implements Testlet, PlayerListener {
|
||||
TestHarness th;
|
||||
|
||||
/**
|
||||
* PlayerListener interface's method.
|
||||
*/
|
||||
public void playerUpdate(Player player, String event, Object eventData) {
|
||||
System.out.println("playerUpdate event: " + event + " " + eventData);
|
||||
}
|
||||
|
||||
public void test(TestHarness th) {
|
||||
this.th = th;
|
||||
|
||||
try {
|
||||
// Create audio player and start playing.
|
||||
InputStream is = getClass().getResourceAsStream("/midlets/MediaSampler/res/laser.wav");
|
||||
Player player = Manager.createPlayer(is, "audio/x-wav");
|
||||
player.addPlayerListener(this);
|
||||
player.realize();
|
||||
player.prefetch();
|
||||
player.start();
|
||||
|
||||
// Get associated volume control from the audio player.
|
||||
VolumeControl control = (VolumeControl)player.getControl("VolumeControl");
|
||||
|
||||
// Change volume level.
|
||||
th.check(control.setLevel(10), 10);
|
||||
Thread.sleep(100);
|
||||
th.check(control.getLevel(), 10);
|
||||
th.check(control.isMuted(), false);
|
||||
|
||||
// Ensure the volume level is between 0 and 100.
|
||||
th.check(control.setLevel(-1), 0);
|
||||
th.check(control.getLevel(), 0);
|
||||
th.check(control.setLevel(120), 100);
|
||||
th.check(control.getLevel(), 100);
|
||||
|
||||
// Mute
|
||||
control.setMute(true);
|
||||
Thread.sleep(100);
|
||||
th.check(control.getLevel(), 100);
|
||||
th.check(control.isMuted(), true);
|
||||
|
||||
// Unmute
|
||||
control.setMute(false);
|
||||
th.check(control.isMuted(), false);
|
||||
th.check(control.getLevel(), 100);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
th.fail("Unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
package org.mozilla.io;
|
||||
|
||||
import java.io.*;
|
||||
import javax.microedition.io.*;
|
||||
import com.nokia.mid.s40.io.LocalMessageProtocolMessage;
|
||||
import com.nokia.mid.s40.io.LocalMessageProtocolConnection;
|
||||
import com.nokia.mid.s40.codec.DataEncoder;
|
||||
import com.nokia.mid.s40.codec.DataDecoder;
|
||||
import gnu.testlet.TestHarness;
|
||||
import gnu.testlet.Testlet;
|
||||
|
||||
public class TestNokiaSASrvRegServer implements Testlet {
|
||||
LocalMessageProtocolConnection client;
|
||||
static final String PROTO_NAME = "nokia.sa.service-registry";
|
||||
|
||||
public void testProtocolVersion(TestHarness th) throws IOException {
|
||||
DataEncoder dataEncoder = new DataEncoder("Conv-BEB");
|
||||
dataEncoder.putStart(14, "event");
|
||||
dataEncoder.put(13, "name", "Common");
|
||||
dataEncoder.putStart(14, "message");
|
||||
dataEncoder.put(13, "name", "ProtocolVersion");
|
||||
dataEncoder.put(10, "version", "2.0");
|
||||
dataEncoder.putEnd(14, "message");
|
||||
dataEncoder.putEnd(14, "event");
|
||||
byte[] sendData = dataEncoder.getData();
|
||||
client.send(sendData, 0, sendData.length);
|
||||
|
||||
LocalMessageProtocolMessage msg = client.newMessage(null);
|
||||
client.receive(msg);
|
||||
byte[] clientData = msg.getData();
|
||||
|
||||
DataDecoder dataDecoder = new DataDecoder("Conv-BEB", clientData, 0, clientData.length);
|
||||
dataDecoder.getStart(14);
|
||||
String name = dataDecoder.getString(13);
|
||||
th.check(name, "Common");
|
||||
th.check(dataDecoder.getName(), "message");
|
||||
dataDecoder.getStart(14);
|
||||
String string2 = dataDecoder.getString(13);
|
||||
String string = string2 + ":" + dataDecoder.getString(10);
|
||||
dataDecoder.getEnd(14);
|
||||
th.check(string.startsWith("ProtocolVersion:"));
|
||||
th.check(string.indexOf(58) + 1 != -1);
|
||||
th.check(string.substring(string.indexOf(58) + 1).length() > 0);
|
||||
}
|
||||
|
||||
public void testSubscribeMessages(TestHarness th) throws IOException {
|
||||
DataEncoder dataEncoder = new DataEncoder("Conv-BEB");
|
||||
dataEncoder.putStart(14, "event");
|
||||
dataEncoder.put(13, "name", "Discovery");
|
||||
dataEncoder.put(2, "discovery_id", 2);
|
||||
dataEncoder.put(0, "notify_support", false);
|
||||
dataEncoder.putStart(15, "service_filter");
|
||||
dataEncoder.put(10, "service", "file_ui");
|
||||
dataEncoder.putEnd(15, "service_filter");
|
||||
dataEncoder.putEnd(14, "event");
|
||||
byte[] sendData = dataEncoder.getData();
|
||||
client.send(sendData, 0, sendData.length);
|
||||
|
||||
LocalMessageProtocolMessage msg = client.newMessage(null);
|
||||
client.receive(msg);
|
||||
byte[] clientData = msg.getData();
|
||||
|
||||
DataDecoder dataDecoder = new DataDecoder("Conv-BEB", clientData, 0, clientData.length);
|
||||
dataDecoder.getStart(14);
|
||||
dataDecoder.getString(13);
|
||||
dataDecoder.getInteger(2);
|
||||
dataDecoder.getString(10);
|
||||
dataDecoder.getStart(16);
|
||||
int i = 0;
|
||||
while (i == 0) {
|
||||
try {
|
||||
dataDecoder.getStart(14);
|
||||
th.check(dataDecoder.getString(10), "file_ui");
|
||||
th.check(dataDecoder.getString(12), "nokia.file-ui");
|
||||
dataDecoder.getString(10);
|
||||
dataDecoder.getString(11);
|
||||
dataDecoder.getString(10);
|
||||
dataDecoder.getByteArray();
|
||||
dataDecoder.getEnd(14);
|
||||
} catch (IOException ioe) {
|
||||
i = 1;
|
||||
dataDecoder.getEnd(16);
|
||||
}
|
||||
}
|
||||
|
||||
dataDecoder.getEnd(14);
|
||||
}
|
||||
|
||||
public void test(TestHarness th) {
|
||||
try {
|
||||
client = (LocalMessageProtocolConnection)Connector.open("localmsg://" + PROTO_NAME);
|
||||
|
||||
testProtocolVersion(th);
|
||||
testSubscribeMessages(th);
|
||||
|
||||
client.close();
|
||||
} catch (IOException ioe) {
|
||||
th.fail("Unexpected exception");
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче