Merge pull request #3272 from abstractj/KEYCLOAK-3638
KEYCLOAK-3638: UnixUserTest will fails on Windows
This commit is contained in:
commit
7d038e72c9
26 changed files with 0 additions and 3204 deletions
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Java Unix Sockets Library
|
||||
*
|
||||
* Copyright (c) Matthew Johnson 2005
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* To Contact the author, please email src@matthew.ath.cx
|
||||
*
|
||||
*/
|
||||
|
||||
package cx.ath.matthew.unix;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class testclient {
|
||||
public static void main(String args[]) throws IOException {
|
||||
UnixSocket s = new UnixSocket(new UnixSocketAddress("testsock", true));
|
||||
OutputStream os = s.getOutputStream();
|
||||
PrintWriter o = new PrintWriter(os);
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
|
||||
String l;
|
||||
while (null != (l = r.readLine())) {
|
||||
byte[] buf = (l + "\n").getBytes();
|
||||
os.write(buf, 0, buf.length);
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public final class ProfileStruct extends Struct {
|
||||
@Position(0)
|
||||
public final String a;
|
||||
@Position(1)
|
||||
public final UInt32 b;
|
||||
@Position(2)
|
||||
public final long c;
|
||||
|
||||
public ProfileStruct(String a, UInt32 b, long c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Profiler extends DBusInterface {
|
||||
public class ProfileSignal extends DBusSignal {
|
||||
public ProfileSignal(String path) throws DBusException {
|
||||
super(path);
|
||||
}
|
||||
}
|
||||
|
||||
public void array(int[] v);
|
||||
|
||||
public void stringarray(String[] v);
|
||||
|
||||
public void map(Map<String, String> m);
|
||||
|
||||
public void list(List<String> l);
|
||||
|
||||
public void bytes(byte[] b);
|
||||
|
||||
public void struct(ProfileStruct ps);
|
||||
|
||||
public void string(String s);
|
||||
|
||||
public void NoReply();
|
||||
|
||||
public void Pong();
|
||||
}
|
||||
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProfilerInstance implements Profiler {
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void array(int[] v) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void stringarray(String[] v) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void map(Map<String, String> m) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void list(List<String> l) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void bytes(byte[] b) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void struct(ProfileStruct ps) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void string(String s) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void NoReply() {
|
||||
return;
|
||||
}
|
||||
|
||||
public void Pong() {
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
|
||||
@Description("A test exception to throw over DBus")
|
||||
@SuppressWarnings("serial")
|
||||
public class TestException extends DBusExecutionException {
|
||||
public TestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
|
||||
/**
|
||||
* A sample remote interface which exports one method.
|
||||
*/
|
||||
public interface TestNewInterface extends DBusInterface {
|
||||
/**
|
||||
* A simple method with no parameters which returns a String
|
||||
*/
|
||||
@Description("Simple test method")
|
||||
public String getName();
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
import org.freedesktop.DBus.Method;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A sample remote interface which exports one method.
|
||||
*/
|
||||
public interface TestRemoteInterface extends DBusInterface {
|
||||
/**
|
||||
* A simple method with no parameters which returns a String
|
||||
*/
|
||||
@Description("Simple test method")
|
||||
public String getName();
|
||||
|
||||
public String getNameAndThrow();
|
||||
|
||||
@Description("Test of nested maps")
|
||||
public <T> int frobnicate(List<Long> n, Map<String, Map<UInt16, Short>> m, T v);
|
||||
|
||||
@Description("Throws a TestException when called")
|
||||
public void throwme() throws TestException;
|
||||
|
||||
@Description("Waits then doesn't return")
|
||||
@Method.NoReply()
|
||||
public void waitawhile();
|
||||
|
||||
@Description("Interface-overloaded method")
|
||||
public int overload();
|
||||
|
||||
@Description("Testing Type Signatures")
|
||||
public void sig(Type[] s);
|
||||
|
||||
@Description("Testing object paths as Path objects")
|
||||
public void newpathtest(Path p);
|
||||
|
||||
@Description("Testing the float type")
|
||||
public float testfloat(float[] f);
|
||||
|
||||
@Description("Testing structs of structs")
|
||||
public int[][] teststructstruct(TestStruct3 in);
|
||||
|
||||
@Description("Regression test for #13291")
|
||||
public void reg13291(byte[] as, byte[] bs);
|
||||
|
||||
public Map<String, Variant> svm();
|
||||
|
||||
/* test lots of things involving Path */
|
||||
public Path pathrv(Path a);
|
||||
|
||||
public List<Path> pathlistrv(List<Path> a);
|
||||
|
||||
public Map<Path, Path> pathmaprv(Map<Path, Path> a);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Description("An example remote interface")
|
||||
@DBusInterfaceName("org.freedesktop.dbus.test.AlternateTestInterface")
|
||||
public interface TestRemoteInterface2 extends DBusInterface {
|
||||
@Description("Test multiple return values and implicit variant parameters.")
|
||||
public <A> TestTuple<String, List<Integer>, Boolean> show(A in);
|
||||
|
||||
@Description("Test passing structs and explicit variants, returning implicit variants")
|
||||
public <T> T dostuff(TestStruct foo);
|
||||
|
||||
@Description("Test arrays, boxed arrays and lists.")
|
||||
public List<Integer> sampleArray(List<String> l, Integer[] is, long[] ls);
|
||||
|
||||
@Description("Test passing objects as object paths.")
|
||||
public DBusInterface getThis(DBusInterface t);
|
||||
|
||||
@Description("Test bools work")
|
||||
@DBusMemberName("checkbool")
|
||||
public boolean check();
|
||||
|
||||
@Description("Test Serializable Object")
|
||||
public TestSerializable<String> testSerializable(byte b, TestSerializable<String> s, int i);
|
||||
|
||||
@Description("Call another method on itself from within a call")
|
||||
public String recursionTest();
|
||||
|
||||
@Description("Parameter-overloaded method (string)")
|
||||
public int overload(String s);
|
||||
|
||||
@Description("Parameter-overloaded method (byte)")
|
||||
public int overload(byte b);
|
||||
|
||||
@Description("Parameter-overloaded method (void)")
|
||||
public int overload();
|
||||
|
||||
@Description("Nested List Check")
|
||||
public List<List<Integer>> checklist(List<List<Integer>> lli);
|
||||
|
||||
@Description("Get new objects as object paths.")
|
||||
public TestNewInterface getNew();
|
||||
|
||||
@Description("Test Complex Variants")
|
||||
public void complexv(Variant<? extends Object> v);
|
||||
|
||||
@Description("Test Introspect on a different interface")
|
||||
public String Introspect();
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class TestSerializable<A> implements DBusSerializable {
|
||||
private int a;
|
||||
private String b;
|
||||
private Vector<Integer> c;
|
||||
|
||||
public TestSerializable(int a, A b, Vector<Integer> c) {
|
||||
this.a = a;
|
||||
this.b = b.toString();
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public TestSerializable() {
|
||||
}
|
||||
|
||||
public void deserialize(int a, String b, List<Integer> c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = new Vector<Integer>(c);
|
||||
}
|
||||
|
||||
public Object[] serialize() throws DBusException {
|
||||
return new Object[]{a, b, c};
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public Vector<Integer> getVector() {
|
||||
return c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "TestSerializable{" + a + "," + b + "," + c + "}";
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A sample signal with two parameters
|
||||
*/
|
||||
@Description("Test interface containing signals")
|
||||
public interface TestSignalInterface extends DBusInterface {
|
||||
@Description("Test basic signal")
|
||||
public static class TestSignal extends DBusSignal {
|
||||
public final String value;
|
||||
public final UInt32 number;
|
||||
|
||||
/**
|
||||
* Create a signal.
|
||||
*/
|
||||
public TestSignal(String path, String value, UInt32 number) throws DBusException {
|
||||
super(path, value, number);
|
||||
this.value = value;
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringSignal extends DBusSignal {
|
||||
public final String aoeu;
|
||||
|
||||
public StringSignal(String path, String aoeu) throws DBusException {
|
||||
super(path, aoeu);
|
||||
this.aoeu = aoeu;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmptySignal extends DBusSignal {
|
||||
public EmptySignal(String path) throws DBusException {
|
||||
super(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Description("Test signal with arrays")
|
||||
public static class TestArraySignal extends DBusSignal {
|
||||
public final List<TestStruct2> v;
|
||||
public final Map<UInt32, TestStruct2> m;
|
||||
|
||||
public TestArraySignal(String path, List<TestStruct2> v, Map<UInt32, TestStruct2> m) throws DBusException {
|
||||
super(path, v, m);
|
||||
this.v = v;
|
||||
this.m = m;
|
||||
}
|
||||
}
|
||||
|
||||
@Description("Test signal sending an object path")
|
||||
@DBusMemberName("TestSignalObject")
|
||||
public static class TestObjectSignal extends DBusSignal {
|
||||
public final DBusInterface otherpath;
|
||||
|
||||
public TestObjectSignal(String path, DBusInterface otherpath) throws DBusException {
|
||||
super(path, otherpath);
|
||||
this.otherpath = otherpath;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPathSignal extends DBusSignal {
|
||||
public final Path otherpath;
|
||||
public final List<Path> pathlist;
|
||||
public final Map<Path, Path> pathmap;
|
||||
|
||||
public TestPathSignal(String path, Path otherpath, List<Path> pathlist, Map<Path, Path> pathmap) throws DBusException {
|
||||
super(path, otherpath, pathlist, pathmap);
|
||||
this.otherpath = otherpath;
|
||||
this.pathlist = pathlist;
|
||||
this.pathmap = pathmap;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Description;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
/**
|
||||
* A sample signal with two parameters
|
||||
*/
|
||||
@Description("Test interface containing signals")
|
||||
@DBusInterfaceName("some.other.interface.Name")
|
||||
public interface TestSignalInterface2 extends DBusInterface {
|
||||
@Description("Test basic signal")
|
||||
public static class TestRenamedSignal extends DBusSignal {
|
||||
public final String value;
|
||||
public final UInt32 number;
|
||||
|
||||
/**
|
||||
* Create a signal.
|
||||
*/
|
||||
public TestRenamedSignal(String path, String value, UInt32 number) throws DBusException {
|
||||
super(path, value, number);
|
||||
this.value = value;
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public final class TestStruct extends Struct {
|
||||
@Position(0)
|
||||
public final String a;
|
||||
@Position(1)
|
||||
public final UInt32 b;
|
||||
@Position(2)
|
||||
public final Variant<? extends Object> c;
|
||||
|
||||
public TestStruct(String a, UInt32 b, Variant<? extends Object> c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class TestStruct2 extends Struct {
|
||||
@Position(0)
|
||||
public final List<String> a;
|
||||
@Position(1)
|
||||
public final Variant<? extends Object> b;
|
||||
|
||||
public TestStruct2(List<String> a, Variant<? extends Object> b) throws DBusException {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class TestStruct3 extends Struct {
|
||||
@Position(0)
|
||||
public final TestStruct2 a;
|
||||
@Position(1)
|
||||
public final List<List<Integer>> b;
|
||||
|
||||
public TestStruct3(TestStruct2 a, List<List<Integer>> b) throws DBusException {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public final class TestTuple<A, B, C> extends Tuple {
|
||||
@Position(0)
|
||||
public final A a;
|
||||
@Position(1)
|
||||
public final B b;
|
||||
@Position(2)
|
||||
public final C c;
|
||||
|
||||
public TestTuple(A a, B b, C c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
||||
public interface TwoPartInterface extends DBusInterface {
|
||||
public TwoPartObject getNew();
|
||||
|
||||
public class TwoPartSignal extends DBusSignal {
|
||||
public final TwoPartObject o;
|
||||
|
||||
public TwoPartSignal(String path, TwoPartObject o) throws DBusException {
|
||||
super(path, o);
|
||||
this.o = o;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public interface TwoPartObject extends DBusInterface {
|
||||
public String getName();
|
||||
}
|
|
@ -1,511 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import cx.ath.matthew.debug.Debug;
|
||||
import org.freedesktop.DBus;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.freedesktop.dbus.types.DBusMapType;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
public class cross_test_client implements DBus.Binding.TestClient, DBusSigHandler<DBus.Binding.TestSignals.Triggered> {
|
||||
private DBusConnection conn;
|
||||
private static Set<String> passed = new TreeSet<String>();
|
||||
private static Map<String, List<String>> failed = new HashMap<String, List<String>>();
|
||||
private static cross_test_client ctc;
|
||||
|
||||
static {
|
||||
List<String> l = new Vector<String>();
|
||||
l.add("Signal never arrived");
|
||||
failed.put("org.freedesktop.DBus.Binding.TestSignals.Triggered", l);
|
||||
l = new Vector<String>();
|
||||
l.add("Method never called");
|
||||
failed.put("org.freedesktop.DBus.Binding.TestClient.Response", l);
|
||||
}
|
||||
|
||||
public cross_test_client(DBusConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handle(DBus.Binding.TestSignals.Triggered t) {
|
||||
failed.remove("org.freedesktop.DBus.Binding.TestSignals.Triggered");
|
||||
if (new UInt64(21389479283L).equals(t.a) && "/Test".equals(t.getPath()))
|
||||
pass("org.freedesktop.DBus.Binding.TestSignals.Triggered");
|
||||
else if (!new UInt64(21389479283L).equals(t.a))
|
||||
fail("org.freedesktop.DBus.Binding.TestSignals.Triggered", "Incorrect signal content; expected 21389479283 got " + t.a);
|
||||
else if (!"/Test".equals(t.getPath()))
|
||||
fail("org.freedesktop.DBus.Binding.TestSignals.Triggered", "Incorrect signal source object; expected /Test got " + t.getPath());
|
||||
}
|
||||
|
||||
public void Response(UInt16 a, double b) {
|
||||
failed.remove("org.freedesktop.DBus.Binding.TestClient.Response");
|
||||
if (a.equals(new UInt16(15)) && (b == 12.5))
|
||||
pass("org.freedesktop.DBus.Binding.TestClient.Response");
|
||||
else
|
||||
fail("org.freedesktop.DBus.Binding.TestClient.Response", "Incorrect parameters; expected 15, 12.5 got " + a + ", " + b);
|
||||
}
|
||||
|
||||
public static void pass(String test) {
|
||||
passed.add(test.replaceAll("[$]", ""));
|
||||
}
|
||||
|
||||
public static void fail(String test, String reason) {
|
||||
test = test.replaceAll("[$]", "");
|
||||
List<String> reasons = failed.get(test);
|
||||
if (null == reasons) {
|
||||
reasons = new Vector<String>();
|
||||
failed.put(test, reasons);
|
||||
}
|
||||
reasons.add(reason);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void test(Class<? extends DBusInterface> iface, Object proxy, String method, Object rv, Object... parameters) {
|
||||
try {
|
||||
Method[] ms = iface.getMethods();
|
||||
Method m = null;
|
||||
for (Method t : ms) {
|
||||
if (t.getName().equals(method))
|
||||
m = t;
|
||||
}
|
||||
Object o = m.invoke(proxy, parameters);
|
||||
|
||||
String msg = "Incorrect return value; sent ( ";
|
||||
if (null != parameters)
|
||||
for (Object po : parameters)
|
||||
if (null != po)
|
||||
msg += collapseArray(po) + ",";
|
||||
msg = msg.replaceAll(".$", ");");
|
||||
msg += " expected " + collapseArray(rv) + " got " + collapseArray(o);
|
||||
|
||||
if (null != rv && rv.getClass().isArray()) {
|
||||
compareArray(iface.getName() + "" + method, rv, o);
|
||||
} else if (rv instanceof Map) {
|
||||
if (o instanceof Map) {
|
||||
Map<Object, Object> a = (Map<Object, Object>) o;
|
||||
Map<Object, Object> b = (Map<Object, Object>) rv;
|
||||
if (a.keySet().size() != b.keySet().size()) {
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
} else for (Object k : a.keySet())
|
||||
if (a.get(k) instanceof List) {
|
||||
if (b.get(k) instanceof List)
|
||||
if (setCompareLists((List<Object>) a.get(k), (List<Object>) b.get(k)))
|
||||
;
|
||||
else
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
else
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
} else if (!a.get(k).equals(b.get(k))) {
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
return;
|
||||
}
|
||||
pass(iface.getName() + "" + method);
|
||||
} else
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
} else {
|
||||
if (o == rv || (o != null && o.equals(rv)))
|
||||
pass(iface.getName() + "" + method);
|
||||
else
|
||||
fail(iface.getName() + "" + method, msg);
|
||||
}
|
||||
} catch (DBusExecutionException DBEe) {
|
||||
DBEe.printStackTrace();
|
||||
fail(iface.getName() + "" + method, "Error occurred during execution: " + DBEe.getClass().getName() + " " + DBEe.getMessage());
|
||||
} catch (InvocationTargetException ITe) {
|
||||
ITe.printStackTrace();
|
||||
fail(iface.getName() + "" + method, "Error occurred during execution: " + ITe.getCause().getClass().getName() + " " + ITe.getCause().getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(iface.getName() + "" + method, "Error occurred during execution: " + e.getClass().getName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String collapseArray(Object array) {
|
||||
if (null == array) return "null";
|
||||
if (array.getClass().isArray()) {
|
||||
String s = "{ ";
|
||||
for (int i = 0; i < Array.getLength(array); i++)
|
||||
s += collapseArray(Array.get(array, i)) + ",";
|
||||
s = s.replaceAll(".$", " }");
|
||||
return s;
|
||||
} else if (array instanceof List) {
|
||||
String s = "{ ";
|
||||
for (Object o : (List<Object>) array)
|
||||
s += collapseArray(o) + ",";
|
||||
s = s.replaceAll(".$", " }");
|
||||
return s;
|
||||
} else if (array instanceof Map) {
|
||||
String s = "{ ";
|
||||
for (Object o : ((Map<Object, Object>) array).keySet())
|
||||
s += collapseArray(o) + " => " + collapseArray(((Map<Object, Object>) array).get(o)) + ",";
|
||||
s = s.replaceAll(".$", " }");
|
||||
return s;
|
||||
} else return array.toString();
|
||||
}
|
||||
|
||||
public static <T> boolean setCompareLists(List<T> a, List<T> b) {
|
||||
if (a.size() != b.size()) return false;
|
||||
for (Object v : a)
|
||||
if (!b.contains(v)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Variant<Object>> PrimitizeRecurse(Object a, Type t) {
|
||||
List<Variant<Object>> vs = new Vector<Variant<Object>>();
|
||||
if (t instanceof ParameterizedType) {
|
||||
Class<Object> c = (Class<Object>) ((ParameterizedType) t).getRawType();
|
||||
if (List.class.isAssignableFrom(c)) {
|
||||
Object os;
|
||||
if (a instanceof List)
|
||||
os = ((List<Object>) a).toArray();
|
||||
else
|
||||
os = a;
|
||||
Type[] ts = ((ParameterizedType) t).getActualTypeArguments();
|
||||
for (int i = 0; i < Array.getLength(os); i++)
|
||||
vs.addAll(PrimitizeRecurse(Array.get(os, i), ts[0]));
|
||||
} else if (Map.class.isAssignableFrom(c)) {
|
||||
Object[] os = ((Map) a).keySet().toArray();
|
||||
Object[] ks = ((Map) a).values().toArray();
|
||||
Type[] ts = ((ParameterizedType) t).getActualTypeArguments();
|
||||
for (int i = 0; i < ks.length; i++)
|
||||
vs.addAll(PrimitizeRecurse(ks[i], ts[0]));
|
||||
for (int i = 0; i < os.length; i++)
|
||||
vs.addAll(PrimitizeRecurse(os[i], ts[1]));
|
||||
} else if (Struct.class.isAssignableFrom(c)) {
|
||||
Object[] os = ((Struct) a).getParameters();
|
||||
Type[] ts = ((ParameterizedType) t).getActualTypeArguments();
|
||||
for (int i = 0; i < os.length; i++)
|
||||
vs.addAll(PrimitizeRecurse(os[i], ts[i]));
|
||||
|
||||
} else if (Variant.class.isAssignableFrom(c)) {
|
||||
vs.addAll(PrimitizeRecurse(((Variant) a).getValue(), ((Variant) a).getType()));
|
||||
}
|
||||
} else if (Variant.class.isAssignableFrom((Class) t))
|
||||
vs.addAll(PrimitizeRecurse(((Variant) a).getValue(), ((Variant) a).getType()));
|
||||
else if (t instanceof Class && ((Class) t).isArray()) {
|
||||
Type t2 = ((Class) t).getComponentType();
|
||||
for (int i = 0; i < Array.getLength(a); i++)
|
||||
vs.addAll(PrimitizeRecurse(Array.get(a, i), t2));
|
||||
} else vs.add(new Variant(a));
|
||||
|
||||
return vs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Variant<Object>> Primitize(Variant<Object> a) {
|
||||
return PrimitizeRecurse(a.getValue(), a.getType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void primitizeTest(DBus.Binding.Tests tests, Object input) {
|
||||
Variant<Object> in = new Variant<Object>(input);
|
||||
List<Variant<Object>> vs = Primitize(in);
|
||||
List<Variant<Object>> res;
|
||||
|
||||
try {
|
||||
|
||||
res = tests.Primitize(in);
|
||||
if (setCompareLists(res, vs))
|
||||
pass("org.freedesktop.DBus.Binding.Tests.Primitize");
|
||||
else
|
||||
fail("org.freedesktop.DBus.Binding.Tests.Primitize", "Wrong Return Value; expected " + collapseArray(vs) + " got " + collapseArray(res));
|
||||
|
||||
} catch (Exception e) {
|
||||
if (Debug.debug) Debug.print(e);
|
||||
fail("org.freedesktop.DBus.Binding.Tests.Primitize", "Exception occurred during test: (" + e.getClass().getName() + ") " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void doTests(DBus.Peer peer, DBus.Introspectable intro, DBus.Introspectable rootintro, DBus.Binding.Tests tests, DBus.Binding.SingleTests singletests) {
|
||||
Random r = new Random();
|
||||
int i;
|
||||
test(DBus.Peer.class, peer, "Ping", null);
|
||||
|
||||
try {
|
||||
if (intro.Introspect().startsWith("<!DOCTYPE")) pass("org.freedesktop.DBus.Introspectable.Introspect");
|
||||
else
|
||||
fail("org.freedesktop.DBus.Introspectable.Introspect", "Didn't get valid xml data back when introspecting /Test");
|
||||
} catch (DBusExecutionException DBEe) {
|
||||
if (Debug.debug) Debug.print(DBEe);
|
||||
fail("org.freedesktop.DBus.Introspectable.Introspect", "Got exception during introspection on /Test (" + DBEe.getClass().getName() + "): " + DBEe.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
if (rootintro.Introspect().startsWith("<!DOCTYPE")) pass("org.freedesktop.DBus.Introspectable.Introspect");
|
||||
else
|
||||
fail("org.freedesktop.DBus.Introspectable.Introspect", "Didn't get valid xml data back when introspecting /");
|
||||
} catch (DBusExecutionException DBEe) {
|
||||
if (Debug.debug) Debug.print(DBEe);
|
||||
fail("org.freedesktop.DBus.Introspectable.Introspect", "Got exception during introspection on / (" + DBEe.getClass().getName() + "): " + DBEe.getMessage());
|
||||
}
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "Identity", new Variant<Integer>(new Integer(1)), new Variant<Integer>(new Integer(1)));
|
||||
test(DBus.Binding.Tests.class, tests, "Identity", new Variant<String>("Hello"), new Variant<String>("Hello"));
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityBool", false, false);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityBool", true, true);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "Invert", false, true);
|
||||
test(DBus.Binding.Tests.class, tests, "Invert", true, false);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) 0, (byte) 0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) 1, (byte) 1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) -1, (byte) -1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", Byte.MAX_VALUE, Byte.MAX_VALUE);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", Byte.MIN_VALUE, Byte.MIN_VALUE);
|
||||
i = r.nextInt();
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) i, (byte) i);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) 0, (short) 0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) 1, (short) 1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) -1, (short) -1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", Short.MAX_VALUE, Short.MAX_VALUE);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", Short.MIN_VALUE, Short.MIN_VALUE);
|
||||
i = r.nextInt();
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) i, (short) i);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", 0, 0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", 1, 1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", -1, -1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
i = r.nextInt();
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt32", i, i);
|
||||
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) 0, (long) 0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) 1, (long) 1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) -1, (long) -1);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", Long.MIN_VALUE, Long.MIN_VALUE);
|
||||
i = r.nextInt();
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) i, (long) i);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(0), new UInt16(0));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(1), new UInt16(1));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(UInt16.MAX_VALUE), new UInt16(UInt16.MAX_VALUE));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(UInt16.MIN_VALUE), new UInt16(UInt16.MIN_VALUE));
|
||||
i = r.nextInt();
|
||||
i = i > 0 ? i : -i;
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(i % UInt16.MAX_VALUE), new UInt16(i % UInt16.MAX_VALUE));
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(0), new UInt32(0));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(1), new UInt32(1));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(UInt32.MAX_VALUE), new UInt32(UInt32.MAX_VALUE));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(UInt32.MIN_VALUE), new UInt32(UInt32.MIN_VALUE));
|
||||
i = r.nextInt();
|
||||
i = i > 0 ? i : -i;
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(i % UInt32.MAX_VALUE), new UInt32(i % UInt32.MAX_VALUE));
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(0), new UInt64(0));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(1), new UInt64(1));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MAX_LONG_VALUE), new UInt64(UInt64.MAX_LONG_VALUE));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MAX_BIG_VALUE), new UInt64(UInt64.MAX_BIG_VALUE));
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MIN_VALUE), new UInt64(UInt64.MIN_VALUE));
|
||||
i = r.nextInt();
|
||||
i = i > 0 ? i : -i;
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(i % UInt64.MAX_LONG_VALUE), new UInt64(i % UInt64.MAX_LONG_VALUE));
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", 0.0, 0.0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", 1.0, 1.0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", -1.0, -1.0);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", Double.MIN_VALUE, Double.MIN_VALUE);
|
||||
i = r.nextInt();
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityDouble", (double) i, (double) i);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityString", "", "");
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityString", "The Quick Brown Fox Jumped Over The Lazy Dog", "The Quick Brown Fox Jumped Over The Lazy Dog");
|
||||
test(DBus.Binding.Tests.class, tests, "IdentityString", "ひらがなゲーム - かなぶん", "ひらがなゲーム - かなぶん");
|
||||
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityBoolArray", Boolean.TYPE, null);
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityByteArray", Byte.TYPE, null);
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityInt16Array", Short.TYPE, null);
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityInt32Array", Integer.TYPE, null);
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityInt64Array", Long.TYPE, null);
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityDoubleArray", Double.TYPE, null);
|
||||
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityArray", Variant.class, new Variant<String>("aoeu"));
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityUInt16Array", UInt16.class, new UInt16(12));
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityUInt32Array", UInt32.class, new UInt32(190));
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityUInt64Array", UInt64.class, new UInt64(103948));
|
||||
testArray(DBus.Binding.Tests.class, tests, "IdentityStringArray", String.class, "asdf");
|
||||
|
||||
int[] is = new int[0];
|
||||
test(DBus.Binding.Tests.class, tests, "Sum", 0L, is);
|
||||
r = new Random();
|
||||
int len = (r.nextInt() % 100) + 15;
|
||||
len = (len < 0 ? -len : len) + 15;
|
||||
is = new int[len];
|
||||
long result = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
is[i] = r.nextInt();
|
||||
result += is[i];
|
||||
}
|
||||
test(DBus.Binding.Tests.class, tests, "Sum", result, is);
|
||||
|
||||
byte[] bs = new byte[0];
|
||||
test(DBus.Binding.SingleTests.class, singletests, "Sum", new UInt32(0), bs);
|
||||
len = (r.nextInt() % 100);
|
||||
len = (len < 0 ? -len : len) + 15;
|
||||
bs = new byte[len];
|
||||
int res = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
bs[i] = (byte) r.nextInt();
|
||||
res += (bs[i] < 0 ? bs[i] + 256 : bs[i]);
|
||||
}
|
||||
test(DBus.Binding.SingleTests.class, singletests, "Sum", new UInt32(res % (UInt32.MAX_VALUE + 1)), bs);
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "DeStruct", new DBus.Binding.Triplet<String, UInt32, Short>("hi", new UInt32(12), new Short((short) 99)), new DBus.Binding.TestStruct("hi", new UInt32(12), new Short((short) 99)));
|
||||
|
||||
Map<String, String> in = new HashMap<String, String>();
|
||||
Map<String, List<String>> out = new HashMap<String, List<String>>();
|
||||
test(DBus.Binding.Tests.class, tests, "InvertMapping", out, in);
|
||||
|
||||
in.put("hi", "there");
|
||||
in.put("to", "there");
|
||||
in.put("from", "here");
|
||||
in.put("in", "out");
|
||||
List<String> l = new Vector<String>();
|
||||
l.add("hi");
|
||||
l.add("to");
|
||||
out.put("there", l);
|
||||
l = new Vector<String>();
|
||||
l.add("from");
|
||||
out.put("here", l);
|
||||
l = new Vector<String>();
|
||||
l.add("in");
|
||||
out.put("out", l);
|
||||
test(DBus.Binding.Tests.class, tests, "InvertMapping", out, in);
|
||||
|
||||
primitizeTest(tests, new Integer(1));
|
||||
primitizeTest(tests,
|
||||
new Variant<Variant<Variant<Variant<String>>>>(
|
||||
new Variant<Variant<Variant<String>>>(
|
||||
new Variant<Variant<String>>(
|
||||
new Variant<String>("Hi")))));
|
||||
primitizeTest(tests, new Variant<Map<String, String>>(in, new DBusMapType(String.class, String.class)));
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "Trigger", null, "/Test", new UInt64(21389479283L));
|
||||
|
||||
try {
|
||||
ctc.conn.sendSignal(new DBus.Binding.TestClient.Trigger("/Test", new UInt16(15), 12.5));
|
||||
} catch (DBusException DBe) {
|
||||
if (Debug.debug) Debug.print(DBe);
|
||||
throw new DBusExecutionException(DBe.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
|
||||
test(DBus.Binding.Tests.class, tests, "Exit", null);
|
||||
}
|
||||
|
||||
public static void testArray(Class<? extends DBusInterface> iface, Object proxy, String method, Class<? extends Object> arrayType, Object content) {
|
||||
Object array = Array.newInstance(arrayType, 0);
|
||||
test(iface, proxy, method, array, array);
|
||||
Random r = new Random();
|
||||
int l = (r.nextInt() % 100);
|
||||
array = Array.newInstance(arrayType, (l < 0 ? -l : l) + 15);
|
||||
if (null != content)
|
||||
Arrays.fill((Object[]) array, content);
|
||||
test(iface, proxy, method, array, array);
|
||||
}
|
||||
|
||||
public static void compareArray(String test, Object a, Object b) {
|
||||
if (!a.getClass().equals(b.getClass())) {
|
||||
fail(test, "Incorrect return type; expected " + a.getClass() + " got " + b.getClass());
|
||||
return;
|
||||
}
|
||||
boolean pass = false;
|
||||
|
||||
if (a instanceof Object[])
|
||||
pass = Arrays.equals((Object[]) a, (Object[]) b);
|
||||
else if (a instanceof byte[])
|
||||
pass = Arrays.equals((byte[]) a, (byte[]) b);
|
||||
else if (a instanceof boolean[])
|
||||
pass = Arrays.equals((boolean[]) a, (boolean[]) b);
|
||||
else if (a instanceof int[])
|
||||
pass = Arrays.equals((int[]) a, (int[]) b);
|
||||
else if (a instanceof short[])
|
||||
pass = Arrays.equals((short[]) a, (short[]) b);
|
||||
else if (a instanceof long[])
|
||||
pass = Arrays.equals((long[]) a, (long[]) b);
|
||||
else if (a instanceof double[])
|
||||
pass = Arrays.equals((double[]) a, (double[]) b);
|
||||
|
||||
if (pass)
|
||||
pass(test);
|
||||
else {
|
||||
String s = "Incorrect return value; expected ";
|
||||
s += collapseArray(a);
|
||||
s += " got ";
|
||||
s += collapseArray(b);
|
||||
fail(test, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
/* init */
|
||||
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
ctc = new cross_test_client(conn);
|
||||
conn.exportObject("/Test", ctc);
|
||||
conn.addSigHandler(DBus.Binding.TestSignals.Triggered.class, ctc);
|
||||
DBus.Binding.Tests tests = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Binding.Tests.class);
|
||||
DBus.Binding.SingleTests singletests = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Binding.SingleTests.class);
|
||||
DBus.Peer peer = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Peer.class);
|
||||
DBus.Introspectable intro = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Introspectable.class);
|
||||
|
||||
DBus.Introspectable rootintro = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/", DBus.Introspectable.class);
|
||||
|
||||
doTests(peer, intro, rootintro, tests, singletests);
|
||||
|
||||
/* report results */
|
||||
for (String s : passed)
|
||||
System.out.println(s + " pass");
|
||||
int i = 1;
|
||||
for (String s : failed.keySet())
|
||||
for (String r : failed.get(s)) {
|
||||
System.out.println(s + " fail " + i);
|
||||
System.out.println("report " + i + ": " + r);
|
||||
i++;
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
} catch (DBusException DBe) {
|
||||
DBe.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,342 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
public class cross_test_server implements DBus.Binding.Tests, DBus.Binding.SingleTests, DBusSigHandler<DBus.Binding.TestClient.Trigger> {
|
||||
private DBusConnection conn;
|
||||
boolean run = true;
|
||||
private Set<String> done = new TreeSet<String>();
|
||||
private Set<String> notdone = new TreeSet<String>();
|
||||
|
||||
{
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Identity");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByte");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBool");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityString");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityArray");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Sum");
|
||||
notdone.add("org.freedesktop.DBus.Binding.SingleTests.Sum");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.InvertMapping");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.DeStruct");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Primitize");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Invert");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Trigger");
|
||||
notdone.add("org.freedesktop.DBus.Binding.Tests.Exit");
|
||||
notdone.add("org.freedesktop.DBus.Binding.TestClient.Trigger");
|
||||
}
|
||||
|
||||
public cross_test_server(DBusConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public <T> Variant<T> Identity(Variant<T> input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Identity");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Identity");
|
||||
return new Variant(input.getValue());
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public byte IdentityByte(byte input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityByte");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByte");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public boolean IdentityBool(boolean input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityBool");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBool");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public short IdentityInt16(short input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt16 IdentityUInt16(UInt16 input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public int IdentityInt32(int input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt32 IdentityUInt32(UInt32 input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public long IdentityInt64(long input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt64 IdentityUInt64(UInt64 input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public double IdentityDouble(double input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public String IdentityString(String input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityString");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityString");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public <T> Variant<T>[] IdentityArray(Variant<T>[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityArray");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityArray");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public byte[] IdentityByteArray(byte[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public boolean[] IdentityBoolArray(boolean[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public short[] IdentityInt16Array(short[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt16[] IdentityUInt16Array(UInt16[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public int[] IdentityInt32Array(int[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt32[] IdentityUInt32Array(UInt32[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public long[] IdentityInt64Array(long[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public UInt64[] IdentityUInt64Array(UInt64[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public double[] IdentityDoubleArray(double[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns whatever it is passed")
|
||||
public String[] IdentityStringArray(String[] input) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
|
||||
return input;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns the sum of the values in the input list")
|
||||
public long Sum(int[] a) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Sum");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Sum");
|
||||
long sum = 0;
|
||||
for (int b : a) sum += b;
|
||||
return sum;
|
||||
}
|
||||
|
||||
@DBus.Description("Returns the sum of the values in the input list")
|
||||
public UInt32 Sum(byte[] a) {
|
||||
done.add("org.freedesktop.DBus.Binding.SingleTests.Sum");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.SingleTests.Sum");
|
||||
int sum = 0;
|
||||
for (byte b : a) sum += (b < 0 ? b + 256 : b);
|
||||
return new UInt32(sum % (UInt32.MAX_VALUE + 1));
|
||||
}
|
||||
|
||||
@DBus.Description("Given a map of A => B, should return a map of B => a list of all the As which mapped to B")
|
||||
public Map<String, List<String>> InvertMapping(Map<String, String> a) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.InvertMapping");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.InvertMapping");
|
||||
HashMap<String, List<String>> m = new HashMap<String, List<String>>();
|
||||
for (String s : a.keySet()) {
|
||||
String b = a.get(s);
|
||||
List<String> l = m.get(b);
|
||||
if (null == l) {
|
||||
l = new Vector<String>();
|
||||
m.put(b, l);
|
||||
}
|
||||
l.add(s);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
@DBus.Description("This method returns the contents of a struct as separate values")
|
||||
public DBus.Binding.Triplet<String, UInt32, Short> DeStruct(DBus.Binding.TestStruct a) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.DeStruct");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.DeStruct");
|
||||
return new DBus.Binding.Triplet<String, UInt32, Short>(a.a, a.b, a.c);
|
||||
}
|
||||
|
||||
@DBus.Description("Given any compound type as a variant, return all the primitive types recursively contained within as an array of variants")
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Variant<Object>> Primitize(Variant<Object> a) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Primitize");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Primitize");
|
||||
return cross_test_client.PrimitizeRecurse(a.getValue(), a.getType());
|
||||
}
|
||||
|
||||
@DBus.Description("inverts it's input")
|
||||
public boolean Invert(boolean a) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Invert");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Invert");
|
||||
return !a;
|
||||
}
|
||||
|
||||
@DBus.Description("triggers sending of a signal from the supplied object with the given parameter")
|
||||
public void Trigger(String a, UInt64 b) {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Trigger");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Trigger");
|
||||
try {
|
||||
conn.sendSignal(new DBus.Binding.TestSignals.Triggered(a, b));
|
||||
} catch (DBusException DBe) {
|
||||
throw new DBusExecutionException(DBe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit() {
|
||||
done.add("org.freedesktop.DBus.Binding.Tests.Exit");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.Tests.Exit");
|
||||
run = false;
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(DBus.Binding.TestClient.Trigger t) {
|
||||
done.add("org.freedesktop.DBus.Binding.TestClient.Trigger");
|
||||
notdone.remove("org.freedesktop.DBus.Binding.TestClient.Trigger");
|
||||
try {
|
||||
DBus.Binding.TestClient cb = conn.getRemoteObject(t.getSource(), "/Test", DBus.Binding.TestClient.class);
|
||||
cb.Response(t.a, t.b);
|
||||
} catch (DBusException DBe) {
|
||||
throw new DBusExecutionException(DBe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
conn.requestBusName("org.freedesktop.DBus.Binding.TestServer");
|
||||
cross_test_server cts = new cross_test_server(conn);
|
||||
conn.addSigHandler(DBus.Binding.TestClient.Trigger.class, cts);
|
||||
conn.exportObject("/Test", cts);
|
||||
synchronized (cts) {
|
||||
while (cts.run) {
|
||||
try {
|
||||
cts.wait();
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String s : cts.done)
|
||||
System.out.println(s + " ok");
|
||||
for (String s : cts.notdone)
|
||||
System.out.println(s + " untested");
|
||||
conn.disconnect();
|
||||
System.exit(0);
|
||||
} catch (DBusException DBe) {
|
||||
DBe.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,378 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus.Introspectable;
|
||||
import org.freedesktop.DBus.Peer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
class ProfileHandler implements DBusSigHandler<Profiler.ProfileSignal> {
|
||||
public int c = 0;
|
||||
|
||||
public void handle(Profiler.ProfileSignal s) {
|
||||
if (0 == (c++ % profile.SIGNAL_INNER)) System.out.print("-");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Profiling tests.
|
||||
*/
|
||||
public class profile {
|
||||
public static final int SIGNAL_INNER = 100;
|
||||
public static final int SIGNAL_OUTER = 100;
|
||||
public static final int PING_INNER = 100;
|
||||
public static final int PING_OUTER = 100;
|
||||
public static final int BYTES = 2000000;
|
||||
public static final int INTROSPECTION_OUTER = 100;
|
||||
public static final int INTROSPECTION_INNER = 10;
|
||||
public static final int STRUCT_OUTER = 100;
|
||||
public static final int STRUCT_INNER = 10;
|
||||
public static final int LIST_OUTER = 100;
|
||||
public static final int LIST_INNER = 10;
|
||||
public static final int LIST_LENGTH = 100;
|
||||
public static final int MAP_OUTER = 100;
|
||||
public static final int MAP_INNER = 10;
|
||||
public static final int MAP_LENGTH = 100;
|
||||
public static final int ARRAY_OUTER = 100;
|
||||
public static final int ARRAY_INNER = 10;
|
||||
public static final int ARRAY_LENGTH = 1000;
|
||||
public static final int STRING_ARRAY_OUTER = 10;
|
||||
public static final int STRING_ARRAY_INNER = 1;
|
||||
public static final int STRING_ARRAY_LENGTH = 20000;
|
||||
|
||||
public static class Log {
|
||||
private long last;
|
||||
private int[] deltas;
|
||||
private int current = 0;
|
||||
|
||||
public Log(int size) {
|
||||
deltas = new int[size];
|
||||
}
|
||||
|
||||
public void start() {
|
||||
last = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
deltas[current] = (int) (System.currentTimeMillis() - last);
|
||||
current++;
|
||||
}
|
||||
|
||||
public double mean() {
|
||||
if (0 == current) return 0;
|
||||
long sum = 0;
|
||||
for (int i = 0; i < current; i++)
|
||||
sum += deltas[i];
|
||||
return sum /= current;
|
||||
}
|
||||
|
||||
public long min() {
|
||||
int m = Integer.MAX_VALUE;
|
||||
for (int i = 0; i < current; i++)
|
||||
if (deltas[i] < m) m = deltas[i];
|
||||
return m;
|
||||
}
|
||||
|
||||
public long max() {
|
||||
int m = 0;
|
||||
for (int i = 0; i < current; i++)
|
||||
if (deltas[i] > m) m = deltas[i];
|
||||
return m;
|
||||
}
|
||||
|
||||
public double stddev() {
|
||||
double mean = mean();
|
||||
double sum = 0;
|
||||
for (int i = 0; i < current; i++)
|
||||
sum += (deltas[i] - mean) * (deltas[i] - mean);
|
||||
return Math.sqrt(sum / (current - 1));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if (0 == args.length) {
|
||||
System.out.println("You must specify a profile type.");
|
||||
System.out.println("Syntax: profile <pings|arrays|introspect|maps|bytes|lists|structs|signals|rate|strings>");
|
||||
System.exit(1);
|
||||
}
|
||||
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
conn.requestBusName("org.freedesktop.DBus.java.profiler");
|
||||
if ("pings".equals(args[0])) {
|
||||
int count = PING_INNER * PING_OUTER;
|
||||
System.out.print("Sending " + count + " pings...");
|
||||
Peer p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Peer.class);
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < PING_OUTER; i++) {
|
||||
for (int j = 0; j < PING_INNER; j++) {
|
||||
l.start();
|
||||
p.Ping();
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("strings".equals(args[0])) {
|
||||
int count = STRING_ARRAY_INNER * STRING_ARRAY_OUTER;
|
||||
System.out.print("Sending array of " + STRING_ARRAY_LENGTH + " strings " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
String[] v = new String[STRING_ARRAY_LENGTH];
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < STRING_ARRAY_LENGTH; i++) v[i] = "" + r.nextInt();
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < STRING_ARRAY_OUTER; i++) {
|
||||
for (int j = 0; j < STRING_ARRAY_INNER; j++) {
|
||||
l.start();
|
||||
p.stringarray(v);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("arrays".equals(args[0])) {
|
||||
int count = ARRAY_INNER * ARRAY_OUTER;
|
||||
System.out.print("Sending array of " + ARRAY_LENGTH + " ints " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
int[] v = new int[ARRAY_LENGTH];
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < ARRAY_LENGTH; i++) v[i] = r.nextInt();
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < ARRAY_OUTER; i++) {
|
||||
for (int j = 0; j < ARRAY_INNER; j++) {
|
||||
l.start();
|
||||
p.array(v);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("maps".equals(args[0])) {
|
||||
int count = MAP_INNER * MAP_OUTER;
|
||||
System.out.print("Sending map of " + MAP_LENGTH + " string=>strings " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
HashMap<String, String> m = new HashMap<String, String>();
|
||||
for (int i = 0; i < MAP_LENGTH; i++)
|
||||
m.put("" + i, "hello");
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < MAP_OUTER; i++) {
|
||||
for (int j = 0; j < MAP_INNER; j++) {
|
||||
l.start();
|
||||
p.map(m);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("lists".equals(args[0])) {
|
||||
int count = LIST_OUTER * LIST_INNER;
|
||||
System.out.print("Sending list of " + LIST_LENGTH + " strings " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
Vector<String> v = new Vector<String>();
|
||||
for (int i = 0; i < LIST_LENGTH; i++)
|
||||
v.add("hello " + i);
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < LIST_OUTER; i++) {
|
||||
for (int j = 0; j < LIST_INNER; j++) {
|
||||
l.start();
|
||||
p.list(v);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("structs".equals(args[0])) {
|
||||
int count = STRUCT_OUTER * STRUCT_INNER;
|
||||
System.out.print("Sending a struct " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
ProfileStruct ps = new ProfileStruct("hello", new UInt32(18), 500L);
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < STRUCT_OUTER; i++) {
|
||||
for (int j = 0; j < STRUCT_INNER; j++) {
|
||||
l.start();
|
||||
p.struct(ps);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
} else if ("introspect".equals(args[0])) {
|
||||
int count = INTROSPECTION_OUTER * INTROSPECTION_INNER;
|
||||
System.out.print("Recieving introspection data " + count + " times.");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Introspectable is = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Introspectable.class);
|
||||
Log l = new Log(count);
|
||||
long t = System.currentTimeMillis();
|
||||
String s = null;
|
||||
for (int i = 0; i < INTROSPECTION_OUTER; i++) {
|
||||
for (int j = 0; j < INTROSPECTION_INNER; j++) {
|
||||
l.start();
|
||||
s = is.Introspect();
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
System.out.println("Introspect data: " + s);
|
||||
} else if ("bytes".equals(args[0])) {
|
||||
System.out.print("Sending " + BYTES + " bytes");
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
byte[] bs = new byte[BYTES];
|
||||
for (int i = 0; i < BYTES; i++)
|
||||
bs[i] = (byte) i;
|
||||
long t = System.currentTimeMillis();
|
||||
p.bytes(bs);
|
||||
System.out.println(" done in " + (System.currentTimeMillis() - t) + "ms.");
|
||||
} else if ("rate".equals(args[0])) {
|
||||
ProfilerInstance pi = new ProfilerInstance();
|
||||
conn.exportObject("/Profiler", pi);
|
||||
Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class);
|
||||
Peer peer = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Peer.class);
|
||||
conn.changeThreadCount((byte) 1);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
do {
|
||||
p.Pong();
|
||||
count++;
|
||||
} while (count < 10000);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("No payload: " + ((count * 1000) / (end - start)) + " RT/second");
|
||||
start = System.currentTimeMillis();
|
||||
count = 0;
|
||||
do {
|
||||
p.Pong();
|
||||
count++;
|
||||
} while (count < 10000);
|
||||
peer.Ping();
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("No payload, One way: " + ((count * 1000) / (end - start)) + " /second");
|
||||
int len = 256;
|
||||
while (len <= 32768) {
|
||||
byte[] bs = new byte[len];
|
||||
count = 0;
|
||||
start = System.currentTimeMillis();
|
||||
do {
|
||||
p.bytes(bs);
|
||||
count++;
|
||||
} while (count < 1000);
|
||||
end = System.currentTimeMillis();
|
||||
long ms = end - start;
|
||||
double cps = (count * 1000) / ms;
|
||||
double rate = (len * cps) / (1024.0 * 1024.0);
|
||||
System.out.println(len + " byte array) " + (count * len) + " bytes in " + ms + "ms (in " + count + " calls / " + (int) cps + " CPS): " + rate + "MB/s");
|
||||
len <<= 1;
|
||||
}
|
||||
len = 256;
|
||||
while (len <= 32768) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < len; i++) sb.append('a');
|
||||
String s = sb.toString();
|
||||
end = System.currentTimeMillis() + 500;
|
||||
count = 0;
|
||||
do {
|
||||
p.string(s);
|
||||
count++;
|
||||
} while (count < 1000);
|
||||
long ms = end - start;
|
||||
double cps = (count * 1000) / ms;
|
||||
double rate = (len * cps) / (1024.0 * 1024.0);
|
||||
System.out.println(len + " string) " + (count * len) + " bytes in " + ms + "ms (in " + count + " calls / " + (int) cps + " CPS): " + rate + "MB/s");
|
||||
len <<= 1;
|
||||
}
|
||||
} else if ("signals".equals(args[0])) {
|
||||
int count = SIGNAL_OUTER * SIGNAL_INNER;
|
||||
System.out.print("Sending " + count + " signals");
|
||||
ProfileHandler ph = new ProfileHandler();
|
||||
conn.addSigHandler(Profiler.ProfileSignal.class, ph);
|
||||
Log l = new Log(count);
|
||||
Profiler.ProfileSignal ps = new Profiler.ProfileSignal("/");
|
||||
long t = System.currentTimeMillis();
|
||||
for (int i = 0; i < SIGNAL_OUTER; i++) {
|
||||
for (int j = 0; j < SIGNAL_INNER; j++) {
|
||||
l.start();
|
||||
conn.sendSignal(ps);
|
||||
l.stop();
|
||||
}
|
||||
System.out.print("");
|
||||
}
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(" done.");
|
||||
System.out.println("min/max/avg (ms): " + l.min() + "/" + l.max() + "/" + l.mean());
|
||||
System.out.println("deviation: " + l.stddev());
|
||||
System.out.println("Total time: " + t + "ms");
|
||||
while (ph.c < count) try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
;
|
||||
} else {
|
||||
conn.disconnect();
|
||||
System.out.println("Invalid profile ``" + args[0] + "''.");
|
||||
System.out.println("Syntax: profile <pings|arrays|introspect|maps|bytes|lists|structs|signals>");
|
||||
System.exit(1);
|
||||
}
|
||||
conn.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,991 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import org.freedesktop.DBus;
|
||||
import org.freedesktop.DBus.Error.MatchRuleInvalid;
|
||||
import org.freedesktop.DBus.Error.ServiceUnknown;
|
||||
import org.freedesktop.DBus.Error.UnknownObject;
|
||||
import org.freedesktop.DBus.Introspectable;
|
||||
import org.freedesktop.DBus.Peer;
|
||||
import org.freedesktop.DBus.Properties;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.freedesktop.dbus.exceptions.NotConnected;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.Collator;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
class testnewclass implements TestNewInterface {
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface, TestSignalInterface2, Properties {
|
||||
private DBusConnection conn;
|
||||
|
||||
public testclass(DBusConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public String Introspect() {
|
||||
return "Not XML";
|
||||
}
|
||||
|
||||
public int[][] teststructstruct(TestStruct3 in) {
|
||||
List<List<Integer>> lli = in.b;
|
||||
int[][] out = new int[lli.size()][];
|
||||
for (int j = 0; j < out.length; j++) {
|
||||
out[j] = new int[lli.get(j).size()];
|
||||
for (int k = 0; k < out[j].length; k++)
|
||||
out[j][k] = lli.get(j).get(k);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public float testfloat(float[] f) {
|
||||
if (f.length < 4 ||
|
||||
f[0] != 17.093f ||
|
||||
f[1] != -23f ||
|
||||
f[2] != 0.0f ||
|
||||
f[3] != 31.42f)
|
||||
test.fail("testfloat got incorrect array");
|
||||
return f[0];
|
||||
}
|
||||
|
||||
public void newpathtest(Path p) {
|
||||
if (!p.toString().equals("/new/path/test"))
|
||||
test.fail("new path test got wrong path");
|
||||
}
|
||||
|
||||
public void waitawhile() {
|
||||
System.out.println("Sleeping.");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
System.out.println("Done sleeping.");
|
||||
}
|
||||
|
||||
public <A> TestTuple<String, List<Integer>, Boolean> show(A in) {
|
||||
System.out.println("Showing Stuff: " + in.getClass() + "(" + in + ")");
|
||||
if (!(in instanceof Integer) || ((Integer) in).intValue() != 234)
|
||||
test.fail("show received the wrong arguments");
|
||||
DBusCallInfo info = DBusConnection.getCallInfo();
|
||||
List<Integer> l = new Vector<Integer>();
|
||||
l.add(1953);
|
||||
return new TestTuple<String, List<Integer>, Boolean>(info.getSource(), l, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T dostuff(TestStruct foo) {
|
||||
System.out.println("Doing Stuff " + foo);
|
||||
System.out.println(" -- (" + foo.a.getClass() + ", " + foo.b.getClass() + ", " + foo.c.getClass() + ")");
|
||||
if (!(foo instanceof TestStruct) ||
|
||||
!(foo.a instanceof String) ||
|
||||
!(foo.b instanceof UInt32) ||
|
||||
!(foo.c instanceof Variant) ||
|
||||
!"bar".equals(foo.a) ||
|
||||
foo.b.intValue() != 52 ||
|
||||
!(foo.c.getValue() instanceof Boolean) ||
|
||||
((Boolean) foo.c.getValue()).booleanValue() != true)
|
||||
test.fail("dostuff received the wrong arguments");
|
||||
return (T) foo.c.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Local classes MUST implement this to return false
|
||||
*/
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method we are exporting to the Bus.
|
||||
*/
|
||||
public List<Integer> sampleArray(List<String> ss, Integer[] is, long[] ls) {
|
||||
System.out.println("Got an array:");
|
||||
for (String s : ss)
|
||||
System.out.println("--" + s);
|
||||
if (ss.size() != 5 ||
|
||||
!"hi".equals(ss.get(0)) ||
|
||||
!"hello".equals(ss.get(1)) ||
|
||||
!"hej".equals(ss.get(2)) ||
|
||||
!"hey".equals(ss.get(3)) ||
|
||||
!"aloha".equals(ss.get(4)))
|
||||
test.fail("sampleArray, String array contents incorrect");
|
||||
System.out.println("Got an array:");
|
||||
for (Integer i : is)
|
||||
System.out.println("--" + i);
|
||||
if (is.length != 4 ||
|
||||
is[0].intValue() != 1 ||
|
||||
is[1].intValue() != 5 ||
|
||||
is[2].intValue() != 7 ||
|
||||
is[3].intValue() != 9)
|
||||
test.fail("sampleArray, Integer array contents incorrect");
|
||||
System.out.println("Got an array:");
|
||||
for (long l : ls)
|
||||
System.out.println("--" + l);
|
||||
if (ls.length != 4 ||
|
||||
ls[0] != 2 ||
|
||||
ls[1] != 6 ||
|
||||
ls[2] != 8 ||
|
||||
ls[3] != 12)
|
||||
test.fail("sampleArray, Integer array contents incorrect");
|
||||
Vector<Integer> v = new Vector<Integer>();
|
||||
v.add(-1);
|
||||
v.add(-5);
|
||||
v.add(-7);
|
||||
v.add(-12);
|
||||
v.add(-18);
|
||||
return v;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "This Is A UTF-8 Name: س !!";
|
||||
}
|
||||
|
||||
public String getNameAndThrow() throws TestException {
|
||||
throw new TestException("test");
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
System.out.println("Being checked");
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> int frobnicate(List<Long> n, Map<String, Map<UInt16, Short>> m, T v) {
|
||||
if (null == n)
|
||||
test.fail("List was null");
|
||||
if (n.size() != 3)
|
||||
test.fail("List was wrong size (expected 3, actual " + n.size() + ")");
|
||||
if (n.get(0) != 2L ||
|
||||
n.get(1) != 5L ||
|
||||
n.get(2) != 71L)
|
||||
test.fail("List has wrong contents");
|
||||
if (!(v instanceof Integer))
|
||||
test.fail("v not an Integer");
|
||||
if (((Integer) v) != 13)
|
||||
test.fail("v is incorrect");
|
||||
if (null == m)
|
||||
test.fail("Map was null");
|
||||
if (m.size() != 1)
|
||||
test.fail("Map was wrong size");
|
||||
if (!m.keySet().contains("stuff"))
|
||||
test.fail("Incorrect key");
|
||||
Map<UInt16, Short> mus = m.get("stuff");
|
||||
if (null == mus)
|
||||
test.fail("Sub-Map was null");
|
||||
if (mus.size() != 3)
|
||||
test.fail("Sub-Map was wrong size");
|
||||
if (!(new Short((short) 5).equals(mus.get(new UInt16(4)))))
|
||||
test.fail("Sub-Map has wrong contents");
|
||||
if (!(new Short((short) 6).equals(mus.get(new UInt16(5)))))
|
||||
test.fail("Sub-Map has wrong contents");
|
||||
if (!(new Short((short) 7).equals(mus.get(new UInt16(6)))))
|
||||
test.fail("Sub-Map has wrong contents");
|
||||
return -5;
|
||||
}
|
||||
|
||||
public DBusInterface getThis(DBusInterface t) {
|
||||
if (!t.equals(this))
|
||||
test.fail("Didn't get this properly");
|
||||
return this;
|
||||
}
|
||||
|
||||
public void throwme() throws TestException {
|
||||
throw new TestException("test");
|
||||
}
|
||||
|
||||
public TestSerializable<String> testSerializable(byte b, TestSerializable<String> s, int i) {
|
||||
System.out.println("Recieving TestSerializable: " + s);
|
||||
if (b != 12
|
||||
|| i != 13
|
||||
|| !(s.getInt() == 1)
|
||||
|| !(s.getString().equals("woo"))
|
||||
|| !(s.getVector().size() == 3)
|
||||
|| !(s.getVector().get(0) == 1)
|
||||
|| !(s.getVector().get(1) == 2)
|
||||
|| !(s.getVector().get(2) == 3))
|
||||
test.fail("Error in recieving custom synchronisation");
|
||||
return s;
|
||||
}
|
||||
|
||||
public String recursionTest() {
|
||||
try {
|
||||
TestRemoteInterface tri = conn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface.class);
|
||||
return tri.getName();
|
||||
} catch (DBusException DBe) {
|
||||
test.fail("Failed with error: " + DBe);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public int overload(String s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int overload(byte b) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int overload() {
|
||||
DBusCallInfo info = DBusConnection.getCallInfo();
|
||||
if ("org.freedesktop.dbus.test.AlternateTestInterface".equals(info.getInterface()))
|
||||
return 3;
|
||||
else if ("org.freedesktop.dbus.test.TestRemoteInterface".equals(info.getInterface()))
|
||||
return 4;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public List<List<Integer>> checklist(List<List<Integer>> lli) {
|
||||
return lli;
|
||||
}
|
||||
|
||||
public TestNewInterface getNew() {
|
||||
testnewclass n = new testnewclass();
|
||||
try {
|
||||
conn.exportObject("/new", n);
|
||||
} catch (DBusException DBe) {
|
||||
throw new DBusExecutionException(DBe.getMessage());
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public void sig(Type[] s) {
|
||||
if (s.length != 2
|
||||
|| !s[0].equals(Byte.class)
|
||||
|| !(s[1] instanceof ParameterizedType)
|
||||
|| !Map.class.equals(((ParameterizedType) s[1]).getRawType())
|
||||
|| ((ParameterizedType) s[1]).getActualTypeArguments().length != 2
|
||||
|| !String.class.equals(((ParameterizedType) s[1]).getActualTypeArguments()[0])
|
||||
|| !Integer.class.equals(((ParameterizedType) s[1]).getActualTypeArguments()[1]))
|
||||
test.fail("Didn't send types correctly");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void complexv(Variant<? extends Object> v) {
|
||||
if (!"a{ss}".equals(v.getSig())
|
||||
|| !(v.getValue() instanceof Map)
|
||||
|| ((Map<Object, Object>) v.getValue()).size() != 1
|
||||
|| !"moo".equals(((Map<Object, Object>) v.getValue()).get("cow")))
|
||||
test.fail("Didn't send variant correctly");
|
||||
}
|
||||
|
||||
public void reg13291(byte[] as, byte[] bs) {
|
||||
if (as.length != bs.length) test.fail("didn't receive identical byte arrays");
|
||||
for (int i = 0; i < as.length; i++)
|
||||
if (as[i] != bs[i]) test.fail("didn't receive identical byte arrays");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <A> A Get(String interface_name, String property_name) {
|
||||
return (A) new Path("/nonexistant/path");
|
||||
}
|
||||
|
||||
public <A> void Set(String interface_name, String property_name, A value) {
|
||||
}
|
||||
|
||||
public Map<String, Variant> GetAll(String interface_name) {
|
||||
return new HashMap<String, Variant>();
|
||||
}
|
||||
|
||||
public Path pathrv(Path a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
public List<Path> pathlistrv(List<Path> a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
public Map<Path, Path> pathmaprv(Map<Path, Path> a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Variant> svm() {
|
||||
HashMap<String, Variant> properties = new HashMap<String, Variant>();
|
||||
HashMap<String, Variant<String>> parameters = new HashMap<String, Variant<String>>();
|
||||
|
||||
parameters.put("Name", new Variant<String>("Joe"));
|
||||
parameters.put("Password", new Variant<String>("abcdef"));
|
||||
|
||||
properties.put("Parameters", new Variant(parameters, "a{sv}"));
|
||||
return (Map<String, Variant>) properties;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Typed signal handler for renamed signal
|
||||
*/
|
||||
class renamedsignalhandler implements DBusSigHandler<TestSignalInterface2.TestRenamedSignal> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(TestSignalInterface2.TestRenamedSignal t) {
|
||||
if (false == test.done5) {
|
||||
test.done5 = true;
|
||||
} else {
|
||||
test.fail("SignalHandler R has been run too many times");
|
||||
}
|
||||
System.out.println("SignalHandler R Running");
|
||||
System.out.println("string(" + t.value + ") int(" + t.number + ")");
|
||||
if (!"Bar".equals(t.value) || !(new UInt32(42)).equals(t.number))
|
||||
test.fail("Incorrect TestRenamedSignal parameters");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty signal handler
|
||||
*/
|
||||
class emptysignalhandler implements DBusSigHandler<TestSignalInterface.EmptySignal> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(TestSignalInterface.EmptySignal t) {
|
||||
if (false == test.done7) {
|
||||
test.done7 = true;
|
||||
} else {
|
||||
test.fail("SignalHandler E has been run too many times");
|
||||
}
|
||||
System.out.println("SignalHandler E Running");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect handler
|
||||
*/
|
||||
class disconnecthandler implements DBusSigHandler<DBus.Local.Disconnected> {
|
||||
private DBusConnection conn;
|
||||
private renamedsignalhandler sh;
|
||||
|
||||
public disconnecthandler(DBusConnection conn, renamedsignalhandler sh) {
|
||||
this.conn = conn;
|
||||
this.sh = sh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(DBus.Local.Disconnected t) {
|
||||
if (false == test.done6) {
|
||||
test.done6 = true;
|
||||
System.out.println("Handling disconnect, unregistering handler");
|
||||
try {
|
||||
conn.removeSigHandler(TestSignalInterface2.TestRenamedSignal.class, sh);
|
||||
} catch (DBusException DBe) {
|
||||
DBe.printStackTrace();
|
||||
test.fail("Disconnect handler threw an exception: " + DBe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Typed signal handler
|
||||
*/
|
||||
class pathsignalhandler implements DBusSigHandler<TestSignalInterface.TestPathSignal> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(TestSignalInterface.TestPathSignal t) {
|
||||
System.out.println("Path sighandler: " + t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Typed signal handler
|
||||
*/
|
||||
class signalhandler implements DBusSigHandler<TestSignalInterface.TestSignal> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(TestSignalInterface.TestSignal t) {
|
||||
if (false == test.done1) {
|
||||
test.done1 = true;
|
||||
} else {
|
||||
test.fail("SignalHandler 1 has been run too many times");
|
||||
}
|
||||
System.out.println("SignalHandler 1 Running");
|
||||
System.out.println("string(" + t.value + ") int(" + t.number + ")");
|
||||
if (!"Bar".equals(t.value) || !(new UInt32(42)).equals(t.number))
|
||||
test.fail("Incorrect TestSignal parameters");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Untyped signal handler
|
||||
*/
|
||||
class arraysignalhandler implements DBusSigHandler<TestSignalInterface.TestArraySignal> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(TestSignalInterface.TestArraySignal t) {
|
||||
try {
|
||||
if (false == test.done2) {
|
||||
test.done2 = true;
|
||||
} else {
|
||||
test.fail("SignalHandler 2 has been run too many times");
|
||||
}
|
||||
System.out.println("SignalHandler 2 Running");
|
||||
if (t.v.size() != 1)
|
||||
test.fail("Incorrect TestArraySignal array length: should be 1, actually " + t.v.size());
|
||||
System.out.println("Got a test array signal with Parameters: ");
|
||||
for (String str : t.v.get(0).a)
|
||||
System.out.println("--" + str);
|
||||
System.out.println(t.v.get(0).b.getType());
|
||||
System.out.println(t.v.get(0).b.getValue());
|
||||
if (!(t.v.get(0).b.getValue() instanceof UInt64) ||
|
||||
567L != ((UInt64) t.v.get(0).b.getValue()).longValue() ||
|
||||
t.v.get(0).a.size() != 5 ||
|
||||
!"hi".equals(t.v.get(0).a.get(0)) ||
|
||||
!"hello".equals(t.v.get(0).a.get(1)) ||
|
||||
!"hej".equals(t.v.get(0).a.get(2)) ||
|
||||
!"hey".equals(t.v.get(0).a.get(3)) ||
|
||||
!"aloha".equals(t.v.get(0).a.get(4)))
|
||||
test.fail("Incorrect TestArraySignal parameters");
|
||||
|
||||
if (t.m.keySet().size() != 2)
|
||||
test.fail("Incorrect TestArraySignal map size: should be 2, actually " + t.m.keySet().size());
|
||||
if (!(t.m.get(new UInt32(1)).b.getValue() instanceof UInt64) ||
|
||||
678L != ((UInt64) t.m.get(new UInt32(1)).b.getValue()).longValue() ||
|
||||
!(t.m.get(new UInt32(42)).b.getValue() instanceof UInt64) ||
|
||||
789L != ((UInt64) t.m.get(new UInt32(42)).b.getValue()).longValue())
|
||||
test.fail("Incorrect TestArraySignal parameters");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
test.fail("SignalHandler 2 threw an exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Object path signal handler
|
||||
*/
|
||||
class objectsignalhandler implements DBusSigHandler<TestSignalInterface.TestObjectSignal> {
|
||||
public void handle(TestSignalInterface.TestObjectSignal s) {
|
||||
if (false == test.done3) {
|
||||
test.done3 = true;
|
||||
} else {
|
||||
test.fail("SignalHandler 3 has been run too many times");
|
||||
}
|
||||
System.out.println(s.otherpath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handler which should never be called
|
||||
*/
|
||||
class badarraysignalhandler<T extends DBusSignal> implements DBusSigHandler<T> {
|
||||
/**
|
||||
* Handling a signal
|
||||
*/
|
||||
public void handle(T s) {
|
||||
test.fail("This signal handler shouldn't be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback handler
|
||||
*/
|
||||
class callbackhandler implements CallbackHandler<String> {
|
||||
public void handle(String r) {
|
||||
System.out.println("Handling callback: " + r);
|
||||
Collator col = Collator.getInstance();
|
||||
col.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
col.setStrength(Collator.PRIMARY);
|
||||
if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", r))
|
||||
test.fail("call with callback, wrong return value");
|
||||
if (test.done4) test.fail("Already ran callback handler");
|
||||
test.done4 = true;
|
||||
}
|
||||
|
||||
public void handleError(DBusExecutionException e) {
|
||||
System.out.println("Handling error callback: " + e + " message = '" + e.getMessage() + "'");
|
||||
if (!(e instanceof TestException)) test.fail("Exception is of the wrong sort");
|
||||
Collator col = Collator.getInstance();
|
||||
col.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
col.setStrength(Collator.PRIMARY);
|
||||
if (0 != col.compare("test", e.getMessage()))
|
||||
test.fail("Exception has the wrong message");
|
||||
if (test.done8) test.fail("Already ran callback error handler");
|
||||
test.done8 = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test program which sends and recieves a signal, implements, exports and calls a remote method.
|
||||
*/
|
||||
public class test {
|
||||
public static boolean done1 = false;
|
||||
public static boolean done2 = false;
|
||||
public static boolean done3 = false;
|
||||
public static boolean done4 = false;
|
||||
public static boolean done5 = false;
|
||||
public static boolean done6 = false;
|
||||
public static boolean done7 = false;
|
||||
public static boolean done8 = false;
|
||||
|
||||
public static void fail(String message) {
|
||||
System.out.println("Test Failed: " + message);
|
||||
System.err.println("Test Failed: " + message);
|
||||
if (null != serverconn) serverconn.disconnect();
|
||||
if (null != clientconn) clientconn.disconnect();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
static DBusConnection serverconn = null;
|
||||
static DBusConnection clientconn = null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.out.println("Creating Connection");
|
||||
serverconn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
clientconn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
serverconn.setWeakReferences(true);
|
||||
clientconn.setWeakReferences(true);
|
||||
|
||||
System.out.println("Registering Name");
|
||||
serverconn.requestBusName("foo.bar.Test");
|
||||
|
||||
/** This gets a remote object matching our bus name and exported object path. */
|
||||
Peer peer = clientconn.getRemoteObject("foo.bar.Test", "/Test", Peer.class);
|
||||
DBus dbus = clientconn.getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class);
|
||||
|
||||
System.out.print("Listening for signals...");
|
||||
signalhandler sigh = new signalhandler();
|
||||
renamedsignalhandler rsh = new renamedsignalhandler();
|
||||
try {
|
||||
/** This registers an instance of the test class as the signal handler for the TestSignal class. */
|
||||
clientconn.addSigHandler(TestSignalInterface.EmptySignal.class, new emptysignalhandler());
|
||||
clientconn.addSigHandler(TestSignalInterface.TestSignal.class, sigh);
|
||||
clientconn.addSigHandler(TestSignalInterface2.TestRenamedSignal.class, rsh);
|
||||
clientconn.addSigHandler(DBus.Local.Disconnected.class, new disconnecthandler(clientconn, rsh));
|
||||
String source = dbus.GetNameOwner("foo.bar.Test");
|
||||
clientconn.addSigHandler(TestSignalInterface.TestArraySignal.class, source, peer, new arraysignalhandler());
|
||||
clientconn.addSigHandler(TestSignalInterface.TestObjectSignal.class, new objectsignalhandler());
|
||||
clientconn.addSigHandler(TestSignalInterface.TestPathSignal.class, new pathsignalhandler());
|
||||
badarraysignalhandler<TestSignalInterface.TestSignal> bash = new badarraysignalhandler<TestSignalInterface.TestSignal>();
|
||||
clientconn.addSigHandler(TestSignalInterface.TestSignal.class, bash);
|
||||
clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, bash);
|
||||
System.out.println("done");
|
||||
} catch (MatchRuleInvalid MRI) {
|
||||
test.fail("Failed to add handlers: " + MRI.getMessage());
|
||||
} catch (DBusException DBe) {
|
||||
test.fail("Failed to add handlers: " + DBe.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("Listening for Method Calls");
|
||||
testclass tclass = new testclass(serverconn);
|
||||
testclass tclass2 = new testclass(serverconn);
|
||||
/** This exports an instance of the test class as the object /Test. */
|
||||
serverconn.exportObject("/Test", tclass);
|
||||
serverconn.exportObject("/BadTest", tclass);
|
||||
serverconn.exportObject("/BadTest2", tclass2);
|
||||
serverconn.addFallback("/FallbackTest", tclass);
|
||||
|
||||
// explicitly unexport object
|
||||
serverconn.unExportObject("/BadTest");
|
||||
// implicitly unexport object
|
||||
tclass2 = null;
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
||||
System.out.println("Sending Signal");
|
||||
/** This creates an instance of the Test Signal, with the given object path, signal name and parameters, and broadcasts in on the Bus. */
|
||||
serverconn.sendSignal(new TestSignalInterface.TestSignal("/foo/bar/Wibble", "Bar", new UInt32(42)));
|
||||
serverconn.sendSignal(new TestSignalInterface.EmptySignal("/foo/bar/Wibble"));
|
||||
serverconn.sendSignal(new TestSignalInterface2.TestRenamedSignal("/foo/bar/Wibble", "Bar", new UInt32(42)));
|
||||
|
||||
System.out.println("These things are on the bus:");
|
||||
String[] names = dbus.ListNames();
|
||||
for (String name : names)
|
||||
System.out.println("\t" + name);
|
||||
|
||||
System.out.println("Getting our introspection data");
|
||||
/** This gets a remote object matching our bus name and exported object path. */
|
||||
Introspectable intro = clientconn.getRemoteObject("foo.bar.Test", "/", Introspectable.class);
|
||||
/** Get introspection data */
|
||||
String data;/* = intro.Introspect();
|
||||
if (null == data || !data.startsWith("<!DOCTYPE"))
|
||||
fail("Introspection data invalid");
|
||||
System.out.println("Got Introspection Data: \n"+data);*/
|
||||
intro = clientconn.getRemoteObject("foo.bar.Test", "/Test", Introspectable.class);
|
||||
/** Get introspection data */
|
||||
data = intro.Introspect();
|
||||
if (null == data || !data.startsWith("<!DOCTYPE"))
|
||||
fail("Introspection data invalid");
|
||||
System.out.println("Got Introspection Data: \n" + data);
|
||||
|
||||
// setup bus name set
|
||||
Set<String> peers = serverconn.new PeerSet();
|
||||
peers.add("org.freedesktop.DBus");
|
||||
clientconn.requestBusName("test.testclient");
|
||||
peers.add("test.testclient");
|
||||
clientconn.releaseBusName("test.testclient");
|
||||
|
||||
System.out.println("Pinging ourselves");
|
||||
/** Call ping. */
|
||||
for (int i = 0; i < 10; i++) {
|
||||
long then = System.currentTimeMillis();
|
||||
peer.Ping();
|
||||
long now = System.currentTimeMillis();
|
||||
System.out.println("Ping returned in " + (now - then) + "ms.");
|
||||
}
|
||||
|
||||
System.out.println("Calling Method0/1");
|
||||
/** This gets a remote object matching our bus name and exported object path. */
|
||||
TestRemoteInterface tri = (TestRemoteInterface) clientconn.getPeerRemoteObject("foo.bar.Test", "/Test");
|
||||
System.out.println("Got Remote Object: " + tri);
|
||||
/** Call the remote object and get a response. */
|
||||
String rname = tri.getName();
|
||||
System.out.println("Got Remote Name: " + rname);
|
||||
|
||||
Map<String, Variant> svmmap = tri.svm();
|
||||
System.out.println(svmmap.toString());
|
||||
if (!"{ Parameters => [{ Name => [Joe],Password => [abcdef] }] }".equals(svmmap.toString()))
|
||||
fail("incorrect reply from svm");
|
||||
|
||||
Path path = new Path("/nonexistantwooooooo");
|
||||
Path p = tri.pathrv(path);
|
||||
System.out.println(path.toString() + " => " + p.toString());
|
||||
if (!path.equals(p)) fail("pathrv incorrect");
|
||||
List<Path> paths = new Vector<Path>();
|
||||
paths.add(path);
|
||||
List<Path> ps = tri.pathlistrv(paths);
|
||||
System.out.println(paths.toString() + " => " + ps.toString());
|
||||
if (!paths.equals(ps)) fail("pathlistrv incorrect");
|
||||
Map<Path, Path> pathm = new HashMap<Path, Path>();
|
||||
pathm.put(path, path);
|
||||
Map<Path, Path> pm = tri.pathmaprv(pathm);
|
||||
System.out.println(pathm.toString() + " => " + pm.toString());
|
||||
System.out.println(pm.containsKey(path) + " " + pm.get(path) + " " + path.equals(pm.get(path)));
|
||||
System.out.println(pm.containsKey(p) + " " + pm.get(p) + " " + p.equals(pm.get(p)));
|
||||
for (Path q : pm.keySet()) {
|
||||
System.out.println(q);
|
||||
System.out.println(pm.get(q));
|
||||
}
|
||||
if (!pm.containsKey(path) || !path.equals(pm.get(path))) fail("pathmaprv incorrect");
|
||||
|
||||
serverconn.sendSignal(new TestSignalInterface.TestPathSignal("/Test", path, paths, pathm));
|
||||
|
||||
Collator col = Collator.getInstance();
|
||||
col.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
col.setStrength(Collator.PRIMARY);
|
||||
if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", rname))
|
||||
fail("getName return value incorrect");
|
||||
System.out.println("sending it to sleep");
|
||||
tri.waitawhile();
|
||||
System.out.println("testing floats");
|
||||
if (17.093f != tri.testfloat(new float[]{17.093f, -23f, 0.0f, 31.42f}))
|
||||
fail("testfloat returned the wrong thing");
|
||||
System.out.println("Structs of Structs");
|
||||
List<List<Integer>> lli = new Vector<List<Integer>>();
|
||||
List<Integer> li = new Vector<Integer>();
|
||||
li.add(1);
|
||||
li.add(2);
|
||||
li.add(3);
|
||||
lli.add(li);
|
||||
lli.add(li);
|
||||
lli.add(li);
|
||||
TestStruct3 ts3 = new TestStruct3(new TestStruct2(new Vector<String>(), new Variant<Integer>(0)), lli);
|
||||
int[][] out = tri.teststructstruct(ts3);
|
||||
if (out.length != 3) fail("teststructstruct returned the wrong thing: " + Arrays.deepToString(out));
|
||||
for (int[] o : out)
|
||||
if (o.length != 3
|
||||
|| o[0] != 1
|
||||
|| o[1] != 2
|
||||
|| o[2] != 3) fail("teststructstruct returned the wrong thing: " + Arrays.deepToString(out));
|
||||
|
||||
System.out.println("frobnicating");
|
||||
List<Long> ls = new Vector<Long>();
|
||||
ls.add(2L);
|
||||
ls.add(5L);
|
||||
ls.add(71L);
|
||||
Map<UInt16, Short> mus = new HashMap<UInt16, Short>();
|
||||
mus.put(new UInt16(4), (short) 5);
|
||||
mus.put(new UInt16(5), (short) 6);
|
||||
mus.put(new UInt16(6), (short) 7);
|
||||
Map<String, Map<UInt16, Short>> msmus = new HashMap<String, Map<UInt16, Short>>();
|
||||
msmus.put("stuff", mus);
|
||||
int rint = tri.frobnicate(ls, msmus, 13);
|
||||
if (-5 != rint)
|
||||
fail("frobnicate return value incorrect");
|
||||
|
||||
System.out.println("Doing stuff asynchronously with callback");
|
||||
clientconn.callWithCallback(tri, "getName", new callbackhandler());
|
||||
System.out.println("Doing stuff asynchronously with callback, which throws an error");
|
||||
clientconn.callWithCallback(tri, "getNameAndThrow", new callbackhandler());
|
||||
|
||||
/** call something that throws */
|
||||
try {
|
||||
System.out.println("Throwing stuff");
|
||||
tri.throwme();
|
||||
test.fail("Method Execution should have failed");
|
||||
} catch (TestException Te) {
|
||||
System.out.println("Remote Method Failed with: " + Te.getClass().getName() + " " + Te.getMessage());
|
||||
if (!Te.getMessage().equals("test"))
|
||||
test.fail("Error message was not correct");
|
||||
}
|
||||
|
||||
/* Test type signatures */
|
||||
Vector<Type> ts = new Vector<Type>();
|
||||
Marshalling.getJavaType("ya{si}", ts, -1);
|
||||
tri.sig(ts.toArray(new Type[0]));
|
||||
|
||||
tri.newpathtest(new Path("/new/path/test"));
|
||||
|
||||
/** Try and call an invalid remote object */
|
||||
try {
|
||||
System.out.println("Calling Method2");
|
||||
tri = clientconn.getRemoteObject("foo.bar.NotATest", "/Moofle", TestRemoteInterface.class);
|
||||
System.out.println("Got Remote Name: " + tri.getName());
|
||||
test.fail("Method Execution should have failed");
|
||||
} catch (ServiceUnknown SU) {
|
||||
System.out.println("Remote Method Failed with: " + SU.getClass().getName() + " " + SU.getMessage());
|
||||
}
|
||||
|
||||
/** Try and call an invalid remote object */
|
||||
try {
|
||||
System.out.println("Calling Method3");
|
||||
tri = clientconn.getRemoteObject("foo.bar.Test", "/Moofle", TestRemoteInterface.class);
|
||||
System.out.println("Got Remote Name: " + tri.getName());
|
||||
test.fail("Method Execution should have failed");
|
||||
} catch (UnknownObject UO) {
|
||||
System.out.println("Remote Method Failed with: " + UO.getClass().getName() + " " + UO.getMessage());
|
||||
}
|
||||
|
||||
/** Try and call an explicitly unexported object */
|
||||
try {
|
||||
System.out.println("Calling Method4");
|
||||
tri = clientconn.getRemoteObject("foo.bar.Test", "/BadTest", TestRemoteInterface.class);
|
||||
System.out.println("Got Remote Name: " + tri.getName());
|
||||
test.fail("Method Execution should have failed");
|
||||
} catch (UnknownObject UO) {
|
||||
System.out.println("Remote Method Failed with: " + UO.getClass().getName() + " " + UO.getMessage());
|
||||
}
|
||||
|
||||
/** Try and call an implicitly unexported object */
|
||||
try {
|
||||
System.out.println("Calling Method5");
|
||||
tri = clientconn.getRemoteObject("foo.bar.Test", "/BadTest2", TestRemoteInterface.class);
|
||||
System.out.println("Got Remote Name: " + tri.getName());
|
||||
test.fail("Method Execution should have failed");
|
||||
} catch (UnknownObject UO) {
|
||||
System.out.println("Remote Method Failed with: " + UO.getClass().getName() + " " + UO.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("Calling Method6");
|
||||
tri = clientconn.getRemoteObject("foo.bar.Test", "/FallbackTest/0/1", TestRemoteInterface.class);
|
||||
intro = clientconn.getRemoteObject("foo.bar.Test", "/FallbackTest/0/4", Introspectable.class);
|
||||
System.out.println("Got Fallback Name: " + tri.getName());
|
||||
System.out.println("Fallback Introspection Data: \n" + intro.Introspect());
|
||||
|
||||
System.out.println("Testing Properties returning Paths");
|
||||
Properties prop = clientconn.getRemoteObject("foo.bar.Test", "/Test", Properties.class);
|
||||
Path prv = (Path) prop.Get("foo.bar", "foo");
|
||||
System.out.println("Got path " + prv);
|
||||
System.out.println("Calling Method7--9");
|
||||
/** This gets a remote object matching our bus name and exported object path. */
|
||||
TestRemoteInterface2 tri2 = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface2.class);
|
||||
System.out.print("Calling the other introspect method: ");
|
||||
String intro2 = tri2.Introspect();
|
||||
System.out.println(intro2);
|
||||
if (0 != col.compare("Not XML", intro2))
|
||||
fail("Introspect return value incorrect");
|
||||
|
||||
/** Call the remote object and get a response. */
|
||||
TestTuple<String, List<Integer>, Boolean> rv = tri2.show(234);
|
||||
System.out.println("Show returned: " + rv);
|
||||
if (!serverconn.getUniqueName().equals(rv.a) ||
|
||||
1 != rv.b.size() ||
|
||||
1953 != rv.b.get(0) ||
|
||||
true != rv.c.booleanValue())
|
||||
fail("show return value incorrect (" + rv.a + "," + rv.b + "," + rv.c + ")");
|
||||
|
||||
System.out.println("Doing stuff asynchronously");
|
||||
DBusAsyncReply<Boolean> stuffreply = (DBusAsyncReply<Boolean>) clientconn.callMethodAsync(tri2, "dostuff", new TestStruct("bar", new UInt32(52), new Variant<Boolean>(new Boolean(true))));
|
||||
|
||||
System.out.println("Checking bools");
|
||||
if (tri2.check()) fail("bools are broken");
|
||||
|
||||
List<String> l = new Vector<String>();
|
||||
l.add("hi");
|
||||
l.add("hello");
|
||||
l.add("hej");
|
||||
l.add("hey");
|
||||
l.add("aloha");
|
||||
System.out.println("Sampling Arrays:");
|
||||
List<Integer> is = tri2.sampleArray(l, new Integer[]{1, 5, 7, 9}, new long[]{2, 6, 8, 12});
|
||||
System.out.println("sampleArray returned an array:");
|
||||
for (Integer i : is)
|
||||
System.out.println("--" + i);
|
||||
if (is.size() != 5 ||
|
||||
is.get(0).intValue() != -1 ||
|
||||
is.get(1).intValue() != -5 ||
|
||||
is.get(2).intValue() != -7 ||
|
||||
is.get(3).intValue() != -12 ||
|
||||
is.get(4).intValue() != -18)
|
||||
fail("sampleArray return value incorrect");
|
||||
|
||||
System.out.println("Get This");
|
||||
if (!tclass.equals(tri2.getThis(tri2)))
|
||||
fail("Didn't get the correct this");
|
||||
|
||||
Boolean b = stuffreply.getReply();
|
||||
System.out.println("Do stuff replied " + b);
|
||||
if (true != b.booleanValue())
|
||||
fail("dostuff return value incorrect");
|
||||
|
||||
System.out.print("Sending Array Signal...");
|
||||
/** This creates an instance of the Test Signal, with the given object path, signal name and parameters, and broadcasts in on the Bus. */
|
||||
List<TestStruct2> tsl = new Vector<TestStruct2>();
|
||||
tsl.add(new TestStruct2(l, new Variant<UInt64>(new UInt64(567))));
|
||||
Map<UInt32, TestStruct2> tsm = new HashMap<UInt32, TestStruct2>();
|
||||
tsm.put(new UInt32(1), new TestStruct2(l, new Variant<UInt64>(new UInt64(678))));
|
||||
tsm.put(new UInt32(42), new TestStruct2(l, new Variant<UInt64>(new UInt64(789))));
|
||||
serverconn.sendSignal(new TestSignalInterface.TestArraySignal("/Test", tsl, tsm));
|
||||
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("testing custom serialization...");
|
||||
Vector<Integer> v = new Vector<Integer>();
|
||||
v.add(1);
|
||||
v.add(2);
|
||||
v.add(3);
|
||||
TestSerializable<String> s = new TestSerializable<String>(1, "woo", v);
|
||||
s = tri2.testSerializable((byte) 12, s, 13);
|
||||
System.out.print("returned: " + s);
|
||||
if (s.getInt() != 1 ||
|
||||
!s.getString().equals("woo") ||
|
||||
s.getVector().size() != 3 ||
|
||||
s.getVector().get(0) != 1 ||
|
||||
s.getVector().get(1) != 2 ||
|
||||
s.getVector().get(2) != 3)
|
||||
fail("Didn't get back the same TestSerializable");
|
||||
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("testing complex variants...");
|
||||
Map m = new HashMap();
|
||||
m.put("cow", "moo");
|
||||
tri2.complexv(new Variant(m, "a{ss}"));
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("testing recursion...");
|
||||
|
||||
if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", tri2.recursionTest())) fail("recursion test failed");
|
||||
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("testing method overloading...");
|
||||
tri = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface.class);
|
||||
if (1 != tri2.overload("foo")) test.fail("wrong overloaded method called");
|
||||
if (2 != tri2.overload((byte) 0)) test.fail("wrong overloaded method called");
|
||||
if (3 != tri2.overload()) test.fail("wrong overloaded method called");
|
||||
if (4 != tri.overload()) test.fail("wrong overloaded method called");
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("reg13291...");
|
||||
byte[] as = new byte[10];
|
||||
for (int i = 0; i < 10; i++)
|
||||
as[i] = (byte) (100 - i);
|
||||
tri.reg13291(as, as);
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("Testing nested lists...");
|
||||
lli = new Vector<List<Integer>>();
|
||||
li = new Vector<Integer>();
|
||||
li.add(1);
|
||||
lli.add(li);
|
||||
List<List<Integer>> reti = tri2.checklist(lli);
|
||||
if (reti.size() != 1 ||
|
||||
reti.get(0).size() != 1 ||
|
||||
reti.get(0).get(0) != 1)
|
||||
test.fail("Failed to check nested lists");
|
||||
System.out.println("done");
|
||||
|
||||
System.out.print("Testing dynamic object creation...");
|
||||
TestNewInterface tni = tri2.getNew();
|
||||
System.out.print(tni.getName() + " ");
|
||||
System.out.println("done");
|
||||
|
||||
/* send an object in a signal */
|
||||
serverconn.sendSignal(new TestSignalInterface.TestObjectSignal("/foo/bar/Wibble", tclass));
|
||||
|
||||
/** Pause while we wait for the DBus messages to go back and forth. */
|
||||
Thread.sleep(1000);
|
||||
|
||||
// check that bus name set has been trimmed
|
||||
if (peers.size() != 1) fail("peers hasn't been trimmed");
|
||||
if (!peers.contains("org.freedesktop.DBus")) fail("peers contains the wrong name");
|
||||
|
||||
System.out.println("Checking for outstanding errors");
|
||||
DBusExecutionException DBEe = serverconn.getError();
|
||||
if (null != DBEe) throw DBEe;
|
||||
DBEe = clientconn.getError();
|
||||
if (null != DBEe) throw DBEe;
|
||||
|
||||
System.out.println("Disconnecting");
|
||||
/** Disconnect from the bus. */
|
||||
clientconn.disconnect();
|
||||
serverconn.disconnect();
|
||||
|
||||
System.out.println("Trying to do things after disconnection");
|
||||
|
||||
/** Remove sig handler */
|
||||
clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, sigh);
|
||||
|
||||
/** Call a method when disconnected */
|
||||
try {
|
||||
System.out.println("getName() suceeded and returned: " + tri.getName());
|
||||
fail("Should not succeed when disconnected");
|
||||
} catch (NotConnected NC) {
|
||||
System.out.println("getName() failed with exception " + NC);
|
||||
}
|
||||
clientconn = null;
|
||||
serverconn = null;
|
||||
|
||||
if (!done1) fail("Signal handler 1 failed to be run");
|
||||
if (!done2) fail("Signal handler 2 failed to be run");
|
||||
if (!done3) fail("Signal handler 3 failed to be run");
|
||||
if (!done4) fail("Callback handler failed to be run");
|
||||
if (!done5) fail("Signal handler R failed to be run");
|
||||
if (!done6) fail("Disconnect handler failed to be run");
|
||||
if (!done7) fail("Signal handler E failed to be run");
|
||||
if (!done8) fail("Error callback handler failed to be run");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Unexpected Exception Occurred: " + e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
import cx.ath.matthew.debug.Debug;
|
||||
|
||||
public class test_low_level {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Debug.setHexDump(true);
|
||||
String addr = System.getenv("DBUS_SESSION_BUS_ADDRESS");
|
||||
Debug.print(addr);
|
||||
BusAddress address = new BusAddress(addr);
|
||||
Debug.print(address);
|
||||
|
||||
Transport conn = new Transport(address);
|
||||
|
||||
Message m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "Hello", (byte) 0, null);
|
||||
conn.mout.writeMessage(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print(m.getClass());
|
||||
Debug.print(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print(m.getClass());
|
||||
Debug.print(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print("" + m);
|
||||
m = new MethodCall("org.freedesktop.DBus", "/", null, "Hello", (byte) 0, null);
|
||||
conn.mout.writeMessage(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print(m);
|
||||
|
||||
m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", (byte) 0, "su", "org.testname", 0);
|
||||
conn.mout.writeMessage(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print(m);
|
||||
m = new DBusSignal(null, "/foo", "org.foo", "Foo", null);
|
||||
conn.mout.writeMessage(m);
|
||||
m = conn.min.readMessage();
|
||||
Debug.print(m);
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public class two_part_test_client {
|
||||
public static class two_part_test_object implements TwoPartObject {
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
System.out.println("client name");
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("get conn");
|
||||
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
System.out.println("get remote");
|
||||
TwoPartInterface remote = conn.getRemoteObject("org.freedesktop.dbus.test.two_part_server", "/", TwoPartInterface.class);
|
||||
System.out.println("get object");
|
||||
TwoPartObject o = remote.getNew();
|
||||
System.out.println("get name");
|
||||
System.out.println(o.getName());
|
||||
two_part_test_object tpto = new two_part_test_object();
|
||||
conn.exportObject("/TestObject", tpto);
|
||||
conn.sendSignal(new TwoPartInterface.TwoPartSignal("/FromObject", tpto));
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
D-Bus Java Implementation
|
||||
Copyright (c) 2005-2006 Matthew Johnson
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of either the GNU Lesser General Public License Version 2 or the
|
||||
Academic Free Licence Version 2.1.
|
||||
|
||||
Full licence texts are included in the COPYING file with this program.
|
||||
*/
|
||||
package org.freedesktop.dbus;
|
||||
|
||||
public class two_part_test_server implements TwoPartInterface, DBusSigHandler<TwoPartInterface.TwoPartSignal> {
|
||||
public class two_part_test_object implements TwoPartObject {
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
System.out.println("give name");
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
private DBusConnection conn;
|
||||
|
||||
public two_part_test_server(DBusConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public boolean isRemote() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public TwoPartObject getNew() {
|
||||
TwoPartObject o = new two_part_test_object();
|
||||
System.out.println("export new");
|
||||
try {
|
||||
conn.exportObject("/12345", o);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.out.println("give new");
|
||||
return o;
|
||||
}
|
||||
|
||||
public void handle(TwoPartInterface.TwoPartSignal s) {
|
||||
System.out.println("Got: " + s.o);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
|
||||
conn.requestBusName("org.freedesktop.dbus.test.two_part_server");
|
||||
two_part_test_server server = new two_part_test_server(conn);
|
||||
conn.exportObject("/", server);
|
||||
conn.addSigHandler(TwoPartInterface.TwoPartSignal.class, server);
|
||||
while (true) try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException Ie) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.jvnet.libpam;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class InteractiveTester extends TestCase {
|
||||
public InteractiveTester(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public void testPositiveCase() throws Exception {
|
||||
for (int i = 0; i < 1000; i++)
|
||||
testOne();
|
||||
}
|
||||
|
||||
public void testOne() throws Exception {
|
||||
UnixUser u = new PAM("sshd").authenticate(System.getProperty("user.name"), System.getProperty("password"));
|
||||
if (!printOnce) {
|
||||
System.out.println(u.getUID());
|
||||
System.out.println(u.getGroups());
|
||||
printOnce = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetGroups() throws Exception {
|
||||
System.out.println(new PAM("sshd").getGroupsOfUser(System.getProperty("user.name")));
|
||||
}
|
||||
|
||||
public void testConcurrent() throws Exception {
|
||||
ExecutorService es = Executors.newFixedThreadPool(10);
|
||||
Set<Future<?>> result = new HashSet<Future<?>>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
result.add(es.submit(new Callable<Object>() {
|
||||
public Object call() throws Exception {
|
||||
testOne();
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
// wait for completion
|
||||
for (Future<?> f : result) {
|
||||
f.get();
|
||||
}
|
||||
es.shutdown();
|
||||
}
|
||||
|
||||
public void testNegative() throws Exception {
|
||||
try {
|
||||
new PAM("sshd").authenticate("bogus", "bogus");
|
||||
fail("expected a failure");
|
||||
} catch (PAMException e) {
|
||||
// yep
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
UnixUser u = new PAM("sshd").authenticate(args[0], args[1]);
|
||||
System.out.println(u.getUID());
|
||||
System.out.println(u.getGroups());
|
||||
System.out.println(u.getGecos());
|
||||
System.out.println(u.getDir());
|
||||
System.out.println(u.getShell());
|
||||
}
|
||||
|
||||
private boolean printOnce;
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2014, R. Tyler Croy
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.jvnet.libpam;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UnixUserTest {
|
||||
private UnixUser user = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PAMException {
|
||||
user = new UnixUser("root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserName() {
|
||||
Assert.assertEquals("root", user.getUserName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDir() {
|
||||
Assert.assertNotNull(user.getDir());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUID() {
|
||||
Assert.assertEquals(0, user.getUID());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue