1 16 package org.apache.cocoon.util.test; 17 18 import java.io.File ; 19 import junit.framework.TestCase; 20 import org.apache.cocoon.util.IOUtils; 21 22 30 public class IOUtilsTestCase extends TestCase 31 { 32 33 39 public IOUtilsTestCase(String name) { 40 super(name); 41 } 42 43 44 50 public static void main(String args[]) { 51 junit.textui.TestRunner.run(IOUtilsTestCase.class); 52 } 53 54 55 61 public void testNormalizedFilename() throws Exception { 62 Object [] test_values = { 63 new String []{".", "__"}, 64 new String []{"", ""}, 65 new String []{"file://", "file_"}, 66 new String []{"/a/b/c", "a" + File.separator + "b" + File.separator + "c"}, 68 new String []{"\\a\\b\\c", "a" + File.separator + "b" + File.separator + "c"}, 69 new String []{"a/b/c", "a" + File.separator + "b" + File.separator + "c"}, 70 new String []{"a\\b\\c", "a" + File.separator + "b" + File.separator + "c"}, 71 72 new String []{"a/b/../c", "a" + File.separator + "c"}, 73 new String []{"public/final.xml", "public_" + File.separator + "final_xml"}, 74 new String []{"123", "_123"} 75 }; 76 for (int i = 0; i < test_values.length; i++) { 77 String tests[] = (String []) test_values[i]; 78 String test = tests[0]; 79 String expected = tests[1]; 80 81 String result = IOUtils.normalizedFilename(test); 82 String message = "Test " + "'" + test + "'"; 83 assertEquals(message, expected, result); 84 } 85 } 86 87 88 94 public void testGetContextFilePath() throws Exception { 95 Object [] test_values = { 96 new String []{"a", "a" + File.separator + "b", "b"}, 97 new String []{"a\\b", "a\\b" + File.separator + "c/d", "c" + File.separator + "d"}, 98 new String []{"a/b", "a/b" + File.separator + "c\\d", "c" + File.separator + "d"}, 99 }; 100 for (int i = 0; i < test_values.length; i++) { 101 String tests[] = (String []) test_values[i]; 102 String test_directory_path = tests[0]; 103 String test_file_path = tests[1]; 104 String expected = tests[2]; 105 106 String result = IOUtils.getContextFilePath(test_directory_path, test_file_path); 107 String message = "Test " + "'" + test_directory_path + "'" + ", " + 108 "'" + test_file_path + "'"; 109 assertEquals(message, expected, result); 110 } 111 } 112 113 114 120 public void testObjectToBytesBytesToObject() throws Exception { 121 String test = "test"; 122 String expected = "test"; 123 124 String message = "Test " + "'" + test + "'"; 125 126 byte[] bytes = IOUtils.objectToBytes(test); 127 String result = (String ) IOUtils.bytesToObject(bytes); 128 129 assertEquals(message, expected, result); 130 } 131 } 132 133 | Popular Tags |