diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-11 01:51:47 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-12 03:00:46 -0600 |
commit | 72ffcd0a79fac3112f436c3841c3ca8b3815391d (patch) | |
tree | c084e1ea8396e21706c71ef7565c98f96e09cd55 /ui/tests | |
parent | build: allow make to skip hidden directory to reduce stats (diff) | |
download | wireguard-windows-72ffcd0a79fac3112f436c3841c3ca8b3815391d.tar.xz wireguard-windows-72ffcd0a79fac3112f436c3841c3ca8b3815391d.zip |
ui: initial stab at a better confview
Diffstat (limited to 'ui/tests')
-rw-r--r-- | ui/tests/Makefile | 30 | ||||
-rw-r--r-- | ui/tests/confview.go | 70 |
2 files changed, 100 insertions, 0 deletions
diff --git a/ui/tests/Makefile b/ui/tests/Makefile new file mode 100644 index 00000000..c71af21d --- /dev/null +++ b/ui/tests/Makefile @@ -0,0 +1,30 @@ +export CFLAGS := -O3 -Wall -std=gnu11 +export CC := x86_64-w64-mingw32-gcc +WINDRES := x86_64-w64-mingw32-windres +export CGO_ENABLED := 1 +export GOOS := windows +export GOARCH := amd64 + +DEPLOYMENT_HOST ?= winvm +DEPLOYMENT_PATH ?= Desktop + +all: tests.exe + +resources.syso: ../../resources.rc ../../manifest.xml ../icon/icon.ico + $(WINDRES) -i $< -o $@ -O coff + +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) +tests.exe: resources.syso $(call rwildcard,..,*.go *.c *.h) + go build -ldflags="-s -w" -v -o $@ + +deploy: tests.exe + -ssh $(DEPLOYMENT_HOST) -- 'taskkill /im tests.exe /f' + scp tests.exe $(DEPLOYMENT_HOST):$(DEPLOYMENT_PATH) + +run: tests.exe + wine tests.exe + +clean: + rm -rf resources.syso tests.exe + +.PHONY: deploy run clean all diff --git a/ui/tests/confview.go b/ui/tests/confview.go new file mode 100644 index 00000000..6907d83d --- /dev/null +++ b/ui/tests/confview.go @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package main + +import ( + "github.com/lxn/walk" + "golang.zx2c4.com/wireguard/windows/conf" + "golang.zx2c4.com/wireguard/windows/ui" + "log" + "runtime" +) + + +const demoConfig = `[Interface] +PrivateKey = 6KpcbNFK4tKBciKBT2Rj6Z/sHBqxdV+p+nuNA5AlWGI= +Address = 192.168.4.84/24 +DNS = 8.8.8.8, 8.8.4.4, 1.1.1.1, 1.0.0.1 + +[Peer] +PublicKey = JRI8Xc0zKP9kXk8qP84NdUQA04h6DLfFbwJn4g+/PFs= +Endpoint = demo.wireguard.com:12912 +AllowedIPs = 0.0.0.0/0 +` + +func main(){ + mw, _ := walk.NewMainWindowWithName("Test ConfView") + mw.SetSize(walk.Size{600, 800}) + mw.SetLayout(walk.NewVBoxLayout()) + cv, err := ui.NewConfView(mw) + if err != nil { + log.Fatal(err) + } + config, _ := conf.FromWgQuick(demoConfig, "demo") + peer := config.Peers[0] + config.Peers = make([]conf.Peer, 0) + + pb1, _ := walk.NewPushButton(mw) + pb1.SetText("Add and increment") + pb1.Clicked().Attach(func() { + config.Interface.ListenPort++ + config.Peers = append(config.Peers, peer) + k,_ := conf.NewPrivateKey() + config.Peers[len(config.Peers) - 1].PublicKey = *k + cv.SetConfiguration(config) + }) + pb2, _ := walk.NewPushButton(mw) + pb2.SetText("Remove first peer") + pb2.Clicked().Attach(func() { + if len(config.Peers) < 1 { + return + } + config.Interface.ListenPort-- + config.Peers = config.Peers[1:] + cv.SetConfiguration(config) + }) + pb3, _ := walk.NewPushButton(mw) + pb3.SetText("Toggle MTU") + pb3.Clicked().Attach(func() { + config.Interface.Mtu = (config.Interface.Mtu + 1) % 2 + cv.SetConfiguration(config) + }) + mw.SetVisible(true) + mw.Show() + mw.Activate() + mw.Run() + runtime.KeepAlive(cv) +}
\ No newline at end of file |