Skip to content

Commit 6a89b9e

Browse files
Add tests for Contacts, Video, and Sockets to hellocodenameone
This commit introduces three new test classes to `scripts/hellocodenameone` to improve test coverage on device farms: 1. `ContactsTest`: Verifies `ContactsManager.getContacts` functionality. 2. `VideoPlaybackTest`: Verifies `MediaManager.createMedia` with video playback. 3. `SocketTest`: Verifies raw `Socket` connections. These tests are designed to be minimal, Java 8 compatible, and use the existing `BaseTest` infrastructure. They are registered in `Cn1ssDeviceRunner`.
1 parent 4c0bced commit 6a89b9e

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/ContactsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codenameone.examples.hellocodenameone.tests;
22

3+
import com.codename1.contacts.Contact;
34
import com.codename1.contacts.ContactsManager;
45
import com.codename1.ui.Display;
56
import com.codename1.ui.Form;
@@ -17,7 +18,7 @@ public boolean runTest() throws Exception {
1718
new Thread(() -> {
1819
try {
1920
// Requesting only IDs to be minimal and reduce permission friction where possible
20-
String[] contacts = ContactsManager.getContacts(false, false, false, false, false, false);
21+
Contact[] contacts = ContactsManager.getContacts(false, false, false, false, false, false);
2122
Display.getInstance().callSerially(() -> {
2223
if (contacts == null) {
2324
status.setText("Contacts access denied or returned null");

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/SocketTest.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,26 @@ public void connectionEstablished(InputStream is, OutputStream os) {
4141
try {
4242
os.write("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n".getBytes());
4343
os.flush();
44+
45+
// Simple read to verify basic connectivity
46+
byte[] buffer = new byte[128];
47+
int read = is.read(buffer);
48+
if (read > 0) {
49+
Display.getInstance().callSerially(() -> {
50+
status.setText("Data received: " + read + " bytes. Success.");
51+
form.revalidate();
52+
done();
53+
});
54+
} else {
55+
Display.getInstance().callSerially(() -> {
56+
fail("Read 0 or -1 bytes from socket.");
57+
});
58+
}
59+
4460
} catch (Exception e) {
45-
fail("Write failed: " + e.getMessage());
61+
Display.getInstance().callSerially(() -> {
62+
fail("Write/Read failed: " + e.getMessage());
63+
});
4664
}
4765
}
4866

@@ -52,18 +70,6 @@ public void connectionError(int errorCode, String message) {
5270
fail("Connection error: " + message);
5371
});
5472
}
55-
56-
@Override
57-
public void messageReceived(InputStream is, OutputStream os) {
58-
// We received something, that's enough for coverage
59-
Display.getInstance().callSerially(() -> {
60-
status.setText("Message received. Success.");
61-
form.revalidate();
62-
done();
63-
});
64-
// We do not assume we can close the socket gracefully here easily as SocketConnection
65-
// is managed by the implementation.
66-
}
6773
});
6874

6975
return true;

0 commit comments

Comments
 (0)