ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBitmaskTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14 
15  public function setUp()
16  {
17  chdir('../../../');
18  require_once './Services/Utilities/classes/class.ilBitmask.php';
19  }
20 
21  public function tearDown()
22  {
23 
24  }
25 
26  public function test_Constructor()
27  {
28  // Arrange
29  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
30  $bitmask = 0;
31  $settings = new ilBitmask($definition, $bitmask);
32 
33  // Act
34 
35  // Assert
36  // No exception - good
37  }
38 
39  public function test_getSetButterflyPattern()
40  {
41  // Arrange
42  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
43  $bitmask = 0;
44  $settings = new ilBitmask($definition, $bitmask);
45 
46  // Act
47  $settings->set('1bit', true);
48  $settings->set('2bit', false);
49  $settings->set('4bit', true);
50  $settings->set('8bit', false);
51  $settings->set('16bit', true);
52  $settings->set('32bit', false);
53  $settings->set('64bit', true);
54  $settings->set('128bit', false);
55 
56  // Assert
57  $this->assertTrue($settings->get('1bit'));
58  $this->assertFalse($settings->get('2bit'));
59  $this->assertTrue($settings->get('4bit'));
60  $this->assertFalse($settings->get('8bit'));
61  $this->assertTrue($settings->get('16bit'));
62  $this->assertFalse($settings->get('32bit'));
63  $this->assertTrue($settings->get('64bit'));
64  $this->assertFalse($settings->get('128bit'));
65  }
66 
67  public function test_getSetallTrue()
68  {
69  // Arrange
70  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
71  $bitmask = 0;
72  $settings = new ilBitmask($definition, $bitmask);
73 
74  // Act
75  $settings->set('1bit', true);
76  $settings->set('2bit', true);
77  $settings->set('4bit', true);
78  $settings->set('8bit', true);
79  $settings->set('16bit', true);
80  $settings->set('32bit', true);
81  $settings->set('64bit', true);
82  $settings->set('128bit', true);
83 
84  // Assert
85  $this->assertTrue($settings->get('1bit'));
86  $this->assertTrue($settings->get('2bit'));
87  $this->assertTrue($settings->get('4bit'));
88  $this->assertTrue($settings->get('8bit'));
89  $this->assertTrue($settings->get('16bit'));
90  $this->assertTrue($settings->get('32bit'));
91  $this->assertTrue($settings->get('64bit'));
92  $this->assertTrue($settings->get('128bit'));
93  }
94 
95  public function test_getSetallFalse()
96  {
97  // Arrange
98  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
99  $bitmask = 0;
100  $settings = new ilBitmask($definition, $bitmask);
101 
102  // Act
103  $settings->set('1bit', false);
104  $settings->set('2bit', false);
105  $settings->set('4bit', false);
106  $settings->set('8bit', false);
107  $settings->set('16bit', false);
108  $settings->set('32bit', false);
109  $settings->set('64bit', false);
110  $settings->set('128bit', false);
111 
112  // Assert
113  $this->assertFalse($settings->get('1bit'));
114  $this->assertFalse($settings->get('2bit'));
115  $this->assertFalse($settings->get('4bit'));
116  $this->assertFalse($settings->get('8bit'));
117  $this->assertFalse($settings->get('16bit'));
118  $this->assertFalse($settings->get('32bit'));
119  $this->assertFalse($settings->get('64bit'));
120  $this->assertFalse($settings->get('128bit'));
121  }
122 
124  {
125  // Arrange
126  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
127  $bitmask = 0;
128  $settings = new ilBitmask($definition, $bitmask);
129 
130  // Act - Set Butterfly Pattern
131  $settings->set('1bit', false);
132  $settings->set('2bit', true);
133  $settings->set('4bit', false);
134  $settings->set('8bit', true);
135  $settings->set('16bit', false);
136  $settings->set('32bit', true);
137  $settings->set('64bit', false);
138  $settings->set('128bit', true);
139 
140  // Act - Invert Butterfly Pattern
141  $settings->set('1bit', true);
142  $settings->set('2bit', false);
143  $settings->set('4bit', true);
144  $settings->set('8bit', false);
145  $settings->set('16bit', true);
146  $settings->set('32bit', false);
147  $settings->set('64bit', true);
148  $settings->set('128bit', false);
149 
150  // Assert
151  $this->assertTrue($settings->get('1bit'));
152  $this->assertFalse($settings->get('2bit'));
153  $this->assertTrue($settings->get('4bit'));
154  $this->assertFalse($settings->get('8bit'));
155  $this->assertTrue($settings->get('16bit'));
156  $this->assertFalse($settings->get('32bit'));
157  $this->assertTrue($settings->get('64bit'));
158  $this->assertFalse($settings->get('128bit'));
159  }
160 
164  public function test_setIllegalSetting()
165  {
166  // Arrange
167  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
168  $bitmask = 0;
169  $settings = new ilBitmask($definition, $bitmask);
170 
171  // Act
172  $settings->set('Günther', true);
173  }
174 
178  public function test_getIllegalSetting()
179  {
180  // Arrange
181  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
182  $bitmask = 0;
183  $settings = new ilBitmask($definition, $bitmask);
184 
185  // Act
186  $settings->get('Günther');
187  }
188 
189  public function test_getBitmask()
190  {
191  // Arrange
192  $definition = array('1bit','2bit','4bit','8bit','16bit','32bit','64bit','128bit');
193  $bitmask = 0;
194  $settings = new ilBitmask($definition, $bitmask);
195 
196  // Act
197  $settings->set('1bit', true);
198  $settings->set('2bit', false);
199  $settings->set('4bit', true);
200  $settings->set('8bit', false);
201  $settings->set('16bit', true);
202  $settings->set('32bit', false);
203  $settings->set('64bit', true);
204  $settings->set('128bit', false);
205  $expected = 85;
206 
207  // Assert
208  $this->assertEquals( $expected, $settings->getBitmask() );
209 
210  }
211 }