The tray and AirDrop helper now live in Verae NetPrint.app so notifications can start, /api/stamp uses the same client as Print-Job and refuses mock receipts, and the default printer name includes the hostname with an mDNS rename when that name is taken. Co-authored-by: George Lambert <marchon@gmail.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf16"
|
|
)
|
|
|
|
func TestNetworkStampUsesDesktopPath(t *testing.T) {
|
|
netprintSrc, err := os.ReadFile("netprint_cmd.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
core, err := os.ReadFile("stampcore.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
text := string(netprintSrc)
|
|
if !strings.Contains(text, "stampWithClient(") || strings.Contains(text, "mock-cert") || strings.Contains(text, `DocumentName: "document.pdf"`) {
|
|
t.Fatal("netprint stamp is not the desktop stamp path")
|
|
}
|
|
if !strings.Contains(string(core), "func stampWithClient(") || !strings.Contains(string(core), "stampWithClient(pdf, t.Title") {
|
|
t.Fatal("stampFile does not use stampWithClient")
|
|
}
|
|
}
|
|
|
|
func TestNetprintUnknownCommandDoesNotStartServer(t *testing.T) {
|
|
if code := runNetprint([]string{"launch-server"}); code != 2 {
|
|
t.Fatalf("unknown command exit %d, want 2", code)
|
|
}
|
|
if runtime.GOOS == "windows" {
|
|
return
|
|
}
|
|
// Linux has no tray launcher. The command must fail before any listen.
|
|
if code := runNetprint([]string{"launch-tray"}); code != 1 {
|
|
t.Fatalf("launch-tray exit %d, want 1", code)
|
|
}
|
|
}
|
|
|
|
func TestReadTextFileUTF16(t *testing.T) {
|
|
s := "Email=a@b.co\r\nPassword=p=\"w\\x\r\n"
|
|
u := utf16.Encode([]rune(s))
|
|
b := []byte{0xFF, 0xFE}
|
|
for _, c := range u {
|
|
b = append(b, byte(c), byte(c>>8))
|
|
}
|
|
p := filepath.Join(t.TempDir(), "r.txt")
|
|
_ = os.WriteFile(p, b, 0o600)
|
|
got, err := readTextFile(p)
|
|
if err != nil || got != s {
|
|
t.Fatalf("%q %v", got, err)
|
|
}
|
|
}
|