Skip to content

Commit 9adbfd3

Browse files
committed
Add test for List of structs and added copyright to new classes
1 parent d7988d0 commit 9adbfd3

7 files changed

Lines changed: 124 additions & 1 deletion

File tree

dbus-java/src/main/java/org/freedesktop/dbus/messages/EmptyCollectionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
D-Bus Java Implementation
3-
Copyright (c) 2019 Technolution
3+
Copyright (c) 2019 Technolution BV
44
55
This program is free software; you can redistribute it and/or modify it
66
under the terms of either the GNU Lesser General Public License Version 2 or the

dbus-java/src/test/java/org/freedesktop/dbus/test/TestAll.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.text.Collator;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.List;
2829
import java.util.Map;
@@ -68,9 +69,11 @@
6869
import org.freedesktop.dbus.test.helper.signals.handler.PathSignalHandler;
6970
import org.freedesktop.dbus.test.helper.signals.handler.RenamedSignalHandler;
7071
import org.freedesktop.dbus.test.helper.signals.handler.SignalHandler;
72+
import org.freedesktop.dbus.test.helper.structs.IntStruct;
7173
import org.freedesktop.dbus.test.helper.structs.SampleStruct;
7274
import org.freedesktop.dbus.test.helper.structs.SampleStruct2;
7375
import org.freedesktop.dbus.test.helper.structs.SampleStruct3;
76+
import org.freedesktop.dbus.test.helper.structs.SampleStruct4;
7477
import org.freedesktop.dbus.test.helper.structs.SampleTuple;
7578
import org.freedesktop.dbus.types.UInt16;
7679
import org.freedesktop.dbus.types.UInt32;
@@ -379,6 +382,25 @@ public void testStruct() throws DBusException {
379382
}
380383
}
381384

385+
@Test
386+
public void testListOfStruct() throws DBusException {
387+
SampleRemoteInterface tri = (SampleRemoteInterface) clientconn.getPeerRemoteObject("foo.bar.Test", TEST_OBJECT_PATH);
388+
389+
IntStruct elem1 = new IntStruct(3, 7);
390+
IntStruct elem2 = new IntStruct(9, 14);
391+
List<IntStruct> list = Arrays.asList(elem1, elem2);
392+
SampleStruct4 param = new SampleStruct4(list);
393+
int[][] out = tri.testListstruct(param);
394+
if (out.length != 2) {
395+
fail("teststructstruct returned the wrong thing: " + Arrays.deepToString(out));
396+
}
397+
assertEquals(elem1.getValue1(), out[0][0]);
398+
assertEquals(elem1.getValue2(), out[0][1]);
399+
assertEquals(elem2.getValue1(), out[1][0]);
400+
assertEquals(elem2.getValue2(), out[1][1]);
401+
402+
}
403+
382404
public void testFrob() throws DBusException {
383405
SampleRemoteInterface tri = (SampleRemoteInterface) clientconn.getPeerRemoteObject("foo.bar.Test", TEST_OBJECT_PATH);
384406
System.out.println("frobnicating");

dbus-java/src/test/java/org/freedesktop/dbus/test/helper/P2pTestServer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import org.freedesktop.dbus.DBusPath;
2323
import org.freedesktop.dbus.connections.impl.DirectConnection;
2424
import org.freedesktop.dbus.test.helper.interfaces.SampleRemoteInterface;
25+
import org.freedesktop.dbus.test.helper.structs.IntStruct;
2526
import org.freedesktop.dbus.test.helper.structs.SampleStruct3;
27+
import org.freedesktop.dbus.test.helper.structs.SampleStruct4;
2628
import org.freedesktop.dbus.types.UInt16;
2729

2830
public class P2pTestServer implements SampleRemoteInterface {
@@ -38,6 +40,18 @@ public int[][] teststructstruct(SampleStruct3 in) {
3840
}
3941
return out;
4042
}
43+
44+
@Override
45+
public int[][] testListstruct(SampleStruct4 in) {
46+
List<IntStruct> list = in.getInnerListOfLists();
47+
int size = list.size();
48+
int[][] retVal = new int [size][];
49+
for(int i = 0; i < size; i++) {
50+
IntStruct elem = list.get(i);
51+
retVal[i] = new int [] { elem.getValue1(), elem.getValue2()};
52+
}
53+
return retVal;
54+
}
4155

4256
@Override
4357
public String getNameAndThrow() {

dbus-java/src/test/java/org/freedesktop/dbus/test/helper/SampleClass.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import org.freedesktop.dbus.test.helper.interfaces.SampleNewInterface;
2323
import org.freedesktop.dbus.test.helper.interfaces.SampleRemoteInterface;
2424
import org.freedesktop.dbus.test.helper.interfaces.SampleRemoteInterface2;
25+
import org.freedesktop.dbus.test.helper.structs.IntStruct;
2526
import org.freedesktop.dbus.test.helper.structs.SampleStruct;
2627
import org.freedesktop.dbus.test.helper.structs.SampleStruct3;
28+
import org.freedesktop.dbus.test.helper.structs.SampleStruct4;
2729
import org.freedesktop.dbus.test.helper.structs.SampleTuple;
2830
import org.freedesktop.dbus.types.UInt16;
2931
import org.freedesktop.dbus.types.UInt32;
@@ -53,6 +55,18 @@ public int[][] teststructstruct(SampleStruct3 in) {
5355
}
5456
return out;
5557
}
58+
59+
@Override
60+
public int[][] testListstruct(SampleStruct4 in) {
61+
List<IntStruct> list = in.getInnerListOfLists();
62+
int size = list.size();
63+
int[][] retVal = new int [size][];
64+
for(int i = 0; i < size; i++) {
65+
IntStruct elem = list.get(i);
66+
retVal[i] = new int [] { elem.getValue1(), elem.getValue2()};
67+
}
68+
return retVal;
69+
}
5670

5771
@Override
5872
public float testfloat(float[] f) {

dbus-java/src/test/java/org/freedesktop/dbus/test/helper/interfaces/SampleRemoteInterface.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.freedesktop.dbus.interfaces.DBusInterface;
2323
import org.freedesktop.dbus.test.helper.SampleException;
2424
import org.freedesktop.dbus.test.helper.structs.SampleStruct3;
25+
import org.freedesktop.dbus.test.helper.structs.SampleStruct4;
2526
import org.freedesktop.dbus.types.UInt16;
2627

2728
/**
@@ -70,4 +71,7 @@ public interface SampleRemoteInterface extends DBusInterface {
7071
List<DBusPath> pathlistrv(List<DBusPath> a);
7172

7273
Map<DBusPath, DBusPath> pathmaprv(Map<DBusPath, DBusPath> a);
74+
75+
@IntrospectionDescription("Some function to test collections")
76+
int[][] testListstruct(SampleStruct4 in);
7377
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
D-Bus Java Implementation
3+
Copyright (c) 2019 Technolution BV
4+
5+
This program is free software; you can redistribute it and/or modify it
6+
under the terms of either the GNU Lesser General Public License Version 2 or the
7+
Academic Free Licence Version 2.1.
8+
9+
Full licence texts are included in the LICENSE file with this program.
10+
*/
11+
12+
package org.freedesktop.dbus.test.helper.structs;
13+
14+
import org.freedesktop.dbus.Struct;
15+
import org.freedesktop.dbus.annotations.Position;
16+
public final class IntStruct extends Struct {
17+
18+
@Position(0)
19+
private final int value1;
20+
21+
@Position(1)
22+
private final int value2;
23+
24+
public IntStruct(int value1, int value2) {
25+
this.value1 = value1;
26+
this.value2 = value2;
27+
}
28+
29+
public int getValue1() {
30+
return value1;
31+
}
32+
33+
public int getValue2() {
34+
return value2;
35+
}
36+
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
D-Bus Java Implementation
3+
Copyright (c) 2019 Technolution BV
4+
5+
This program is free software; you can redistribute it and/or modify it
6+
under the terms of either the GNU Lesser General Public License Version 2 or the
7+
Academic Free Licence Version 2.1.
8+
9+
Full licence texts are included in the LICENSE file with this program.
10+
*/
11+
12+
package org.freedesktop.dbus.test.helper.structs;
13+
14+
import java.util.List;
15+
16+
import org.freedesktop.dbus.Struct;
17+
import org.freedesktop.dbus.annotations.Position;
18+
19+
20+
public final class SampleStruct4 extends Struct {
21+
@Position(0)
22+
private final List<IntStruct> innerListOfLists;
23+
24+
public SampleStruct4(List<IntStruct> innerListOfLists) {
25+
this.innerListOfLists = innerListOfLists;
26+
}
27+
28+
public List<IntStruct> getInnerListOfLists() {
29+
return innerListOfLists;
30+
}
31+
32+
}

0 commit comments

Comments
 (0)