1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sf.bluecove;
26
27 import java.io.DataInputStream;
28 import java.io.IOException;
29
30 import javax.microedition.io.Connection;
31 import javax.microedition.io.StreamConnection;
32
33 import org.bluecove.tester.log.Logger;
34
35 import junit.framework.Assert;
36
37
38
39
40 public class TestResponderClientRFCOMM extends TestResponderClientConnection {
41
42 private ConnectionHolderStream c;
43
44 static void connectAndTest(TestResponderClient client, String serverURL) {
45 client.connectAndTest(serverURL, "", Configuration.TEST_CASE_FIRST, Configuration.TEST_CASE_LAST,
46 new TestResponderClientRFCOMM());
47 }
48
49 public String protocolID() {
50 return "RF";
51 }
52
53 public ConnectionHolder connected(Connection conn) throws IOException {
54 c = new ConnectionHolderStream((StreamConnection) conn);
55 c.os = c.conn.openOutputStream();
56
57 return c;
58 }
59
60 public void executeTest(int testType, TestStatus testStatus) throws IOException {
61 c.os.write(Consts.SEND_TEST_START);
62 c.os.write(testType);
63 c.os.flush();
64
65 c.is = c.conn.openInputStream();
66 c.active();
67
68 CommunicationTester.runTest(testType, false, c, testStatus);
69 c.active();
70
71 }
72
73 public void replySuccess(String logPrefix, int testType, TestStatus testStatus) throws IOException {
74 c.os.flush();
75 Logger.debug(logPrefix + "read server status");
76 int ok = c.is.read();
77 if (ok != Consts.SEND_TEST_REPLY_OK_MESSAGE) {
78 Assert.assertEquals("Server reply OK", Consts.SEND_TEST_REPLY_OK, ok);
79 }
80 int conformTestType = c.is.read();
81 Assert.assertEquals("Test reply conform#", testType, conformTestType);
82 if (ok == Consts.SEND_TEST_REPLY_OK_MESSAGE) {
83 DataInputStream dis = new DataInputStream(c.is);
84 String message = dis.readUTF();
85 if (message == null) {
86 Assert.fail("Server message expected");
87 }
88 Logger.info(logPrefix + "Server message\n[" + message + "]");
89 }
90 }
91
92 public void sendStopServerCmd(String serverURL) {
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 }
114 }