001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018 019 package org.apache.commons.codec.binary; 020 021 import static org.junit.Assert.assertFalse; 022 import static org.junit.Assert.assertNotNull; 023 import static org.junit.Assert.assertTrue; 024 025 import org.junit.Before; 026 import org.junit.Test; 027 028 public class BaseNCodecTest { 029 030 BaseNCodec codec; 031 032 @Before 033 public void setUp() { 034 codec = new BaseNCodec(0, 0, 0, 0) { 035 @Override 036 protected boolean isInAlphabet(final byte b) { 037 return b=='O' || b == 'K'; // allow OK 038 } 039 040 @Override 041 void encode(final byte[] pArray, final int i, final int length, final Context context) { 042 } 043 044 @Override 045 void decode(final byte[] pArray, final int i, final int length, final Context context) { 046 } 047 }; 048 } 049 050 @Test 051 public void testBaseNCodec() { 052 assertNotNull(codec); 053 } 054 055 // @Test 056 // public void testHasData() { 057 // fail("Not yet implemented"); 058 // } 059 // 060 // @Test 061 // public void testAvail() { 062 // fail("Not yet implemented"); 063 // } 064 // 065 // @Test 066 // public void testEnsureBufferSize() { 067 // fail("Not yet implemented"); 068 // } 069 // 070 // @Test 071 // public void testReadResults() { 072 // fail("Not yet implemented"); 073 // } 074 // 075 @Test 076 public void testIsWhiteSpace() { 077 assertTrue(BaseNCodec.isWhiteSpace((byte) ' ')); 078 assertTrue(BaseNCodec.isWhiteSpace((byte) '\n')); 079 assertTrue(BaseNCodec.isWhiteSpace((byte) '\r')); 080 assertTrue(BaseNCodec.isWhiteSpace((byte) '\t')); 081 } 082 // 083 // @Test 084 // public void testEncodeObject() { 085 // fail("Not yet implemented"); 086 // } 087 // 088 // @Test 089 // public void testEncodeToString() { 090 // fail("Not yet implemented"); 091 // } 092 // 093 // @Test 094 // public void testDecodeObject() { 095 // fail("Not yet implemented"); 096 // } 097 // 098 // @Test 099 // public void testDecodeString() { 100 // fail("Not yet implemented"); 101 // } 102 // 103 // @Test 104 // public void testDecodeByteArray() { 105 // fail("Not yet implemented"); 106 // } 107 // 108 // @Test 109 // public void testEncodeByteArray() { 110 // fail("Not yet implemented"); 111 // } 112 // 113 // @Test 114 // public void testEncodeAsString() { 115 // fail("Not yet implemented"); 116 // } 117 // 118 // @Test 119 // public void testEncodeByteArrayIntInt() { 120 // fail("Not yet implemented"); 121 // } 122 // 123 // @Test 124 // public void testDecodeByteArrayIntInt() { 125 // fail("Not yet implemented"); 126 // } 127 // 128 @Test 129 public void testIsInAlphabetByte() { 130 assertFalse(codec.isInAlphabet((byte) 0)); 131 assertFalse(codec.isInAlphabet((byte) 'a')); 132 assertTrue(codec.isInAlphabet((byte) 'O')); 133 assertTrue(codec.isInAlphabet((byte) 'K')); 134 } 135 136 @Test 137 public void testIsInAlphabetByteArrayBoolean() { 138 assertTrue(codec.isInAlphabet(new byte[]{}, false)); 139 assertTrue(codec.isInAlphabet(new byte[]{'O'}, false)); 140 assertFalse(codec.isInAlphabet(new byte[]{'O',' '}, false)); 141 assertFalse(codec.isInAlphabet(new byte[]{' '}, false)); 142 assertTrue(codec.isInAlphabet(new byte[]{}, true)); 143 assertTrue(codec.isInAlphabet(new byte[]{'O'}, true)); 144 assertTrue(codec.isInAlphabet(new byte[]{'O',' '}, true)); 145 assertTrue(codec.isInAlphabet(new byte[]{' '}, true)); 146 } 147 148 @Test 149 public void testIsInAlphabetString() { 150 assertTrue(codec.isInAlphabet("OK")); 151 assertTrue(codec.isInAlphabet("O=K= \t\n\r")); 152 } 153 154 @Test 155 public void testContainsAlphabetOrPad() { 156 assertFalse(codec.containsAlphabetOrPad(null)); 157 assertFalse(codec.containsAlphabetOrPad(new byte[]{})); 158 assertTrue(codec.containsAlphabetOrPad("OK".getBytes())); 159 assertTrue(codec.containsAlphabetOrPad("OK ".getBytes())); 160 assertFalse(codec.containsAlphabetOrPad("ok ".getBytes())); 161 assertTrue(codec.containsAlphabetOrPad(new byte[]{codec.PAD})); 162 } 163 164 // @Test 165 // public void testGetEncodedLength() { 166 // fail("Not yet implemented"); 167 // } 168 }