package setqq.saki.com.sqv9;

import com.saki.encode.Canvart;
import com.saki.plugin.dictionary.TempPseudoCode;

import org.junit.Test;

import java.util.Random;
import java.util.zip.CRC32;

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        long seed = Canvart.toUnsignedInt32(new Random().nextLong());
        System.out.println("种子:"+seed);
        byte[] key = new byte[16];
        new Random(seed).nextBytes(key);
        System.out.println("密匙:"+Canvart.Bytes2Hex(key));
        byte[] hex = Canvart.Long2Bytes(seed,4);
        System.out.println("hex:"+Canvart.Bytes2Hex(hex));

        long seed2 = Canvart.Bytes2UnsignedInt32(hex);
        System.out.println("reSeed;"+seed2);
        byte[] key2 = new byte[16];
        new Random(seed2).nextBytes(key2);
        System.out.println("密匙:"+Canvart.Bytes2Hex(key2));
//        Global.qq = 1465711308;
//        Key.KSESSION = new byte[16];
//
//        byte[] bin = new VisitorSvc.ReqFavorite(123,302652034).toByteArray();//new FriendList.GetTroopListReqV2(123).toByteArray();
//        System.out.println(Canvart.Bytes2Hex(bin));
//        String s = new TempPseudoCode(null,1,2,3,"4","5","$调用 123 123$",null).executeCode("$调用 123 123$");
//        System.out.println(s);
//        ScriptUtil.checkScriptPublicLibraryFile();
//        assertEquals(4, 2 + 2);
//        V8 v8 = V8.createV8Runtime();
//        api a=new api();
//        V8Object obj = new V8Object(v8);
//        v8.add("api",obj);
//        obj.registerJavaMethod(a,"getTestMsg","getTextMsg",new Class<?>[]{});
//        obj.registerJavaMethod(a,"log_red","log_red",new Class<?>[]{String.class});
//        obj.release();
//        v8.executeScript("var s = api.getTextMsg();api.log_red(s);");

//        Context c = Context.enter();
//        ScriptableObject o = c.initStandardObjects();
//        String js = "Script = {id:'123',info:'Demo',handleMessage:function(a){var i = Number(a.getCode());a.log(i)}}";
//        Object obj = c.evaluateString(o,js,"Test",1,null);
//        NativeObject no = (NativeObject) obj;
//        System.out.println(no.get("id",o).toString());
//        System.out.println(no.get("info",o).toString());
//        System.out.println(no.get("ui",o) == UniqueTag.NOT_FOUND);
//        NativeFunction function = (NativeFunction) no.get("handleMessage",o);
//        ScriptableObject.defineClass(o,api.class);
//        api a = (api)c.newObject(o,"api");
//        function.call(c,o,o,new Object[]{a});
    }
}