- Add a missing test about foundation to change \"frozen\" candidate pair state to \"waiting\";

- Nominee for a component are now obtained by looking in \"ValidList\" rather than \"CheckList\";
- Checks that are received before we start ours are triggered immediately when ICE state change to RUNNING;
- Always use \"BASE\" transport address as source for sending and checking STUN request (peer reflexive cases);
- Fix infinite recursivity in DelegatingDatagramSocket;
- Various formatting, typos, 80-line cut and missing javadocs fix.
This commit is contained in:
seb 2010-11-25 16:03:44 +00:00
parent 7de929986c
commit ed5856810a
24 changed files with 285 additions and 186 deletions

View File

@ -13,7 +13,7 @@ import org.ice4j.*;
* TURN address of certain transport protocol. * TURN address of certain transport protocol.
* *
* In the original TURN specification, only UDP is supported. * In the original TURN specification, only UDP is supported.
* Support of TCP is detailed in draft-ietf-behave-turn-tcp-05. * Support of TCP is detailed in draft-ietf-behave-turn-tcp-07.
* *
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */

View File

@ -375,6 +375,21 @@ public class Agent
//change state before we actually send checks so that we don't //change state before we actually send checks so that we don't
//miss responses and hence the possibility to nominate a pair. //miss responses and hence the possibility to nominate a pair.
setState(IceProcessingState.RUNNING); setState(IceProcessingState.RUNNING);
//if we have received connectivity checks before RUNNING state,
//trigger a check for those candidate pairs.
if(this.preDiscoveredPairsQueue.size() > 0)
{
Iterator<CandidatePair> it = preDiscoveredPairsQueue.iterator();
while(it.hasNext())
{
triggerCheck(it.next());
}
this.preDiscoveredPairsQueue.clear();
}
connCheckClient.startChecks(); connCheckClient.startChecks();
} }
} }
@ -1029,7 +1044,9 @@ public class Agent
= new CandidatePair(localCandidate, remoteCandidate); = new CandidatePair(localCandidate, remoteCandidate);
if(useCandidate) if(useCandidate)
{
triggeredPair.setUseCandidateReceived(); triggeredPair.setUseCandidateReceived();
}
synchronized(startLock) synchronized(startLock)
{ {
@ -1042,7 +1059,7 @@ public class Agent
else else
{ {
//we are not started yet so we'd better wait until we get the //we are not started yet so we'd better wait until we get the
//remote candidates incase we are holding to a new PR one. //remote candidates in case we are holding to a new PR one.
this.preDiscoveredPairsQueue.add(triggeredPair); this.preDiscoveredPairsQueue.add(triggeredPair);
} }
} }
@ -1133,7 +1150,7 @@ public class Agent
// Emil: This actually applies for all cases. // Emil: This actually applies for all cases.
/* /*
* Lyubomir: The connectivity checks for a CheckList are started * Lyubomir: The connectivity checks for a CheckList are started
* elsewhere as soon as and only if the CheckList changes from fronzen * elsewhere as soon as and only if the CheckList changes from frozen
* to unfrozen. Since CheckList#scheduleTriggeredCheck will change * to unfrozen. Since CheckList#scheduleTriggeredCheck will change
* triggerPair to Waiting and will thus unfreeze its CheckList, make * triggerPair to Waiting and will thus unfreeze its CheckList, make
* sure that the connectivity checks for the CheckList are started. * sure that the connectivity checks for the CheckList are started.
@ -1176,7 +1193,7 @@ public class Agent
* *
* @see Agent#setNominationStrategy(NominationStrategy) * @see Agent#setNominationStrategy(NominationStrategy)
*/ */
public void nominate(CandidatePair pair) public synchronized void nominate(CandidatePair pair)
throws IllegalStateException throws IllegalStateException
{ {
if(! isControlling() ) if(! isControlling() )
@ -1185,12 +1202,14 @@ public class Agent
Component parentComponent = pair.getParentComponent(); Component parentComponent = pair.getParentComponent();
IceMediaStream parentStream = parentComponent.getParentStream(); IceMediaStream parentStream = parentComponent.getParentStream();
CheckList checkList = parentStream.getCheckList(); //CheckList checkList = parentStream.getCheckList();
//If the pair is not already nominated and if its parent component //If the pair is not already nominated and if its parent component
//does not already contain a nominated pair - nominate it. //does not already contain a nominated pair - nominate it.
if(!pair.isNominated() if(!pair.isNominated()
&& !checkList.containsNomineeForComponent(parentComponent)) && !parentStream.validListContainsNomineeForComponent(
parentComponent))
/* && !checkList.containsNomineeForComponent(parentComponent)) */
{ {
pair.nominate(); pair.nominate();
pair.getParentComponent().getParentStream() pair.getParentComponent().getParentStream()
@ -1267,6 +1286,7 @@ public class Agent
atLeastOneListSucceeded = true; atLeastOneListSucceeded = true;
} }
} }
//Once the state of each check list is Completed: //Once the state of each check list is Completed:
//The agent sets the state of ICE processing overall to Completed. //The agent sets the state of ICE processing overall to Completed.
if(allListsEnded) if(allListsEnded)

View File

@ -337,13 +337,13 @@ public abstract class Candidate
*/ */
public long computePriorityForType(CandidateType candidateType) public long computePriorityForType(CandidateType candidateType)
{ {
//According to the ICE speck we compute priority this way: //According to the ICE spec we compute priority this way:
//priority = (2^24)*(type preference) + //priority = (2^24)*(type preference) +
// (2^8)*(local preference) + // (2^8)*(local preference) +
// (2^0)*(256 - component ID) // (2^0)*(256 - component ID)
return (long)( getTypePreference(candidateType) << 24 )+ return (long) (getTypePreference(candidateType) << 24) +
(long)( getLocalPreference() << 8 )+ (long) (getLocalPreference() << 8 ) +
(long) (256 - getParentComponent().getComponentID()); (long) (256 - getParentComponent().getComponentID());
} }
@ -422,7 +422,6 @@ public abstract class Candidate
if(isVirtual()) if(isVirtual())
return MIN_LOCAL_PREFERENCE; return MIN_LOCAL_PREFERENCE;
InetAddress addr = getTransportAddress().getAddress(); InetAddress addr = getTransportAddress().getAddress();
//the following tries to reusse precedence from RFC 3484 but that's a //the following tries to reusse precedence from RFC 3484 but that's a

View File

@ -449,11 +449,11 @@ public class CandidatePair
* Indicates whether some other object is &quot;equal to&quot; to this * Indicates whether some other object is &quot;equal to&quot; to this
* Comparator. This method must obey the general contract of * Comparator. This method must obey the general contract of
* <tt>Object.equals(Object)</tt>. Additionally, this method can return * <tt>Object.equals(Object)</tt>. Additionally, this method can return
* <tt>true</tt> <i>only</i> if the specified Object is also a comparator * <tt>true</tt> <i>only</i> if the specified Object is also a
* and it imposes the same ordering as this comparator. Thus, * comparator and it imposes the same ordering as this comparator. Thus,
* <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1, * <code>comp1.equals(comp2)</code> implies that
* o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference * <tt>sgn(comp1.compare(o1,o2))==sgn(comp2.compare(o1, o2))</tt> for
* <tt>o1</tt> and <tt>o2</tt>.<p> * every object reference <tt>o1</tt> and <tt>o2</tt>.<p>
* *
* Note that it is <i>always</i> safe <i>not</i> to override * Note that it is <i>always</i> safe <i>not</i> to override
* <tt>Object.equals(Object)</tt>. However, overriding this method may, * <tt>Object.equals(Object)</tt>. However, overriding this method may,

View File

@ -170,6 +170,7 @@ public class CheckList
|| pair.getPriority() > highestPriorityPair.getPriority()) || pair.getPriority() > highestPriorityPair.getPriority())
{ {
highestPriorityPair = pair; highestPriorityPair = pair;
pair.setStateWaiting();
} }
} }
} }
@ -401,19 +402,23 @@ public class CheckList
* nominated {@link CandidatePair} for the specified <tt>component</tt> * nominated {@link CandidatePair} for the specified <tt>component</tt>
* and <tt>false</tt> otherwise. * and <tt>false</tt> otherwise.
* *
* @param componennt the {@link Component} that we'd whose nominees we are * @param component the {@link Component} that we'd whose nominees we are
* interested in. * interested in.
* *
* @return <tt>true</tt> if this <tt>CheckList</tt> already contains a * @return <tt>true</tt> if this <tt>CheckList</tt> already contains a
* nominated {@link CandidatePair} for the specified <tt>component</tt> * nominated {@link CandidatePair} for the specified <tt>component</tt>
* and <tt>false</tt> otherwise. * and <tt>false</tt> otherwise.
* @deprecated This method takes into account only candidates in the
* checklist. In case of peer reflexives candidates nominated, they do not
* appears in checklist but in valid list.
*/ */
@Deprecated
public synchronized boolean containsNomineeForComponent( public synchronized boolean containsNomineeForComponent(
Component componennt) Component component)
{ {
for (CandidatePair pair : this) for (CandidatePair pair : this)
{ {
if (pair.isNominated() && pair.getParentComponent() == componennt) if (pair.isNominated() && pair.getParentComponent() == component)
return true; return true;
} }

View File

@ -413,11 +413,11 @@ public class Component
* Indicates whether some other object is &quot;equal to&quot; this * Indicates whether some other object is &quot;equal to&quot; this
* Comparator. This method must obey the general contract of * Comparator. This method must obey the general contract of
* <tt>Object.equals(Object)</tt>. Additionally, this method can return * <tt>Object.equals(Object)</tt>. Additionally, this method can return
* <tt>true</tt> <i>only</i> if the specified Object is also a comparator * <tt>true</tt> <i>only</i> if the specified Object is also a
* and it imposes the same ordering as this comparator. Thus, * comparator and it imposes the same ordering as this comparator. Thus,
* <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1, * <code>comp1.equals(comp2)</code> implies that
* o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference * <tt>sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2))</tt> for
* <tt>o1</tt> and <tt>o2</tt>.<p> * every object reference <tt>o1</tt> and <tt>o2</tt>.<p>
* *
* Note that it is <i>always</i> safe <i>not</i> to override * Note that it is <i>always</i> safe <i>not</i> to override
* <tt>Object.equals(Object)</tt>. However, overriding this method may, * <tt>Object.equals(Object)</tt>. However, overriding this method may,

View File

@ -164,12 +164,15 @@ class ConnectivityCheckClient
try try
{ {
TransportAddress localAddr = localCandidate.getBase().
getTransportAddress();
tran tran
= stunStack.sendRequest( = stunStack.sendRequest(
request, request,
candidatePair candidatePair
.getRemoteCandidate().getTransportAddress(), .getRemoteCandidate().getTransportAddress(),
localCandidate.getTransportAddress(), localAddr,
this, this,
tran); tran);
if(logger.isLoggable(Level.FINEST)) if(logger.isLoggable(Level.FINEST))
@ -402,7 +405,8 @@ class ConnectivityCheckClient
CheckList parentCheckList = parentStream.getCheckList(); CheckList parentCheckList = parentStream.getCheckList();
for(CandidatePair pair : parentCheckList) for(CandidatePair pair : parentCheckList)
if (pair.getState() == CandidatePairState.FROZEN) if ((pair.getState() == CandidatePairState.FROZEN) &&
(checkedPair.getFoundation().equals(pair.getFoundation())))
pair.setStateWaiting(); pair.setStateWaiting();
// The agent examines the check list for all other streams in turn // The agent examines the check list for all other streams in turn
@ -484,9 +488,10 @@ class ConnectivityCheckClient
{ {
CandidatePair pair = ((CandidatePair)evt.getTransactionID() CandidatePair pair = ((CandidatePair)evt.getTransactionID()
.getApplicationData()); .getApplicationData());
TransportAddress localAddr = pair.getLocalCandidate().getBase().
getTransportAddress();
boolean sym = pair.getLocalCandidate().getTransportAddress() boolean sym = localAddr.equals(evt.getLocalAddress())
.equals(evt.getLocalAddress())
&& pair.getRemoteCandidate().getTransportAddress() && pair.getRemoteCandidate().getTransportAddress()
.equals(evt.getRemoteAddress()); .equals(evt.getRemoteAddress());
@ -640,7 +645,8 @@ class ConnectivityCheckClient
} }
catch (InterruptedException e) catch (InterruptedException e)
{ {
logger.log(Level.FINER, "PaceMake got interrupted", e); logger.log(Level.FINER, "PaceMaker got interrupted",
e);
} }
if (!running) if (!running)

View File

@ -176,7 +176,7 @@ class ConnectivityCheckServer
} }
/** /**
* Resolves a role conflicts by either sendinf a <tt>487 Role Conflict</tt> * Resolves a role conflicts by either sending a <tt>487 Role Conflict</tt>
* response or by changing this server's parent agent role. The method * response or by changing this server's parent agent role. The method
* returns <tt>true</tt> if the role conflict is silently resolved and * returns <tt>true</tt> if the role conflict is silently resolved and
* processing can continue. It returns <tt>false</tt> if we had to reply * processing can continue. It returns <tt>false</tt> if we had to reply

View File

@ -493,7 +493,6 @@ public class IceMediaStream
return null; return null;
} }
/** /**
* Returns the {@link CandidatePair} with the specified remote and local * Returns the {@link CandidatePair} with the specified remote and local
* addresses or <tt>null</tt> if neither of the {@link CheckList}s in this * addresses or <tt>null</tt> if neither of the {@link CheckList}s in this
@ -602,6 +601,34 @@ public class IceMediaStream
return false; return false;
} }
/**
* Returns <tt>true</tt> if this stream's <tt>validList</tt> contains a
* pair that is nominated for the specified <tt>Component</tt> and
* <tt>false</tt> otherwise.
*
* @param component the <tt>Component</tt> we'd like to search our
* validList for.
*
* @return <tt>true</tt> if this stream's <tt>validList</tt> contains a
* pair that is nominated for the specified <tt>Component</tt> and
* <tt>false</tt> otherwise.
*/
protected boolean validListContainsNomineeForComponent(Component component)
{
synchronized(validList)
{
for(CandidatePair pair : validList)
{
if (pair.isNominated() && pair.getParentComponent() ==
component)
{
return true;
}
}
}
return false;
}
/** /**
* Returns <tt>true</tt> if this stream's valid list contains at least * Returns <tt>true</tt> if this stream's valid list contains at least
* one {@link CandidatePair} for each {@link Component} of the stream and * one {@link CandidatePair} for each {@link Component} of the stream and
@ -744,7 +771,7 @@ public class IceMediaStream
} }
PropertyChangeEvent evt = new PropertyChangeEvent( PropertyChangeEvent evt = new PropertyChangeEvent(
source, PROPERTY_PAIR_VALIDATED, oldValue, newValue); source, propertyName, oldValue, newValue);
for(PropertyChangeListener l : listenersCopy) for(PropertyChangeListener l : listenersCopy)
{ {

View File

@ -485,7 +485,7 @@ public class DelegatingDatagramSocket
@Override @Override
public boolean isClosed() public boolean isClosed()
{ {
return (delegate == null) ? super.isClosed() : this.isClosed(); return (delegate == null) ? super.isClosed() : delegate.isClosed();
} }
/** /**
@ -498,7 +498,8 @@ public class DelegatingDatagramSocket
@Override @Override
public boolean isConnected() public boolean isConnected()
{ {
return (delegate == null) ? super.isConnected() : this.isConnected(); return (delegate == null) ? super.isConnected() :
delegate.isConnected();
} }
/** /**

View File

@ -15,11 +15,11 @@ import org.ice4j.message.*;
/** /**
* Implements a <tt>DatagramPacketFilter</tt> which accepts * Implements a <tt>DatagramPacketFilter</tt> which accepts
* <tt>DatagramPacket</tt>s which represent TURN messages defined in * <tt>DatagramPacket</tt>s which represent TURN messages defined in
* draft-ietf-behave-turn-16 "Traversal Using Relays around NAT (TURN): Relay * RFC 5766 "Traversal Using Relays around NAT (TURN): Relay Extensions to
* Extensions to Session Traversal Utilities for NAT (STUN)" and which are part * Session Traversal Utilities for NAT (STUN)" and which are part of the
* of the communication with a specific TURN server. * communication with a specific TURN server. <tt>TurnDatagramPacketFilter</tt>
* <tt>TurnDatagramPacketFilter</tt> does not accept TURN ChannelData messages * does not accept TURN ChannelData messages because they require knowledge of
* because they require knowledge of the value of the "Channel Number" field. * the value of the "Channel Number" field.
* *
* @author Lubomir Marinov * @author Lubomir Marinov
*/ */

View File

@ -320,10 +320,10 @@ public class AddressAttributeTest extends TestCase {
assertEquals( assertEquals(
"AddressAttribute.decode() did not properly decode the port field.", "AddressAttribute.decode() did not properly decode the port field.",
msgFixture.ADDRESS_ATTRIBUTE_PORT, addressAttribute.getPort()); MsgFixture.ADDRESS_ATTRIBUTE_PORT, addressAttribute.getPort());
assertTrue( assertTrue(
"AddressAttribute.decode() did not properly decode the address field.", "AddressAttribute.decode() did not properly decode the address field.",
Arrays.equals( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, Arrays.equals( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
addressAttribute.getAddressBytes())); addressAttribute.getAddressBytes()));
@ -342,10 +342,10 @@ public class AddressAttributeTest extends TestCase {
assertEquals("decode() failed for an IPv6 Addr's port.", assertEquals("decode() failed for an IPv6 Addr's port.",
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
addressAttribute.getPort()); addressAttribute.getPort());
assertTrue("AddressAttribute.decode() failed for an IPv6 address.", assertTrue("AddressAttribute.decode() failed for an IPv6 address.",
Arrays.equals( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, Arrays.equals( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
addressAttribute.getAddressBytes())); addressAttribute.getAddressBytes()));
@ -354,7 +354,7 @@ public class AddressAttributeTest extends TestCase {
/** /**
* Test whether attributes are properly encoded. * Test whether attributes are properly encoded.
* *
* @throws StunException java.lang.Exception if we fail * @throws Exception java.lang.Exception if we fail
*/ */
public void testEncode() public void testEncode()
throws Exception throws Exception
@ -362,8 +362,8 @@ public class AddressAttributeTest extends TestCase {
byte[] expectedReturn = msgFixture.mappedAddress; byte[] expectedReturn = msgFixture.mappedAddress;
addressAttribute.setAddress( addressAttribute.setAddress(
new TransportAddress(msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, new TransportAddress(MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
byte[] actualReturn = addressAttribute.encode(); byte[] actualReturn = addressAttribute.encode();
@ -375,7 +375,7 @@ public class AddressAttributeTest extends TestCase {
/** /**
* Test whether attributes are properly encoded. * Test whether attributes are properly encoded.
* *
* @throws StunException java.lang.Exception if we fail * @throws Exception java.lang.Exception if we fail
*/ */
public void testEncodev6() public void testEncodev6()
throws Exception throws Exception
@ -383,8 +383,8 @@ public class AddressAttributeTest extends TestCase {
byte[] expectedReturn = msgFixture.mappedAddressv6; byte[] expectedReturn = msgFixture.mappedAddressv6;
addressAttribute.setAddress( addressAttribute.setAddress(
new TransportAddress(msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, new TransportAddress(MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP));
byte[] actualReturn = addressAttribute.encode(); byte[] actualReturn = addressAttribute.encode();
assertTrue("An AddressAttribute did not properly encode an IPv6 addr.", assertTrue("An AddressAttribute did not properly encode an IPv6 addr.",
@ -396,7 +396,7 @@ public class AddressAttributeTest extends TestCase {
* Tests the equals method against a null, a different and an identical * Tests the equals method against a null, a different and an identical
* object. * object.
* *
* @throws StunException java.lang.Exception if we fail * @throws Exception java.lang.Exception if we fail
*/ */
public void testEquals() public void testEquals()
throws Exception throws Exception
@ -412,13 +412,13 @@ public class AddressAttributeTest extends TestCase {
//difference test //difference test
target = new MappedAddressAttribute(); target = new MappedAddressAttribute();
char port = (char)(msgFixture.ADDRESS_ATTRIBUTE_PORT + 1 ); char port = (char)(MsgFixture.ADDRESS_ATTRIBUTE_PORT + 1 );
target.setAddress( new TransportAddress( target.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, port, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, port, Transport.UDP));
addressAttribute.setAddress( new TransportAddress( addressAttribute.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
expectedReturn = false; expectedReturn = false;
@ -429,8 +429,8 @@ public class AddressAttributeTest extends TestCase {
//equality test //equality test
target.setAddress( new TransportAddress( target.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP )); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP ));
expectedReturn = true; expectedReturn = true;
actualReturn = addressAttribute.equals(target); actualReturn = addressAttribute.equals(target);
@ -440,12 +440,12 @@ public class AddressAttributeTest extends TestCase {
//ipv6 equality test //ipv6 equality test
target.setAddress( new TransportAddress( target.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP));
addressAttribute.setAddress(new TransportAddress( addressAttribute.setAddress(new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
expectedReturn = true; expectedReturn = true;
@ -457,7 +457,7 @@ public class AddressAttributeTest extends TestCase {
/** /**
* Tests whether data length is properly calculated. * Tests whether data length is properly calculated.
* *
* @throws StunException java.lang.Exception if we fail * @throws Exception java.lang.Exception if we fail
*/ */
public void testGetDataLength() public void testGetDataLength()
throws Exception throws Exception
@ -465,8 +465,8 @@ public class AddressAttributeTest extends TestCase {
char expectedReturn = 8;//1-padding + 1-family + 2-port + 4-address char expectedReturn = 8;//1-padding + 1-family + 2-port + 4-address
addressAttribute.setAddress( new TransportAddress( addressAttribute.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
char actualReturn = addressAttribute.getDataLength(); char actualReturn = addressAttribute.getDataLength();
@ -476,8 +476,8 @@ public class AddressAttributeTest extends TestCase {
expectedReturn = 20;//1-padding + 1-family + 2-port + 16-address expectedReturn = 20;//1-padding + 1-family + 2-port + 16-address
addressAttribute.setAddress( new TransportAddress( addressAttribute.setAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP));
actualReturn = addressAttribute.getDataLength(); actualReturn = addressAttribute.getDataLength();
@ -487,14 +487,16 @@ public class AddressAttributeTest extends TestCase {
/** /**
* Tests that the address family is always 1. * Tests that the address family is always 1.
*
* @throws Exception java.lang.Exception if we fail
*/ */
public void testGetFamily() public void testGetFamily()
throws Exception throws Exception
{ {
byte expectedReturn = 1; byte expectedReturn = 1;
addressAttribute.setAddress(new TransportAddress( addressAttribute.setAddress(new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP));
byte actualReturn = addressAttribute.getFamily(); byte actualReturn = addressAttribute.getFamily();
assertEquals("Address family was not 1 for an IPv4", assertEquals("Address family was not 1 for an IPv4",
expectedReturn, actualReturn); expectedReturn, actualReturn);
@ -502,8 +504,8 @@ public class AddressAttributeTest extends TestCase {
//ipv6 //ipv6
expectedReturn = 2; expectedReturn = 2;
addressAttribute.setAddress(new TransportAddress( addressAttribute.setAddress(new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6,
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP));
actualReturn = addressAttribute.getFamily(); actualReturn = addressAttribute.getFamily();
assertEquals("Address family was not 2 for an IPv6 address", assertEquals("Address family was not 2 for an IPv6 address",
expectedReturn, actualReturn); expectedReturn, actualReturn);

View File

@ -14,15 +14,18 @@ import junit.framework.*;
* We have already tested individual decode methods, so our job here * We have already tested individual decode methods, so our job here
* is to verify that that AttributeDecoder.decode distributes the right way. * is to verify that that AttributeDecoder.decode distributes the right way.
*/ */
public class AttributeDecoderTest extends TestCase { public class AttributeDecoderTest extends TestCase
{
private MsgFixture msgFixture; private MsgFixture msgFixture;
private byte[] expectedAttributeValue = null; private byte[] expectedAttributeValue = null;
public AttributeDecoderTest(String name) { public AttributeDecoderTest(String name)
{
super(name); super(name);
} }
protected void setUp() throws Exception { protected void setUp() throws Exception
{
super.setUp(); super.setUp();
msgFixture = new MsgFixture(); msgFixture = new MsgFixture();
@ -38,7 +41,8 @@ public class AttributeDecoderTest extends TestCase {
msgFixture.setUp(); msgFixture.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception
{
msgFixture.tearDown(); msgFixture.tearDown();
msgFixture = null; msgFixture = null;

View File

@ -12,15 +12,23 @@ import java.util.Arrays;
import org.ice4j.*; import org.ice4j.*;
public class ChangeRequestAttributeTest extends TestCase { /**
* Tests the CHANGE-REQUEST attribute class.
*
* @author Emil Ivov
*/
public class ChangeRequestAttributeTest extends TestCase
{
private ChangeRequestAttribute changeRequestAttribute = null; private ChangeRequestAttribute changeRequestAttribute = null;
private MsgFixture binMessagesFixture; private MsgFixture binMessagesFixture;
public ChangeRequestAttributeTest(String name) { public ChangeRequestAttributeTest(String name)
{
super(name); super(name);
} }
protected void setUp() throws Exception { protected void setUp() throws Exception
{
super.setUp(); super.setUp();
changeRequestAttribute = new ChangeRequestAttribute(); changeRequestAttribute = new ChangeRequestAttribute();
binMessagesFixture = new MsgFixture(); binMessagesFixture = new MsgFixture();
@ -28,7 +36,8 @@ public class ChangeRequestAttributeTest extends TestCase {
binMessagesFixture.setUp(); binMessagesFixture.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception
{
changeRequestAttribute = null; changeRequestAttribute = null;
binMessagesFixture.tearDown(); binMessagesFixture.tearDown();
@ -39,7 +48,8 @@ public class ChangeRequestAttributeTest extends TestCase {
/** /**
* Test whether the constructed object has the proper type. * Test whether the constructed object has the proper type.
*/ */
public void testChangeRequestAttribute() { public void testChangeRequestAttribute()
{
changeRequestAttribute = new ChangeRequestAttribute(); changeRequestAttribute = new ChangeRequestAttribute();
assertEquals( assertEquals(
@ -64,11 +74,11 @@ public class ChangeRequestAttributeTest extends TestCase {
changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length); changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length);
assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag", assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag",
binMessagesFixture.CHANGE_IP_FLAG_1, MsgFixture.CHANGE_IP_FLAG_1,
changeRequestAttribute.getChangeIpFlag() changeRequestAttribute.getChangeIpFlag()
); );
assertEquals("decodeAttributeBody() did not properly decode the changePortFlag", assertEquals("decodeAttributeBody() did not properly decode the changePortFlag",
binMessagesFixture.CHANGE_PORT_FLAG_1, MsgFixture.CHANGE_PORT_FLAG_1,
changeRequestAttribute.getChangePortFlag() changeRequestAttribute.getChangePortFlag()
); );
@ -76,11 +86,11 @@ public class ChangeRequestAttributeTest extends TestCase {
attributeValue = binMessagesFixture.chngReqTestValue2; attributeValue = binMessagesFixture.chngReqTestValue2;
changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length); changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length);
assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag", assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag",
binMessagesFixture.CHANGE_IP_FLAG_2, MsgFixture.CHANGE_IP_FLAG_2,
changeRequestAttribute.getChangeIpFlag() changeRequestAttribute.getChangeIpFlag()
); );
assertEquals("decodeAttributeBody() did not properly decode the changePortFlag", assertEquals("decodeAttributeBody() did not properly decode the changePortFlag",
binMessagesFixture.CHANGE_PORT_FLAG_2, MsgFixture.CHANGE_PORT_FLAG_2,
changeRequestAttribute.getChangePortFlag() changeRequestAttribute.getChangePortFlag()
); );
@ -91,13 +101,14 @@ public class ChangeRequestAttributeTest extends TestCase {
/** /**
* Create sample objects and test whether they encode properly. * Create sample objects and test whether they encode properly.
*/ */
public void testEncode() { public void testEncode()
{
byte[] expectedReturn = binMessagesFixture.chngReqTestValue1; byte[] expectedReturn = binMessagesFixture.chngReqTestValue1;
changeRequestAttribute = new ChangeRequestAttribute(); changeRequestAttribute = new ChangeRequestAttribute();
changeRequestAttribute.setChangeIpFlag(binMessagesFixture.CHANGE_IP_FLAG_1); changeRequestAttribute.setChangeIpFlag(MsgFixture.CHANGE_IP_FLAG_1);
changeRequestAttribute.setChangePortFlag(binMessagesFixture.CHANGE_PORT_FLAG_1); changeRequestAttribute.setChangePortFlag(MsgFixture.CHANGE_PORT_FLAG_1);
byte[] actualReturn = changeRequestAttribute.encode(); byte[] actualReturn = changeRequestAttribute.encode();
assertTrue("Object did not encode properly.", assertTrue("Object did not encode properly.",
@ -107,8 +118,8 @@ public class ChangeRequestAttributeTest extends TestCase {
expectedReturn = binMessagesFixture.chngReqTestValue2; expectedReturn = binMessagesFixture.chngReqTestValue2;
changeRequestAttribute = new ChangeRequestAttribute(); changeRequestAttribute = new ChangeRequestAttribute();
changeRequestAttribute.setChangeIpFlag(binMessagesFixture.CHANGE_IP_FLAG_2); changeRequestAttribute.setChangeIpFlag(MsgFixture.CHANGE_IP_FLAG_2);
changeRequestAttribute.setChangePortFlag(binMessagesFixture.CHANGE_PORT_FLAG_2); changeRequestAttribute.setChangePortFlag(MsgFixture.CHANGE_PORT_FLAG_2);
actualReturn = changeRequestAttribute.encode(); actualReturn = changeRequestAttribute.encode();
assertTrue("Object did not encode properly.", assertTrue("Object did not encode properly.",
@ -121,7 +132,8 @@ public class ChangeRequestAttributeTest extends TestCase {
* Tests the equals method against a null, a different and an identical * Tests the equals method against a null, a different and an identical
* object. * object.
*/ */
public void testEquals() { public void testEquals()
{
ChangeRequestAttribute target = null; ChangeRequestAttribute target = null;
boolean expectedReturn = false; boolean expectedReturn = false;
@ -161,7 +173,8 @@ public class ChangeRequestAttributeTest extends TestCase {
/** /**
* Test whether the returned value is always 4. * Test whether the returned value is always 4.
*/ */
public void testGetDataLength() { public void testGetDataLength()
{
char expectedReturn = 4; // constant 4 bytes of data char expectedReturn = 4; // constant 4 bytes of data
char actualReturn = changeRequestAttribute.getDataLength(); char actualReturn = changeRequestAttribute.getDataLength();
assertEquals("data length returned an invalid value", assertEquals("data length returned an invalid value",
@ -171,7 +184,8 @@ public class ChangeRequestAttributeTest extends TestCase {
/** /**
* Test whether we get a relevant name. * Test whether we get a relevant name.
*/ */
public void testGetName() { public void testGetName()
{
String expectedReturn = "CHANGE-REQUEST"; String expectedReturn = "CHANGE-REQUEST";
String actualReturn = changeRequestAttribute.getName(); String actualReturn = changeRequestAttribute.getName();
assertEquals("Invalid name", expectedReturn, actualReturn); assertEquals("Invalid name", expectedReturn, actualReturn);

View File

@ -66,15 +66,15 @@ public class ErrorCodeAttributeTest extends TestCase {
errorCodeAttribute.decodeAttributeBody(attributeValue, offset, length); errorCodeAttribute.decodeAttributeBody(attributeValue, offset, length);
assertEquals("Error Class was not correctly decoded", assertEquals("Error Class was not correctly decoded",
msgFixture.ERROR_CLASS, MsgFixture.ERROR_CLASS,
errorCodeAttribute.getErrorClass()); errorCodeAttribute.getErrorClass());
assertEquals("Error Number was not correctly decoded", assertEquals("Error Number was not correctly decoded",
msgFixture.ERROR_NUMBER, MsgFixture.ERROR_NUMBER,
errorCodeAttribute.getErrorNumber()); errorCodeAttribute.getErrorNumber());
assertEquals("Reason phrase was not correctly decoded", assertEquals("Reason phrase was not correctly decoded",
msgFixture.REASON_PHRASE.trim(), MsgFixture.REASON_PHRASE.trim(),
errorCodeAttribute.getReasonPhrase().trim()); errorCodeAttribute.getReasonPhrase().trim());
} }
@ -90,10 +90,10 @@ public class ErrorCodeAttributeTest extends TestCase {
{ {
byte[] expectedReturn = msgFixture.errCodeTestValue; byte[] expectedReturn = msgFixture.errCodeTestValue;
errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS);
errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setReasonPhrase(msgFixture.REASON_PHRASE); errorCodeAttribute.setReasonPhrase(MsgFixture.REASON_PHRASE);
byte[] actualReturn = errorCodeAttribute.encode(); byte[] actualReturn = errorCodeAttribute.encode();
@ -122,11 +122,11 @@ public class ErrorCodeAttributeTest extends TestCase {
target = new ErrorCodeAttribute(); target = new ErrorCodeAttribute();
expectedReturn = false; expectedReturn = false;
target.setErrorClass(msgFixture.ERROR_CLASS); target.setErrorClass(MsgFixture.ERROR_CLASS);
target.setErrorNumber(msgFixture.ERROR_NUMBER); target.setErrorNumber(MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setErrorClass((byte)(msgFixture.ERROR_CLASS+1)); errorCodeAttribute.setErrorClass((byte)(MsgFixture.ERROR_CLASS+1));
errorCodeAttribute.setErrorNumber((byte)(msgFixture.ERROR_NUMBER+1)); errorCodeAttribute.setErrorNumber((byte)(MsgFixture.ERROR_NUMBER+1));
actualReturn = errorCodeAttribute.equals(target); actualReturn = errorCodeAttribute.equals(target);
assertEquals("equals() failed against a not equal target.", assertEquals("equals() failed against a not equal target.",
@ -137,11 +137,11 @@ public class ErrorCodeAttributeTest extends TestCase {
errorCodeAttribute = new ErrorCodeAttribute(); errorCodeAttribute = new ErrorCodeAttribute();
expectedReturn = true; expectedReturn = true;
target.setErrorClass(msgFixture.ERROR_CLASS); target.setErrorClass(MsgFixture.ERROR_CLASS);
target.setErrorNumber(msgFixture.ERROR_NUMBER); target.setErrorNumber(MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS);
errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER);
actualReturn = errorCodeAttribute.equals(target); actualReturn = errorCodeAttribute.equals(target);
assertEquals("equals() failed against a not equal target.", assertEquals("equals() failed against a not equal target.",
@ -158,12 +158,12 @@ public class ErrorCodeAttributeTest extends TestCase {
public void testGetDataLength() public void testGetDataLength()
throws StunException throws StunException
{ {
int expectedReturn = msgFixture.REASON_PHRASE.getBytes().length int expectedReturn = MsgFixture.REASON_PHRASE.getBytes().length
+ 4; //error code specific header + 4; //error code specific header
errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS);
errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setReasonPhrase(msgFixture.REASON_PHRASE); errorCodeAttribute.setReasonPhrase(MsgFixture.REASON_PHRASE);
char actualReturn = errorCodeAttribute.getDataLength(); char actualReturn = errorCodeAttribute.getDataLength();
assertEquals("data length1", expectedReturn, actualReturn); assertEquals("data length1", expectedReturn, actualReturn);
@ -177,11 +177,11 @@ public class ErrorCodeAttributeTest extends TestCase {
public void testGetErrorCode() public void testGetErrorCode()
throws StunException throws StunException
{ {
char expectedReturn = (char)(100*msgFixture.ERROR_CLASS char expectedReturn = (char)(100*MsgFixture.ERROR_CLASS
+ msgFixture.ERROR_NUMBER); + MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS);
errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER);
char actualReturn = errorCodeAttribute.getErrorCode(); char actualReturn = errorCodeAttribute.getErrorCode();
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
@ -203,14 +203,14 @@ public class ErrorCodeAttributeTest extends TestCase {
* @throws StunException java.lang.Exception if we fail * @throws StunException java.lang.Exception if we fail
*/ */
public void testSetErrorCode() throws StunException { public void testSetErrorCode() throws StunException {
char errorCode = (char)(msgFixture.ERROR_CLASS*100 + msgFixture.ERROR_NUMBER); char errorCode = (char)(MsgFixture.ERROR_CLASS*100 + MsgFixture.ERROR_NUMBER);
errorCodeAttribute.setErrorCode(errorCode); errorCodeAttribute.setErrorCode(errorCode);
assertEquals("An error class was not properly set after decoding an error code.", assertEquals("An error class was not properly set after decoding an error code.",
(int)msgFixture.ERROR_CLASS, (int)MsgFixture.ERROR_CLASS,
(int)errorCodeAttribute.getErrorClass()); (int)errorCodeAttribute.getErrorClass());
assertEquals("An error number was not properly set after decoding an error code.", assertEquals("An error number was not properly set after decoding an error code.",
(int)msgFixture.ERROR_NUMBER, (int)MsgFixture.ERROR_NUMBER,
(int)errorCodeAttribute.getErrorNumber()); (int)errorCodeAttribute.getErrorNumber());
} }

View File

@ -47,8 +47,6 @@ public class OptionalAttributeAttributeTest extends TestCase
super.tearDown(); super.tearDown();
} }
/** /**
* Test whether sample binary arrays are correctly decoded. * Test whether sample binary arrays are correctly decoded.
* @throws StunException if anything goes wrong. * @throws StunException if anything goes wrong.

View File

@ -26,7 +26,8 @@ public class SoftwareAttributeTest extends TestCase
(byte)(SoftwareAttribute.SOFTWARE>>8), (byte)(SoftwareAttribute.SOFTWARE>>8),
(byte)(SoftwareAttribute.SOFTWARE & 0x00FF), (byte)(SoftwareAttribute.SOFTWARE & 0x00FF),
0, (byte)softwareValue.length(), 0, (byte)softwareValue.length(),
't', 'u', 'r', 'n', 's', 'e', 'r','v', 'e', 'r', '.', 'o', 'r', 'g', 0x00, 0x00}; 't', 'u', 'r', 'n', 's', 'e', 'r','v', 'e', 'r', '.', 'o', 'r', 'g',
0x00, 0x00};
protected void setUp() throws Exception protected void setUp() throws Exception
{ {

View File

@ -12,15 +12,23 @@ import java.util.*;
import org.ice4j.*; import org.ice4j.*;
public class UnknownAttributesAttributeTest extends TestCase { /**
* Tests the UNKNOWN attribute class.
*
* @author Emil Ivov
*/
public class UnknownAttributesAttributeTest extends TestCase
{
private UnknownAttributesAttribute unknownAttributesAttribute = null; private UnknownAttributesAttribute unknownAttributesAttribute = null;
private MsgFixture binMessagesFixture; private MsgFixture binMessagesFixture;
public UnknownAttributesAttributeTest(String name) { public UnknownAttributesAttributeTest(String name)
{
super(name); super(name);
} }
protected void setUp() throws Exception { protected void setUp() throws Exception
{
super.setUp(); super.setUp();
unknownAttributesAttribute = new UnknownAttributesAttribute(); unknownAttributesAttribute = new UnknownAttributesAttribute();
binMessagesFixture = new MsgFixture(); binMessagesFixture = new MsgFixture();
@ -28,7 +36,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
binMessagesFixture.setUp(); binMessagesFixture.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception
{
unknownAttributesAttribute = null; unknownAttributesAttribute = null;
binMessagesFixture.tearDown(); binMessagesFixture.tearDown();
@ -40,7 +49,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Verify the the constructed object has the correct (UNKNOWN-ATTRIBUTES) * Verify the the constructed object has the correct (UNKNOWN-ATTRIBUTES)
* type. * type.
*/ */
public void testUnknownAttributesAttribute() { public void testUnknownAttributesAttribute()
{
unknownAttributesAttribute = new UnknownAttributesAttribute(); unknownAttributesAttribute = new UnknownAttributesAttribute();
assertEquals("UnknownAttributesAttribute() did not properly set the " assertEquals("UnknownAttributesAttribute() did not properly set the "
@ -55,7 +65,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* and that a second addition of the same id would not augment the attribute * and that a second addition of the same id would not augment the attribute
* count. * count.
*/ */
public void testAddAttributeID() { public void testAddAttributeID()
{
char attributeID = 0x22; // unknown attribute id char attributeID = 0x22; // unknown attribute id
unknownAttributesAttribute.addAttributeID(attributeID); unknownAttributesAttribute.addAttributeID(attributeID);
@ -85,7 +96,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Tests whether a sample binary array is properly decoded. * Tests whether a sample binary array is properly decoded.
* @throws StunException if anything goes wrong. * @throws StunException if anything goes wrong.
*/ */
public void testDecodeAttributeBody() throws StunException { public void testDecodeAttributeBody() throws StunException
{
//a copy of the array in the fixture: //a copy of the array in the fixture:
byte[] attributeValue = binMessagesFixture.unknownAttsDecodeTestValue; byte[] attributeValue = binMessagesFixture.unknownAttsDecodeTestValue;
@ -126,7 +138,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Creates a new UnknownAttributesAttribute encodes it and assert equality * Creates a new UnknownAttributesAttribute encodes it and assert equality
* with binMessagesFixture.unknownAttsEncodeExpectedResult. * with binMessagesFixture.unknownAttsEncodeExpectedResult.
*/ */
public void testEncode() { public void testEncode()
{
byte[] expectedReturn = binMessagesFixture.unknownAttsEncodeExpectedResult; byte[] expectedReturn = binMessagesFixture.unknownAttsEncodeExpectedResult;
unknownAttributesAttribute.addAttributeID( unknownAttributesAttribute.addAttributeID(
@ -145,7 +158,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Tests the equals method against a null, a different and an identical * Tests the equals method against a null, a different and an identical
* object. * object.
*/ */
public void testEquals() { public void testEquals()
{
UnknownAttributesAttribute target = new UnknownAttributesAttribute(); UnknownAttributesAttribute target = new UnknownAttributesAttribute();
boolean expectedReturn = false; boolean expectedReturn = false;
@ -173,7 +187,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Tests that getAttribute() return the correct attribute id, preserving * Tests that getAttribute() return the correct attribute id, preserving
* entry order. * entry order.
*/ */
public void testGetAttribute() { public void testGetAttribute()
{
char expectedId1 = 20; char expectedId1 = 20;
char expectedId2 = 21; char expectedId2 = 21;
@ -194,7 +209,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Add some attributes and test whether their number is properly calculated. * Add some attributes and test whether their number is properly calculated.
* Tests duplicate id handling as well. * Tests duplicate id handling as well.
*/ */
public void testGetAttributeCount() { public void testGetAttributeCount()
{
int expectedReturn = 5; int expectedReturn = 5;
unknownAttributesAttribute.addAttributeID((char)21); unknownAttributesAttribute.addAttributeID((char)21);
@ -213,7 +229,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Same as testGetAttributeID, only attribute attributes are extracted * Same as testGetAttributeID, only attribute attributes are extracted
* through the getAttributes()'s iterator. * through the getAttributes()'s iterator.
*/ */
public void testGetAttributes() { public void testGetAttributes()
{
char expectedId1 = 20; char expectedId1 = 20;
char expectedId2 = 21; char expectedId2 = 21;
@ -239,7 +256,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
* Test is first performed for an odd number of attributes and then again * Test is first performed for an odd number of attributes and then again
* (after adding another attribute id). Both results should be the same. * (after adding another attribute id). Both results should be the same.
*/ */
public void testGetDataLength() { public void testGetDataLength()
{
char expectedReturn = 8; char expectedReturn = 8;
unknownAttributesAttribute.addAttributeID((char)20); unknownAttributesAttribute.addAttributeID((char)20);
@ -261,7 +279,8 @@ public class UnknownAttributesAttributeTest extends TestCase {
/** /**
* Tests whether getName returns a relevant name. * Tests whether getName returns a relevant name.
*/ */
public void testGetName() { public void testGetName()
{
String expectedReturn = "UNKNOWN-ATTRIBUTES"; String expectedReturn = "UNKNOWN-ATTRIBUTES";
String actualReturn = unknownAttributesAttribute.getName(); String actualReturn = unknownAttributesAttribute.getName();
assertEquals("getName() return", expectedReturn, actualReturn); assertEquals("getName() return", expectedReturn, actualReturn);

View File

@ -11,31 +11,33 @@ import junit.framework.*;
import org.ice4j.*; import org.ice4j.*;
import org.ice4j.attribute.*; import org.ice4j.attribute.*;
public class MessageFactoryTest extends TestCase { public class MessageFactoryTest extends TestCase
private MessageFactory messageFactory = null; {
private MsgFixture msgFixture; private MsgFixture msgFixture;
public MessageFactoryTest(String name) { public MessageFactoryTest(String name)
{
super(name); super(name);
} }
protected void setUp() throws Exception { protected void setUp() throws Exception
{
super.setUp(); super.setUp();
messageFactory = new MessageFactory();
msgFixture = new MsgFixture(); msgFixture = new MsgFixture();
msgFixture.setUp(); msgFixture.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception
messageFactory = null; {
msgFixture.tearDown(); msgFixture.tearDown();
msgFixture = null; msgFixture = null;
super.tearDown(); super.tearDown();
} }
public void testCreateBindingErrorResponse() throws StunException { public void testCreateBindingErrorResponse() throws StunException
{
char errorCode = 400; char errorCode = 400;
Response expectedReturn = new Response(); Response expectedReturn = new Response();
@ -46,11 +48,12 @@ public class MessageFactoryTest extends TestCase {
expectedReturn.addAttribute(errorCodeAtt); expectedReturn.addAttribute(errorCodeAtt);
Message actualReturn Message actualReturn
= messageFactory.createBindingErrorResponse(errorCode); = MessageFactory.createBindingErrorResponse(errorCode);
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
} }
public void testCreateBindingErrorResponse1() throws StunException { public void testCreateBindingErrorResponse1() throws StunException
{
char errorCode = 400; char errorCode = 400;
String reasonPhrase = "Bad Request"; String reasonPhrase = "Bad Request";
@ -61,7 +64,7 @@ public class MessageFactoryTest extends TestCase {
.createErrorCodeAttribute(errorCode, reasonPhrase); .createErrorCodeAttribute(errorCode, reasonPhrase);
expectedReturn.addAttribute(errorCodeAtt); expectedReturn.addAttribute(errorCodeAtt);
Message actualReturn = messageFactory Message actualReturn = MessageFactory
.createBindingErrorResponse(errorCode, reasonPhrase); .createBindingErrorResponse(errorCode, reasonPhrase);
assertEquals("Failed to create an error code attribute.", assertEquals("Failed to create an error code attribute.",
expectedReturn, actualReturn); expectedReturn, actualReturn);
@ -92,7 +95,7 @@ public class MessageFactoryTest extends TestCase {
expectedReturn.addAttribute(unknownAtts); expectedReturn.addAttribute(unknownAtts);
//create the same message using the factory //create the same message using the factory
Message actualReturn = messageFactory Message actualReturn = MessageFactory
.createBindingErrorResponseUnknownAttributes(unknownAttributes); .createBindingErrorResponseUnknownAttributes(unknownAttributes);
//compare //compare
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
@ -121,7 +124,7 @@ public class MessageFactoryTest extends TestCase {
} }
expectedReturn.addAttribute(unknownAtts); expectedReturn.addAttribute(unknownAtts);
Message actualReturn = messageFactory Message actualReturn = MessageFactory
.createBindingErrorResponseUnknownAttributes( .createBindingErrorResponseUnknownAttributes(
reasonPhrase, unknownAttributes); reasonPhrase, unknownAttributes);
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
@ -137,7 +140,7 @@ public class MessageFactoryTest extends TestCase {
msgFixture.CHANGE_IP_FLAG_1, msgFixture.CHANGE_PORT_FLAG_1); msgFixture.CHANGE_IP_FLAG_1, msgFixture.CHANGE_PORT_FLAG_1);
bindingRequest.addAttribute(changeRequest); bindingRequest.addAttribute(changeRequest);
*/ */
Request actualReturn = messageFactory.createBindingRequest(); Request actualReturn = MessageFactory.createBindingRequest();
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
} }
@ -148,37 +151,37 @@ public class MessageFactoryTest extends TestCase {
bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute( Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute(
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
bindingResponse.addAttribute(mappedAddress); bindingResponse.addAttribute(mappedAddress);
Attribute sourceAddress = AttributeFactory.createSourceAddressAttribute( Attribute sourceAddress = AttributeFactory.createSourceAddressAttribute(
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2,
msgFixture.ADDRESS_ATTRIBUTE_PORT_2, MsgFixture.ADDRESS_ATTRIBUTE_PORT_2,
Transport.UDP)); Transport.UDP));
bindingResponse.addAttribute(sourceAddress); bindingResponse.addAttribute(sourceAddress);
Attribute changedAddress = AttributeFactory. Attribute changedAddress = AttributeFactory.
createChangedAddressAttribute( createChangedAddressAttribute(
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3,
msgFixture.ADDRESS_ATTRIBUTE_PORT_3, MsgFixture.ADDRESS_ATTRIBUTE_PORT_3,
Transport.UDP)); Transport.UDP));
bindingResponse.addAttribute(changedAddress); bindingResponse.addAttribute(changedAddress);
Message expectedReturn = bindingResponse; Message expectedReturn = bindingResponse;
Message actualReturn = messageFactory.create3482BindingResponse( Message actualReturn = MessageFactory.create3482BindingResponse(
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP), Transport.UDP),
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2,
msgFixture.ADDRESS_ATTRIBUTE_PORT_2, MsgFixture.ADDRESS_ATTRIBUTE_PORT_2,
Transport.UDP), Transport.UDP),
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3,
msgFixture.ADDRESS_ATTRIBUTE_PORT_3, MsgFixture.ADDRESS_ATTRIBUTE_PORT_3,
Transport.UDP)); Transport.UDP));
assertEquals("return value", expectedReturn, actualReturn); assertEquals("return value", expectedReturn, actualReturn);
} }

View File

@ -14,7 +14,8 @@ import org.ice4j.*;
import org.ice4j.attribute.*; import org.ice4j.attribute.*;
import org.ice4j.stack.*; import org.ice4j.stack.*;
public class MessageTest extends TestCase { public class MessageTest extends TestCase
{
private Message bindingRequest = null; private Message bindingRequest = null;
private Message bindingResponse = null; private Message bindingResponse = null;
@ -31,7 +32,8 @@ public class MessageTest extends TestCase {
*/ */
private StunStack stunStack; private StunStack stunStack;
protected void setUp() throws Exception { protected void setUp() throws Exception
{
super.setUp(); super.setUp();
msgFixture = new MsgFixture(); msgFixture = new MsgFixture();
@ -44,9 +46,9 @@ public class MessageTest extends TestCase {
bindingRequest.setMessageType(Message.BINDING_REQUEST); bindingRequest.setMessageType(Message.BINDING_REQUEST);
changeRequest = AttributeFactory.createChangeRequestAttribute( changeRequest = AttributeFactory.createChangeRequestAttribute(
msgFixture.CHANGE_IP_FLAG_1, msgFixture.CHANGE_PORT_FLAG_1); MsgFixture.CHANGE_IP_FLAG_1, MsgFixture.CHANGE_PORT_FLAG_1);
bindingRequest.addAttribute(changeRequest); bindingRequest.addAttribute(changeRequest);
bindingRequest.setTransactionID(msgFixture.TRANSACTION_ID); bindingRequest.setTransactionID(MsgFixture.TRANSACTION_ID);
//binding response //binding response
bindingResponse = new Response(); bindingResponse = new Response();
@ -54,26 +56,26 @@ public class MessageTest extends TestCase {
mappedAddress = AttributeFactory.createMappedAddressAttribute( mappedAddress = AttributeFactory.createMappedAddressAttribute(
new TransportAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
msgFixture.ADDRESS_ATTRIBUTE_PORT, MsgFixture.ADDRESS_ATTRIBUTE_PORT,
Transport.UDP)); Transport.UDP));
bindingResponse.addAttribute(mappedAddress); bindingResponse.addAttribute(mappedAddress);
sourceAddress = AttributeFactory.createSourceAddressAttribute( sourceAddress = AttributeFactory.createSourceAddressAttribute(
new TransportAddress( new TransportAddress(
msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2,
msgFixture.ADDRESS_ATTRIBUTE_PORT_2, MsgFixture.ADDRESS_ATTRIBUTE_PORT_2,
Transport.UDP)); Transport.UDP));
bindingResponse.addAttribute(sourceAddress); bindingResponse.addAttribute(sourceAddress);
changedAddress = AttributeFactory.createChangedAddressAttribute( changedAddress = AttributeFactory.createChangedAddressAttribute(
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3,
msgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP)); MsgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP));
bindingResponse.addAttribute(changedAddress); bindingResponse.addAttribute(changedAddress);
bindingResponse.setTransactionID(msgFixture.TRANSACTION_ID); bindingResponse.setTransactionID(MsgFixture.TRANSACTION_ID);
} }
protected void tearDown() throws Exception protected void tearDown() throws Exception
@ -101,8 +103,8 @@ public class MessageTest extends TestCase {
* *
* @throws StunException java.lang.Exception if we fail * @throws StunException java.lang.Exception if we fail
*/ */
public void testAddAndGetAttribute() throws StunException
public void testAddAndGetAttribute() throws StunException { {
Response message = new Response(); Response message = new Response();
message.setMessageType(Message.BINDING_SUCCESS_RESPONSE); message.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
@ -157,7 +159,7 @@ public class MessageTest extends TestCase {
* Encodes a bindingRequest and then a binding response and checks whether * Encodes a bindingRequest and then a binding response and checks whether
* they match the corresponding binary arrays. * they match the corresponding binary arrays.
* *
* @throws StunException java.lang.Exception if we fail * @throws Exception java.lang.Exception if we fail
*/ */
public void testDecode() public void testDecode()
throws Exception throws Exception
@ -238,7 +240,8 @@ public class MessageTest extends TestCase {
/** /**
* Tests whether attributes are properly counted * Tests whether attributes are properly counted
*/ */
public void testGetAttributeCount() { public void testGetAttributeCount()
{
int expectedReturn = 1; int expectedReturn = 1;
int actualReturn = bindingRequest.getAttributeCount(); int actualReturn = bindingRequest.getAttributeCount();
assertEquals("getAttributeCount failed for a bindingRequest", assertEquals("getAttributeCount failed for a bindingRequest",
@ -252,7 +255,8 @@ public class MessageTest extends TestCase {
/** /**
* Test whether attributes are properly removed. * Test whether attributes are properly removed.
*/ */
public void testRemoveAttribute() { public void testRemoveAttribute()
{
bindingRequest.removeAttribute(changeRequest.getAttributeType()); bindingRequest.removeAttribute(changeRequest.getAttributeType());

View File

@ -230,7 +230,6 @@ public class StunAddressDiscovererTest
assertEquals( assertEquals(
"The StunAddressDiscoverer failed for a no-udp environment.", "The StunAddressDiscoverer failed for a no-udp environment.",
expectedReturn, actualReturn); expectedReturn, actualReturn);
} }
/** /**

View File

@ -27,7 +27,8 @@ import org.ice4j.stack.*;
* <p>Company: Net Research Team, Louis Pasteur University</p> * <p>Company: Net Research Team, Louis Pasteur University</p>
* @author Emil Ivov * @author Emil Ivov
*/ */
public class StunAddressDiscovererTest_v4v6 extends TestCase { public class StunAddressDiscovererTest_v4v6 extends TestCase
{
private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v6 private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v6
= null; = null;
private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v4 private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v4

View File

@ -22,7 +22,8 @@ import org.ice4j.stack.*;
* <p>Company: Net Research Team, Louis Pasteur University</p> * <p>Company: Net Research Team, Louis Pasteur University</p>
* @author Emil Ivov * @author Emil Ivov
*/ */
public class StunAddressDiscovererTest_v6 extends TestCase { public class StunAddressDiscovererTest_v6 extends TestCase
{
private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer = null; private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer = null;
private TransportAddress discovererAddress private TransportAddress discovererAddress
= new TransportAddress("::1", 16555, Transport.UDP); = new TransportAddress("::1", 16555, Transport.UDP);
@ -290,9 +291,4 @@ public class StunAddressDiscovererTest_v6 extends TestCase {
expectedReturn, actualReturn); expectedReturn, actualReturn);
} }
} }