Files
openchamber-android-native/third_party/mygo/ui/svg_image_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

36 lines
1.1 KiB
Go

package ui
import (
"image/color"
"testing"
)
// TestSVGImage draws an SVG to pixels, fitted, with currentColor.
func TestSVGImage(t *testing.T) {
s := MustParseSVG([]byte(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="currentColor"/></svg>`))
img := s.Image(20, 10, color.NRGBA{G: 255, A: 255})
if b := img.Bounds(); b.Dx() != 20 || b.Dy() != 10 {
t.Fatalf("bounds %v, want 20 by 10", b)
}
// Fitted in the middle, as preserveAspectRatio's default says.
if c := img.RGBAAt(10, 5); c != (color.RGBA{G: 255, A: 255}) {
t.Errorf("the middle is %v, want green", c)
}
if c := img.RGBAAt(1, 5); c.A != 0 {
t.Errorf("beside the square is %v, want nothing", c)
}
if c := s.Image(4, 4, nil).RGBAAt(2, 2); c != (color.RGBA{A: 255}) {
t.Errorf("with no current color, %v, want black", c)
}
var none *SVG
if w, h := none.Size(); w != 0 || h != 0 {
t.Errorf("a nil SVG's size is %v by %v", w, h)
}
if b := none.Image(4, 4, nil).Bounds(); b.Dx() != 4 {
t.Errorf("a nil SVG's image is %v", b)
}
if b := s.Image(-1, 3, nil).Bounds(); !b.Empty() {
t.Errorf("an image of no pixels is %v", b)
}
}