001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd;
019:
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: /**
024: * @author mog
025: * @version $Id: BytesTest.java 781 2004-11-09 19:00:01Z mog $
026: */
027: public class BytesTest extends TestCase {
028: public BytesTest() {
029: super ();
030: }
031:
032: public BytesTest(String fName) {
033: super (fName);
034: }
035:
036: public static TestSuite suite() {
037: return new TestSuite(BytesTest.class);
038: }
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: }
043:
044: protected void tearDown() throws Exception {
045: super .tearDown();
046: }
047:
048: public void testFormat50KB() {
049: assertEquals("50.0KB", Bytes
050: .formatBytes(Bytes.KILO * 50, false));
051: }
052:
053: public void testFormat50KiB() {
054: assertEquals("50.0KiB", Bytes
055: .formatBytes(Bytes.KIBI * 50, true));
056: }
057:
058: public void testFormatByte() {
059: assertEquals("123B", Bytes.formatBytes(123, false));
060: }
061:
062: public void testFormatGB() {
063: assertEquals("1.0GB", Bytes.formatBytes(Bytes.GIGA, false));
064: }
065:
066: public void testFormatGiB() {
067: assertEquals("1.0GiB", Bytes.formatBytes(Bytes.GIBI, true));
068: }
069:
070: public void testFormatKB() {
071: assertEquals("1.0KB", Bytes.formatBytes(Bytes.KILO, false));
072: }
073:
074: public void testFormatKiB() {
075: assertEquals("1.0KiB", Bytes.formatBytes(Bytes.KIBI, true));
076: }
077:
078: public void testFormatMB() {
079: assertEquals("1.0MB", Bytes.formatBytes(Bytes.MEGA, false));
080: }
081:
082: public void testFormatMib() {
083: assertEquals("1.0MiB", Bytes.formatBytes(Bytes.MEBI, true));
084: }
085:
086: public void testFormatTB() {
087: assertEquals("1.0TB", Bytes.formatBytes(Bytes.TERRA, false));
088: }
089:
090: public void testFormatTiB() {
091: assertEquals("1.0TiB", Bytes.formatBytes(Bytes.TEBI, true));
092: }
093:
094: public void testParse1GB() {
095: assertEquals(Bytes.GIGA, Bytes.parseBytes("1GB"));
096: }
097:
098: public void testParse1GiB() {
099: assertEquals(Bytes.GIBI, Bytes.parseBytes("1GiB"));
100: }
101:
102: public void testParse1KB() {
103: assertEquals(Bytes.KILO, Bytes.parseBytes("1KB"));
104: }
105:
106: public void testParse1KiB() {
107: assertEquals(Bytes.KIBI, Bytes.parseBytes("1KiB"));
108: }
109:
110: public void testParse1MB() {
111: assertEquals(Bytes.MEGA, Bytes.parseBytes("1MB"));
112: }
113:
114: public void testParse1MiB() {
115: assertEquals(Bytes.MEBI, Bytes.parseBytes("1MiB"));
116: }
117:
118: public void testParse1TB() {
119: assertEquals(Bytes.TERRA, Bytes.parseBytes("1TB"));
120: }
121:
122: public void testParse1TiB() {
123: assertEquals(Bytes.TEBI, Bytes.parseBytes("1TiB"));
124: }
125:
126: public void testParseByte() {
127: assertEquals(123, Bytes.parseBytes("123"));
128: }
129: }
|