Commit 7b20679d authored by jehan's avatar jehan
Browse files

more test

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@103 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 7084a695
......@@ -208,4 +208,75 @@ public class SipClient {
}
/**
* @param aTo uri to call
* @param should I put an SDP ?
*/
public Call call(String aTo,boolean enableSdp,final long aCallDuration) {
try {
String lCallerUri = mSipIdentity;
String lCalleeUri = aTo;
mLog.info("Calling ["+aTo+"] from ["+mSipIdentity+"]");
long lTimout = 75000;
final Semaphore lCallerSemaphoreAccepted = new Semaphore(0);
final Semaphore lCalleeSemaphoreClosed = new Semaphore(0);
final Semaphore lCallerSemaphoreRinging = new Semaphore(0);
CallListener lCallerListener = new DefaultCallListener() {
public void onCallAccepted(Call call, String sdp, Message resp) {
lCallerSemaphoreAccepted.release();
call.ackWithAnswer(sdp);
}
public void onCallClosing(Call call, Message bye) {
//nop
}
public void onCallRinging(Call call, Message resp) {
lCallerSemaphoreRinging.release();
}
};
Call lCaller = new Call(mProvider, lCallerUri, getContact(mProvider), lCallerListener);
if (enableSdp) {
lCaller.setLocalSessionDescriptor(sdp_offer);
}
lCaller.call(lCalleeUri);
Assert.assertTrue("caller call not accepted until ["+lTimout+"]", lCallerSemaphoreAccepted.tryAcquire(lTimout,TimeUnit.MILLISECONDS));
try {
Thread.sleep(aCallDuration);
} catch (InterruptedException e) {
//nop
}
lCaller.bye();
Assert.assertTrue("caller call not closed until ["+lTimout+"]", lCalleeSemaphoreClosed.tryAcquire(lTimout,TimeUnit.MILLISECONDS));
mLog.info("Call ok");
return lCaller;
} catch (Exception e) {
mLog.error("Call ko",e);
Assert.fail(e.getMessage());
return null;
}
}
public void listen() {
CallListener lCalleeListener = new DefaultCallListener() {
public void onCallConfirmed(Call call, String sdp, Message ack) {
}
public void onCallIncoming(Call call, NameAddress callee, NameAddress caller, String sdp, Message invite) {
call.accept(sdp);
}
public void onCallClosed(Call call, Message resp) {
//nop
}
};
Call lCallee = new Call(mProvider, mSipIdentity, getContact(mProvider), lCalleeListener);
lCallee.setLocalSessionDescriptor(sdp_offer);
lCallee.listen();
}
}
......@@ -25,6 +25,7 @@ import java.net.DatagramSocket;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.log4j.Logger;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.api.P2pProxyResourceManagement;
import org.linphone.p2pproxy.core.P2pProxyMain;
......@@ -38,8 +39,8 @@ private final Thread mFonisThread;
private Timer mTimer;
private final SipProvider mProvider;
private final SipClient mSipClient;
private final int REGISTRATION_PERIOD=60;
private final static Logger mLog = Logger.getLogger(UserInstance.class);
public UserInstance(final String userName) throws P2pProxyException {
try {
DatagramSocket lSocket = new DatagramSocket();
......@@ -73,19 +74,66 @@ public UserInstance(final String userName) throws P2pProxyException {
if (lFile.exists() == false) lFile.mkdir();
mProvider=new SipProvider(null,lSipPort);
mSipClient = new SipClient(mProvider,userName,30000);
TimerTask lTimerTask = new TimerTask() {
final TimerTask lTimerTask = new TimerTask() {
@Override
public void run() {
try {
// 1 get proxy address
String lProxyUri = P2pProxyMain.lookupSipProxyUri(P2pProxyResourceManagement.DOMAINE);
//2 setOutbound proxy
mProvider.setOutboundProxy(new SocketAddress(lProxyUri));
mSipClient.register(REGISTRATION_PERIOD,userName);
} catch(Exception e) {
mLog.error("cannot register user["+userName+"]",e);
} finally {
mTimer.schedule(this, REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
}
}
};
mTimer.schedule(lTimerTask, REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
mSipClient.listen();
} catch (Exception e) {
throw new P2pProxyException("cannot start client",e);
}
}
public void call(String aTo, int duration) {
mSipClient.call(aTo, true, duration);
}
static int main(String[] args) throws P2pProxyException {
String lFrom="sip:toto", lTo;
int lDuration = 10, lLoop=1;
for (int i=0; i < args.length; i=i+2) {
String argument = args[i];
if (argument.equals("-from")) {
lFrom = args[i + 1];
System.out.println("from [" + lFrom + "]");
//nop
} else if (argument.equals("-to")) {
lTo = args[i + 1];
System.out.println("to [" + lTo + "]");
} else if (argument.equals("-duration")) {
lDuration = Integer.parseInt(args[i + 1]);
System.out.println("duration [" + lDuration + "]");
} else if (argument.equals("-nb-call")) {
lLoop = Integer.parseInt(args[i + 1]);
System.out.println("nb-call [" + lLoop + "]");
} else {
System.out.println("Invalid option: " + args[i]);
usage();
System.exit(1);
}
} UserInstance lUserInstance= new UserInstance(lFrom);
for (int i=0;i<lLoop;i++) {
lUserInstance.call(lTo, lDuration);
}
}
private static void usage() {
// TODO Auto-generated method stub
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment