|
| 1 | +package org.bouncycastle.util.utiltest; |
| 2 | + |
| 3 | +import junit.framework.TestCase; |
| 4 | +import org.bouncycastle.bcpg.sig.PrimaryUserID; |
| 5 | + |
| 6 | +public class BytesBooleansTest |
| 7 | + extends TestCase |
| 8 | +{ |
| 9 | + public void testParseFalse() |
| 10 | + { |
| 11 | + PrimaryUserID primaryUserID = new PrimaryUserID(true, false); |
| 12 | + |
| 13 | + byte[] bFalse = primaryUserID.getData(); |
| 14 | + assertEquals(1, bFalse.length); |
| 15 | + assertEquals(0, bFalse[0]); |
| 16 | + assertFalse(primaryUserID.isPrimaryUserID()); |
| 17 | + } |
| 18 | + |
| 19 | + public void testParseTrue() |
| 20 | + { |
| 21 | + PrimaryUserID primaryUserID = new PrimaryUserID(true, true); |
| 22 | + |
| 23 | + byte[] bTrue = primaryUserID.getData(); |
| 24 | + |
| 25 | + assertEquals(1, bTrue.length); |
| 26 | + assertEquals(1, bTrue[0]); |
| 27 | + assertTrue(primaryUserID.isPrimaryUserID()); |
| 28 | + } |
| 29 | + |
| 30 | + public void testParseTooShort() |
| 31 | + { |
| 32 | + PrimaryUserID primaryUserID = new PrimaryUserID(true, false, new byte[0]); |
| 33 | + byte[] bTooShort = primaryUserID.getData(); |
| 34 | + try |
| 35 | + { |
| 36 | + primaryUserID.isPrimaryUserID(); |
| 37 | + fail("Should throw."); |
| 38 | + } |
| 39 | + catch (IllegalStateException e) |
| 40 | + { |
| 41 | + // expected. |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + public void testParseTooLong() |
| 46 | + { |
| 47 | + PrimaryUserID primaryUserID = new PrimaryUserID(true, false, new byte[42]); |
| 48 | + byte[] bTooLong = primaryUserID.getData(); |
| 49 | + |
| 50 | + try |
| 51 | + { |
| 52 | + primaryUserID.isPrimaryUserID(); |
| 53 | + fail("Should throw."); |
| 54 | + } |
| 55 | + catch (IllegalStateException e) |
| 56 | + { |
| 57 | + // expected. |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments