예제 #1
0
func TestNewSingleColorTile(t *testing.T) {
	img, err := sampledata.Asset("s_color.png")
	require.Nil(t, err)

	tile, err := NewTile(img)
	require.Nil(t, err)

	for i := 0; i < len(img); i++ {
		if tile.Image[i] != img[i] {
			t.Error("tile.Image != img")
		}
	}
	if tile.SingleColor == nil {
		t.Error("SingleColor should not be nil")
	}
	r, g, b, a := tile.SingleColor.RGBA()
	if r != 181|(181<<8) {
		t.Error("Invalid SingleColor r: ", r)
	}
	if g != 208|(208<<8) {
		t.Error("Invalid SingleColor g: ", g)
	}
	if b != 208|(208<<8) {
		t.Error("Invalid SingleColor b: ", b)
	}
	if a != 255|(255<<8) {
		t.Error("Invalid SingleColor a: ", a)
	}
}
예제 #2
0
func (s *StorePluginSuite) GetSetTest(c *C, cfgStr string) {
	var cfg app.PluginConfig
	err := json.Unmarshal([]byte(cfgStr), &cfg)
	c.Assert(err, IsNil)

	var tiles []gopnik.Tile
	for _, fname := range []string{"1_0_0.png", "1_1_0.png", "1_0_1.png", "1_1_1.png"} {
		data, err := sampledata.Asset(fname)
		c.Assert(err, IsNil)
		tile, err := gopnik.NewTile(data)
		c.Assert(err, IsNil)
		c.Assert(tile, Not(IsNil))
		tiles = append(tiles, *tile)
	}

	plgn, err := plugins.DefaultPluginStore.Create(cfg.Plugin, cfg.PluginConfig)
	c.Assert(err, IsNil)
	store, ok := plgn.(gopnik.CachePluginInterface)
	c.Assert(ok, Equals, true)

	err = store.Set(gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 2,
	}, tiles)
	// Set error should be nil
	c.Assert(err, IsNil)

	t01, err := store.Get(gopnik.TileCoord{
		X:    0,
		Y:    1,
		Zoom: 1,
		Size: 1,
	})
	// Get error should be nil
	c.Assert(err, IsNil)

	t01Orig, err := sampledata.Asset("1_0_1.png")
	c.Assert(err, IsNil)
	sampledata.CheckImage(c, t01, t01Orig)
}
예제 #3
0
func TestNewNormalTile(t *testing.T) {
	img, err := sampledata.Asset("1_0_0.png")
	require.Nil(t, err)

	tile, err := NewTile(img)
	require.Nil(t, err)

	for i := 0; i < len(img); i++ {
		if tile.Image[i] != img[i] {
			t.Error("tile.Image != img")
		}
	}

	require.Nil(t, tile.SingleColor)
}
예제 #4
0
func (self *FakeCachePlugin) Configure(cfg json.RawMessage) error {
	err := json.Unmarshal(cfg, &self.config)
	if err != nil {
		return err
	}
	if self.config.UseStubImage {
		self.img, err = sampledata.Asset("1_0_0.png")
		if err != nil {
			return err
		}
	}

	if self.config.GetSleep != "" {
		var err error
		self.getSleep, err = time.ParseDuration(self.config.GetSleep)
		if err != nil {
			return nil
		}
	}
	if self.config.SetSleep != "" {
		var err error
		self.setSleep, err = time.ParseDuration(self.config.SetSleep)
		if err != nil {
			return nil
		}
	}

	if self.config.SetError != "" {
		self.setError = errors.New(self.config.SetError)
	}
	if self.config.GetError != "" {
		self.getError = errors.New(self.config.GetError)
	}

	return nil
}