Adding upstream version 0.0~git20250520.a1d9079+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
590ac7ff5f
commit
20149b7f3a
456 changed files with 70406 additions and 0 deletions
67
app/internal/apptest/apptest.go
Normal file
67
app/internal/apptest/apptest.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package apptest provides utilities for testing an app.
|
||||
//
|
||||
// It is extremely incomplete, hence it being internal.
|
||||
// For starters, it should support iOS.
|
||||
package apptest
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// Port is the TCP port used to communicate with the test app.
|
||||
//
|
||||
// TODO(crawshaw): find a way to make this configurable. adb am extras?
|
||||
const Port = "12533"
|
||||
|
||||
// Comm is a simple text-based communication protocol.
|
||||
//
|
||||
// Assumes all sides are friendly and cooperative and that the
|
||||
// communication is over at the first sign of trouble.
|
||||
type Comm struct {
|
||||
Conn net.Conn
|
||||
Fatalf func(format string, args ...interface{})
|
||||
Printf func(format string, args ...interface{})
|
||||
|
||||
scanner *bufio.Scanner
|
||||
}
|
||||
|
||||
func (c *Comm) Send(cmd string, args ...interface{}) {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString(cmd)
|
||||
for _, arg := range args {
|
||||
buf.WriteRune(' ')
|
||||
fmt.Fprintf(buf, "%v", arg)
|
||||
}
|
||||
buf.WriteRune('\n')
|
||||
b := buf.Bytes()
|
||||
c.Printf("comm.send: %s\n", b)
|
||||
if _, err := c.Conn.Write(b); err != nil {
|
||||
c.Fatalf("failed to send %s: %v", b, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Comm) Recv(cmd string, a ...interface{}) {
|
||||
if c.scanner == nil {
|
||||
c.scanner = bufio.NewScanner(c.Conn)
|
||||
}
|
||||
if !c.scanner.Scan() {
|
||||
c.Fatalf("failed to recv %q: %v", cmd, c.scanner.Err())
|
||||
}
|
||||
text := c.scanner.Text()
|
||||
c.Printf("comm.recv: %s\n", text)
|
||||
var recvCmd string
|
||||
args := append([]interface{}{&recvCmd}, a...)
|
||||
if _, err := fmt.Sscan(text, args...); err != nil {
|
||||
c.Fatalf("cannot scan recv command %s: %q: %v", cmd, text, err)
|
||||
}
|
||||
if cmd != recvCmd {
|
||||
c.Fatalf("expecting recv %q, got %v", cmd, text)
|
||||
}
|
||||
}
|
16
app/internal/callfn/callfn.go
Normal file
16
app/internal/callfn/callfn.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build android && (arm || 386 || amd64 || arm64)
|
||||
|
||||
// Package callfn provides an android entry point.
|
||||
//
|
||||
// It is a separate package from app because it contains Go assembly,
|
||||
// which does not compile in a package using cgo.
|
||||
package callfn
|
||||
|
||||
// CallFn calls a zero-argument function by its program counter.
|
||||
// It is only intended for calling main.main. Using it for
|
||||
// anything else will not end well.
|
||||
func CallFn(fn uintptr)
|
11
app/internal/callfn/callfn_386.s
Normal file
11
app/internal/callfn/callfn_386.s
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
#include "funcdata.h"
|
||||
|
||||
TEXT ·CallFn(SB),$0-4
|
||||
MOVL fn+0(FP), AX
|
||||
CALL AX
|
||||
RET
|
11
app/internal/callfn/callfn_amd64.s
Normal file
11
app/internal/callfn/callfn_amd64.s
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
#include "funcdata.h"
|
||||
|
||||
TEXT ·CallFn(SB),$0-8
|
||||
MOVQ fn+0(FP), AX
|
||||
CALL AX
|
||||
RET
|
11
app/internal/callfn/callfn_arm.s
Normal file
11
app/internal/callfn/callfn_arm.s
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
#include "funcdata.h"
|
||||
|
||||
TEXT ·CallFn(SB),$0-4
|
||||
MOVW fn+0(FP), R0
|
||||
BL (R0)
|
||||
RET
|
11
app/internal/callfn/callfn_arm64.s
Normal file
11
app/internal/callfn/callfn_arm64.s
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
#include "funcdata.h"
|
||||
|
||||
TEXT ·CallFn(SB),$0-8
|
||||
MOVD fn+0(FP), R0
|
||||
BL (R0)
|
||||
RET
|
27
app/internal/testapp/AndroidManifest.xml
Normal file
27
app/internal/testapp/AndroidManifest.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2015 The Go Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style
|
||||
license that can be found in the LICENSE file.
|
||||
-->
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.golang.testapp"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="15" />
|
||||
<!-- to talk to the host -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application android:label="testapp" android:debuggable="true">
|
||||
<activity android:name="org.golang.app.GoNativeActivity"
|
||||
android:label="testapp"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.lib_name" android:value="testapp" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
94
app/internal/testapp/testapp.go
Normal file
94
app/internal/testapp/testapp.go
Normal file
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build darwin || linux
|
||||
|
||||
// Small test app used by app/app_test.go.
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/app/internal/apptest"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app.Main(func(a app.App) {
|
||||
var (
|
||||
glctx gl.Context
|
||||
visible bool
|
||||
)
|
||||
|
||||
addr := "127.0.0.1:" + apptest.Port
|
||||
log.Printf("addr: %s", addr)
|
||||
|
||||
conn, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
log.Printf("dialled")
|
||||
comm := &apptest.Comm{
|
||||
Conn: conn,
|
||||
Fatalf: log.Panicf,
|
||||
Printf: log.Printf,
|
||||
}
|
||||
|
||||
comm.Send("hello_from_testapp")
|
||||
comm.Recv("hello_from_host")
|
||||
|
||||
color := "red"
|
||||
sendPainting := false
|
||||
for e := range a.Events() {
|
||||
switch e := a.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
switch e.Crosses(lifecycle.StageVisible) {
|
||||
case lifecycle.CrossOn:
|
||||
comm.Send("lifecycle_visible")
|
||||
sendPainting = true
|
||||
visible = true
|
||||
glctx, _ = e.DrawContext.(gl.Context)
|
||||
case lifecycle.CrossOff:
|
||||
comm.Send("lifecycle_not_visible")
|
||||
visible = false
|
||||
}
|
||||
case size.Event:
|
||||
comm.Send("size", e.PixelsPerPt, e.Orientation)
|
||||
case paint.Event:
|
||||
if visible {
|
||||
if color == "red" {
|
||||
glctx.ClearColor(1, 0, 0, 1)
|
||||
} else {
|
||||
glctx.ClearColor(0, 1, 0, 1)
|
||||
}
|
||||
glctx.Clear(gl.COLOR_BUFFER_BIT)
|
||||
a.Publish()
|
||||
}
|
||||
if sendPainting {
|
||||
comm.Send("paint", color)
|
||||
sendPainting = false
|
||||
}
|
||||
case touch.Event:
|
||||
comm.Send("touch", e.Type, e.X, e.Y)
|
||||
if e.Type == touch.TypeEnd {
|
||||
if color == "red" {
|
||||
color = "green"
|
||||
} else {
|
||||
color = "red"
|
||||
}
|
||||
sendPainting = true
|
||||
// Send a paint event so the screen gets redrawn.
|
||||
a.Send(paint.Event{})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue