22
33import android .util .Log ;
44
5- import com .unity3d .ads .log .DeviceLog ;
65import com .unity3d .ads .misc .Utilities ;
76
87import org .json .JSONObject ;
98import org .junit .Test ;
109
10+ import java .io .ByteArrayInputStream ;
11+
1112import static org .junit .Assert .assertEquals ;
1213
1314public class UtilitiesTest {
@@ -63,4 +64,24 @@ public void testMergeJson() throws Exception {
6364
6465 assertEquals ("Incorrect 'override' value" , "primary" , testObject .getString ("override" ));
6566 }
67+
68+ @ Test
69+ public void testSha256Stream () throws Exception {
70+ assertHash (10240 , "88278aa898609ddff1418ac55011741c563d3e3cd0d70bc07c407a3a882d8004" );
71+ assertHash (8192 , "9b4cd9b4977133275a2fc9ab7ec25101cfe5273808837a2490437871614f56ab" );
72+ assertHash (2048 , "b07cbef157ea4e7bf4e233f3e766c668bf93578e9954c64fcd6ec3d9f4c6f4f4" );
73+ assertHash (1 , "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9" );
74+ assertHash (0 , "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" );
75+ }
76+
77+ public void assertHash (int size , String sha256 ) throws Exception {
78+ byte [] buffer = new byte [size ];
79+
80+ for (int i = 0 ; i < buffer .length ; i ++ ) {
81+ buffer [i ] = (byte )((byte )'0' + (byte )(i % 9 ));
82+ }
83+
84+ ByteArrayInputStream inputStream = new ByteArrayInputStream (buffer );
85+ assertEquals (String .format ("Hash for buffer size %d is wrong" , size ), sha256 , Utilities .Sha256 (inputStream ));
86+ }
6687}
0 commit comments