Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ go:
env:
global:
- secure: "GYPf9iqbY/5YLmorhVxH2Q4Y8/kxF3MWxDau8Sb2QnineLAJZA2HKi4aWdZIoK8AMAJgXdHUC4Pw2jywp9nC2Q+TW1+57tp0uLLIdghuwif78oyqykhlt11ny+SUk5PAkqYmm+dCbA0kxShg1hFFfHGTTiDuWklTWomxGGICSPc="
- DISPLAY: ":99.0"

before_install:
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
- go get github.com/mattn/goveralls
- sh -e /etc/init.d/xvfb start

script:
- go get -d -t -v ./...
Expand Down
2 changes: 2 additions & 0 deletions vg/vgimg/vgimg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func TestIssue179(t *testing.T) {
if err != nil {
t.Error(err)
}
defer f.Close()

want, err := ioutil.ReadAll(f)
if err != nil {
t.Error(err)
Expand Down
5 changes: 2 additions & 3 deletions vg/vgx11/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

// +build !windows

// The vgx11 package uses xgbutil (github.com/BurntSushi/xgbutil)
// as a X11-display backend for vg.
// Package vgx11 implements X-Window vg support.
package vgx11

import (
Expand Down Expand Up @@ -69,7 +68,7 @@ func NewImage(img draw.Image, name string) (*Canvas, error) {
gc := draw2d.NewGraphicContextWithPainter(ximg, painter)
gc.SetDPI(dpi)
gc.Scale(1, -1)
gc.Translate(+0.5*w, -0.5*h)
gc.Translate(0, -h)

wid := ximg.XShowExtra(name, true)
go func() {
Expand Down
69 changes: 69 additions & 0 deletions vg/vgx11/canvas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright ©2015 The gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !windows

package vgx11

import (
"bytes"
"image/jpeg"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/gonum/plot"
"github.com/gonum/plot/plotter"
"github.com/gonum/plot/vg"
"github.com/gonum/plot/vg/draw"
)

// hasX11 checks if X11 is available by looking at the DISPLAY environment variable
func hasX11() bool {
return os.Getenv("DISPLAY") != ""
}

func TestIssue179(t *testing.T) {
if !hasX11() {
t.Skip("no X11 environment")
}

scatter, err := plotter.NewScatter(plotter.XYs{{1, 1}, {0, 1}, {0, 0}})
if err != nil {
t.Fatalf("error: %v\n", err)
}
p, err := plot.New()
if err != nil {
t.Fatalf("error: %v\n", err)
}
p.Add(scatter)
p.HideAxes()

c, err := New(5.08*vg.Centimeter, 5.08*vg.Centimeter, "test issue179")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the joke, but we don't have to do it everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we actually do - Seb is using the same image that Brendan created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. Fair enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... at some point I was tinkering with the idea of folding vgx11 into vgimg directly so it could be handled like the JpegCanvas and co. (so the test could also be folded into vgimg_test...)

if err != nil {
t.Fatalf("error: %v\n", err)
}

p.Draw(draw.New(c))
b := bytes.NewBuffer([]byte{})
err = jpeg.Encode(b, c.ximg, nil)
if err != nil {
t.Error(err)
}

f, err := os.Open(filepath.Join("..", "vgimg", "testdata", "issue179.jpg"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we are going to be doing this boilerplate reading from a file and compare in various tests. I think that it's time for a vgtest package that exports this function.

if err != nil {
t.Error(err)
}
defer f.Close()

want, err := ioutil.ReadAll(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer f.Close()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also fixed in vgimg_test)

if err != nil {
t.Error(err)
}
if !bytes.Equal(b.Bytes(), want) {
t.Error("Image mismatch")
}
}