My favorites | Sign in
Logo
                
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2008-2009 Vlad Skarzhevskyy
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @author vlads
* @version $Id$
*/
package net.sf.bluecove.obex;

import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.obex.Authenticator;
import javax.obex.HeaderSet;
import javax.obex.ServerRequestHandler;
import javax.obex.SessionNotifier;

import net.sf.bluecove.BaseEmulatorTestCase;
import net.sf.bluecove.TestCaseRunnable;

import com.intel.bluetooth.DebugLog;
import com.intel.bluetooth.obex.BlueCoveInternals;

/**
*
*/
public abstract class OBEXBaseEmulatorTestCase extends BaseEmulatorTestCase {

protected static final int OBEX_HDR_USER = 0x30;

protected static final String serverUUID = "11111111111111111111111111111123";

protected static final byte[] simpleData = "Hello world!".getBytes();

protected int serverRequestHandlerInvocations;

protected HeaderSet serverHeaders;

private volatile Connection serverAcceptedConnection;

private final Object acceptedConnectionLock = new Object();

private volatile boolean ingoreServerErrors = true;

@Override
protected void setUp() throws Exception {
super.setUp();
ingoreServerErrors = true;
serverRequestHandlerInvocations = 0;
serverHeaders = null;
serverAcceptedConnection = null;
BlueCoveInternals.readServerErrorCount();
}

protected void tearDown() throws Exception {
super.tearDown();
int errors = BlueCoveInternals.readServerErrorCount();
if (errors != 0) {
DebugLog.error("Test Server errors " + errors);
if (!ingoreServerErrors) {
// This may hide the assert message
throw new Error("Test Server errors " + errors);
}
}
}

protected abstract ServerRequestHandler createRequestHandler();

protected Authenticator getServerAuthenticator(ServerRequestHandler handler) {
return null;
}

@Override
protected Runnable createTestServer() {
return new TestCaseRunnable() {
public void execute() throws Exception {
SessionNotifier serverConnection = (SessionNotifier) Connector.open("btgoep://localhost:" + serverUUID
+ ";name=ObexTest");
synchronized (acceptedConnectionLock) {
ServerRequestHandler handler = createRequestHandler();
serverAcceptedConnection = serverConnection.acceptAndOpen(handler, getServerAuthenticator(handler));
}
}
};
}

protected void ingoreServerErrors() {
ingoreServerErrors = true;
BlueCoveInternals.readServerErrorCount();
}

protected void assertServerErrors() {
ingoreServerErrors = false;
assertEquals("OBEX Server Errors", 0, BlueCoveInternals.readServerErrorCount());
}

protected Connection getServerAcceptedConnection() {
synchronized (acceptedConnectionLock) {
return serverAcceptedConnection;
}
}

public static int longRequestPhasePackets() {
return (BlueCoveInternals.isShortRequestPhase() ? 0 : 1);
}

protected byte[] makeTestData(int length) {
byte data[] = new byte[length];
for (int i = 0; i < length; i++) {
data[i] = (byte) (i & 0xFF);
}
return data;
}
}
Show details Hide details

Change log

r2917 by skarzhevskyy on Mar 13, 2009   Diff
Updated javadocs and Copyright
Go to: 
Project members, sign in to write a code review

Older revisions

r2604 by skarzhevskyy on Dec 17, 2008   Diff
Work on OBEX TCK
r2602 by skarzhevskyy on Dec 16, 2008   Diff
Work on OBEX Authenticator
r2601 by skarzhevskyy on Dec 16, 2008   Diff
Correction to OBEX Client Operations
All revisions of this file

File info

Size: 3872 bytes, 130 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Hosted by Google Code