
org.freedesktop.dbus.test.test Maven / Gradle / Ivy
The newest version!
/*
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.test;
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.Set;
import java.util.Vector;
import java.text.Collator;
import org.freedesktop.dbus.CallbackHandler;
import org.freedesktop.dbus.DBusAsyncReply;
import org.freedesktop.dbus.DBusCallInfo;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.Marshalling;
import org.freedesktop.dbus.Path;
import org.freedesktop.dbus.UInt16;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.UInt64;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.freedesktop.dbus.exceptions.NotConnected;
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.Peer;
import org.freedesktop.DBus.Introspectable;
import org.freedesktop.DBus.Properties;
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> 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 TestTuple, 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 l = new Vector();
l.add(1953);
return new TestTuple, Boolean>(info.getSource(), l, true);
}
@SuppressWarnings("unchecked")
public 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 sampleArray(List 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 v = new Vector();
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 int frobnicate(List n, Map> 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 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 testSerializable(byte b, TestSerializable 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> checklist(List> 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy