aboutsummaryrefslogtreecommitdiff
path: root/mobileapp/src/smoots/udesign/packet/.svn/text-base/ServerToClientPacketTest.java.svn-base
blob: 85c36f03dc04b63460bd11a9de3202e3ddd498bd (plain)
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
package packet;

import java.util.ArrayList;
import java.util.List;

import library.User;

import org.junit.Assert;
import org.junit.Test;

/**
 * JUnit test for ServerToClientPacket.
 * @author seojin
 *
 */
public class ServerToClientPacketTest extends ServerToClientPacket{
	
	/* PROTOCOL TO Test
	Server to client
	Packet ::= AdministrativePacket | ConversationalPacket
	AdministrativePacket ::= acceptLogin | wholeUserList
	acceptLogin ::= clientID
	wholeUserList ::= (user \n)*
	ConversationalPacket ::= ConversationID  \t  actionType  \t  clientID  \n  (Message | screenName | userList)?
	actionType ::= OthersOpenConversation | OthersExitConversation | sendMessage | Invitation | screenNameChange
	userList ::= (user \n)*
	user ::= clientID \t screenName
	**clientID specifies who's source of event.
	**screenNameChange is followed by screenName
	**userList comes after Invitation.
	 */
	/**
	 * Admin type packet test
	 */
	@Test
	public void AdminTest(){
		Admin.AcceptLogin p;
		Admin.WholeUserList pp;
		ServerToClientPacket p2;
		p = new Admin.AcceptLogin(111);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));
		List<User> uList = new ArrayList<User>();
		uList.add(new User(212, "Eugene"));
		uList.add(new User(213, "Mehmet"));
		pp = new Admin.WholeUserList(uList);
		System.out.print(pp.packetToText());
		p2 = ServerToClientPacket.parsePacket(pp.packetToText());
		Assert.assertTrue(pp.packetToText().equals(p2.packetToText()));
		
	}
	/**
	 * Conversation type Test.
	 */
	@Test
	public void ConvTest(){
		Conv p;
		ServerToClientPacket p2;
		List<User> uList = new ArrayList<User>();
		uList.add(new User(212, "Eugene"));
		p = new Conv(1111, SCActionType.Invitation, 212, uList);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));

		p = new Conv(1111, SCActionType.screenNameChange, 212, "Egin", false);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));
		
		p = new Conv(1111, SCActionType.sendMessage, 212, "HI all of u guys !! \nhihihi", true);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));
		
		p = new Conv(1111, SCActionType.OthersJoinConversation, 212, "Egin", false);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));
		
		p = new Conv(1111, SCActionType.OthersExitConversation, 212, "Egin", false);
		System.out.print(p.packetToText());
		p2 = ServerToClientPacket.parsePacket(p.packetToText());
		Assert.assertTrue(p.packetToText().equals(p2.packetToText()));
		
	}
}