1 21 22 package net.sourceforge.jcetaglib.test; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 import net.sourceforge.jcetaglib.lib.Digesters; 27 28 import java.io.DataOutputStream ; 29 import java.io.FileOutputStream ; 30 import java.io.IOException ; 31 32 42 public class DigestTest extends TestCase { 43 private StringBuffer digest1 = null; 44 private StringBuffer digest2 = null; 45 46 51 protected void setUp() throws IOException { 52 FileOutputStream outStr = new FileOutputStream (RunTest.TEMPFOLDER + "readable.txt"); 54 DataOutputStream dataStr = new DataOutputStream (outStr); 55 56 dataStr.writeBytes("This is a readable string inside a file"); 57 58 dataStr.flush(); 59 dataStr.close(); 60 61 outStr.close(); 62 } 63 64 69 public void testDigest() throws Exception { 70 for (int i = 0; i < RunTest.digestalg.length; i++) { 71 for (int j = 0; j < RunTest.text.length; j++) { 72 digest1 = Digesters.hash(RunTest.text[j], RunTest.digestalg[i]); 73 digest2 = Digesters.hash(RunTest.text[j], RunTest.digestalg[i]); 74 75 Assert.assertEquals(digest1.toString(), digest2.toString()); 76 } 77 } 78 79 } 80 81 82 87 public void testFileDigest() throws Exception { 88 for (int i = 0; i < RunTest.digestalg.length; i++) { 89 digest1 = Digesters.hashFile(RunTest.TEMPFOLDER + "readable.txt", RunTest.digestalg[i]); 90 digest2 = Digesters.hashFile(RunTest.TEMPFOLDER + "readable.txt", RunTest.digestalg[i]); 91 92 Assert.assertEquals(digest1.toString(), digest2.toString()); 93 } 94 } 95 96 101 public void testFormDigest() throws Exception { 102 for (int i = 0; i < RunTest.digestalg.length; i++) { 103 for (int j = 0; j < RunTest.alg.length; j++) { 104 String keyfile = RunTest.TEMPFOLDER + RunTest.alg[j][0] + "_" + RunTest.alg[j][1] + ".key"; 105 digest1 = Digesters.formDigest(new StringBuffer ("field1=a&field2=b"), RunTest.digestalg[i], keyfile, new StringBuffer ("password"), RunTest.alg[j][0]); 106 digest2 = Digesters.formDigest(new StringBuffer ("field1=a&field2=b"), RunTest.digestalg[i], keyfile, new StringBuffer ("password"), RunTest.alg[j][0]); 107 108 Assert.assertEquals(digest1.toString(), digest2.toString()); 109 } 110 } 111 } 112 } 113 | Popular Tags |