View Javadoc
1   /******************************************************************************
2    * TestCookieMonster.java - Test the CookieMonster
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.4  2011/06/15 00:43:22  dick
10   * resetFIBSCookieMonster() becomes just reset().
11   * Use FIBSMessages constants, not hard coded numbers.
12   *
13   * Revision 1.3  2011/05/21 17:20:45  dick
14   * Add 253, which is the last index we know about.
15   *
16   * Revision 1.2  2011/05/21 16:21:40  dick
17   * MatchResults changed (expected) but RatingsFalse didn't change?
18   *
19   * Revision 1.1  2011/05/07 15:12:17  dick
20   * Test the CookieMonster
21   *
22   */
23  
24  /* 
25   * This program is free software: you can redistribute it and/or modify
26   * it under the terms of the GNU General Public License as published by
27   * the Free Software Foundation, either version 3 of the License, or
28   * (at your option) any later version.
29   *
30   * This program is distributed in the hope that it will be useful,
31   * but WITHOUT ANY WARRANTY; without even the implied warranty of
32   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33   * GNU General Public License for more details.
34   *
35   * You should have received a copy of the GNU General Public License
36   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
37   *
38   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
39   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
40   * 
41   */
42  package com.buckosoft.fibs.net;
43  
44  import junit.framework.TestCase;
45  
46  import org.junit.Before;
47  import org.junit.Test;
48  
49  import com.buckosoft.fibs.net.CookieMonster;
50  import com.buckosoft.fibs.net.FIBSMessages;
51  
52  /** Test the {@link com.buckosoft.fibs.net.CookieMonster}
53   * @author dick
54   * @since 2011/05/12
55   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/test/java/com/buckosoft/fibs/test/net/TestCookieMonster.java">cvs TestCookieMonster.java</a>
56  
57   */
58  public class TestCookieMonster extends TestCase implements FIBSMessages {
59  	private CookieMonster cm;
60  
61  	private final static String c20a = "WELCOME TO THE FIBS";
62  	private final static String c20b = "IT'S A VERY GOOD PLACE TO BE.";
63  	private final static String c21  = "login: ";
64  	private final static String c20c = "";
65  
66  	private final static String c1   = "1 BuckoFIBSa 1304778418 75-144-150-169-NewEngland.hfc.comcastbusiness.net";
67  	private final static String c2   = "2 BuckoFIBSa 1 1 0 0 0 0 1 1 5013 0 1 0 1 1679.40 0 1 0 1 0 UTC";
68  	private final static String c3   = "3";
69  	private final static String c3a  = "+--------------------------------------------------------------------+";
70  	private final static String c3b  = "|                                                                    |";
71  	private final static String c4   = "4";
72  	private final static String c27  = "";
73  	private final static String c5 = "5 vegas_vic - - 1 0 1956.77 22677 1 1304718118 66.108.89.80 ?CHVegas8ic________! -";
74  	private final static String c7 = "7 vegas_vic vegas_vic logs in.";
75  	private final static String c184 = "GammonBot_VIII wins a 9 point match against Mozart  10-7 .";
76  	private final static String c219 = "** You're now ready to invite or join someone.";
77  	private final static String c253 = "** Fred wanted to resign. Type 'accept' or 'reject'.";
78  	
79  
80  		
81  	@Before
82  	public void setUp() throws Exception {
83  		cm = new CookieMonster();
84  	}
85  
86  	@Test
87  	public void testSetClientConnection() {
88  		//fail("Not yet implemented");
89  	}
90  
91  	@Test
92  	public void testFIBSCookie() {
93  		assertEquals(FIBS_PreLogin, cm.fIBSCookie(c20a));
94  		assertEquals(FIBS_PreLogin, cm.fIBSCookie(c20b));
95  		assertEquals(FIBS_PreLogin, cm.fIBSCookie(c20c));
96  		assertEquals(FIBS_LoginPrompt, cm.fIBSCookie(c21));
97  		assertEquals(CLIP_WELCOME,  cm.fIBSCookie(c1));
98  		assertEquals(CLIP_OWN_INFO,  cm.fIBSCookie(c2));
99  		assertEquals(CLIP_MOTD_BEGIN,  cm.fIBSCookie(c3));
100 		assertEquals(CLIP_MOTD_BEGIN,  cm.fIBSCookie(c3a));
101 		assertEquals(CLIP_MOTD_BEGIN,  cm.fIBSCookie(c3b));
102 		assertEquals(CLIP_MOTD_END,  cm.fIBSCookie(c4));
103 		assertEquals(FIBS_Empty, cm.fIBSCookie(c27));
104 		assertEquals(CLIP_WHO_INFO,  cm.fIBSCookie(c5));
105 		assertEquals(CLIP_LOGIN,  cm.fIBSCookie(c7));
106 		assertEquals(FIBS_MatchResult, cm.fIBSCookie(c184));
107 		assertEquals(FIBS_ReadyTrue, cm.fIBSCookie(c219));
108 		assertEquals(FIBS_WantedToResign, cm.fIBSCookie(c253));
109 		
110 	}
111 
112 	@Test
113 	public void testReset() {
114 		cm.reset();
115 	}
116 }