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.Macs; 27 28 import java.io.DataOutputStream ; 29 import java.io.FileOutputStream ; 30 import java.io.IOException ; 31 32 42 public class MacTest extends TestCase { 43 private StringBuffer mac1 = null; 44 private StringBuffer mac2 = 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 testMac() throws Exception { 70 for (int i = 0; i < RunTest.macalg.length; i++) { 71 for (int j = 0; j < RunTest.text.length; j++) { 72 73 mac1 = Macs.generateMAC(RunTest.text[j], RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer ("password"), RunTest.alg[i][0], RunTest.macalg[i][0]); 74 mac2 = Macs.generateMAC(RunTest.text[j], RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer ("password"), RunTest.alg[i][0], RunTest.macalg[i][0]); 75 76 Assert.assertEquals(mac1.toString(), mac2.toString()); 77 } 78 } 79 } 80 81 86 public void testFileMac() throws Exception { 87 for (int i = 0; i < RunTest.macalg.length; i++) { 88 89 mac1 = Macs.generateFileMAC(RunTest.TEMPFOLDER + "readable.txt", RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer ("password"), RunTest.alg[i][0], RunTest.macalg[i][0]); 90 mac2 = Macs.generateFileMAC(RunTest.TEMPFOLDER + "readable.txt", RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer ("password"), RunTest.alg[i][0], RunTest.macalg[i][0]); 91 92 Assert.assertEquals(mac1.toString(), mac2.toString()); 93 94 } 95 } 96 } 97 | Popular Tags |