Exemple #1
0
//export Java_io_v_v23_context_VContext_nativeCreate
func Java_io_v_v23_context_VContext_nativeCreate(jenv *C.JNIEnv, jVContext C.jclass) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _ := context.RootContext()
	jContext, err := JavaContext(env, ctx, nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jContext))
}
Exemple #2
0
func TestMessage(t *testing.T) {
	s := &message.Setup{
		Versions: version.RPCVersionRange{
			Min: version.RPCVersion10,
			Max: version.RPCVersion14,
		},
		PeerNaClPublicKey: &[32]byte{
			1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
			11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
			21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
			31, 32},
		Mtu:          999,
		SharedTokens: 1001,
	}

	ctx, cancel := context.RootContext()
	defer cancel()
	inputGo, err := message.Append(ctx, s, nil)
	if err != nil {
		t.Fatal(err)
	}

	inputC, err := Write(s)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Equal(inputGo, inputC) {
		t.Error("Go write and C write differ")
		t.Log("go ->", inputGo)
		t.Log("c  ->", inputC)
	}

	m2, err := Read(inputGo)
	if err != nil {
		t.Fatal(err)
	}

	if su, ok := m2.(*message.Setup); ok {
		if !bytes.Equal(su.PeerNaClPublicKey[:], s.PeerNaClPublicKey[:]) {
			t.Error("PeerNaClPublicKey does not match")
		}
	} else {
		t.Errorf("wrong type: %T", m2)
	}
}