Beispiel #1
0
// newFromStorage creates a config page builder with the given config storage.
//
func newFromStorage(source cftype.Source, log cdtype.Logger, storage cftype.Storage, originalConf, gettextDomain string) *grouper {
	grouper := &grouper{
		Builder: NewBuilder(source, log, storage, originalConf, gettextDomain),
	}
	storage.SetBuilder(grouper)
	grouper.free = grouper.Builder.Free
	grouper.Builder.Connect("destroy", func() { grouper.free() })
	return grouper
}
Beispiel #2
0
func testValuerToBoth(t *testing.T, conf cftype.Storage, group string) {
	ii := 42
	ib := true
	it := float64(4.2)
	is := "42"
	ili := []int{42, -1}
	ilb := []bool{true, true}
	ilf := []float64{4.2, -5.9}
	ils := []string{"42", "or", "!"}

	vi := conf.Valuer(group, "int").(extendedValuer)
	vb := conf.Valuer(group, "bool").(extendedValuer)
	vf := conf.Valuer(group, "float").(extendedValuer)
	vs := conf.Valuer(group, "string").(extendedValuer)
	vli := conf.Valuer(group, "listint").(extendedValuer)
	vlb := conf.Valuer(group, "listbool").(extendedValuer)
	vlf := conf.Valuer(group, "listfloat").(extendedValuer)
	vls := conf.Valuer(group, "liststring").(extendedValuer)

	// Set from Valuer.

	vi.Set(ii)
	vb.Set(ib)
	vf.Set(it)
	vs.Set(is)
	vli.Set(ili)
	vlb.Set(ilb)
	vlf.Set(ilf)
	vls.Set(ils)

	// Test get from Valuer.

	assert.Equal(t, ii, vi.Int(), "get Valuer int")
	assert.Equal(t, ib, vb.Bool(), "get Valuer bool")
	assert.Equal(t, it, vf.Float(), "get Valuer float64")
	assert.Equal(t, is, vs.String(), "get Valuer string")
	assert.Equal(t, ili, vli.ListInt(), "get Valuer list int")
	assert.Equal(t, ilb, vlb.ListBool(), "get Valuer list bool")
	assert.Equal(t, ilf, vlf.ListFloat(), "get Valuer list float")
	assert.Equal(t, ils, vls.ListString(), "get Valuer list string")

	// Test get from Source with pointer.

	ob := false
	oi := 0
	ot := float64(0)
	os := ""
	olb := []bool{}
	oli := []int{}
	olf := []float64{}
	ols := []string{}

	log.Err(conf.Get(group, "int", &oi), "get int")
	log.Err(conf.Get(group, "bool", &ob), "get bool")
	log.Err(conf.Get(group, "float", &ot), "get float")
	log.Err(conf.Get(group, "string", &os), "get string")
	log.Err(conf.Get(group, "listint", &oli), "get listint")
	log.Err(conf.Get(group, "listbool", &olb), "get listbool")
	log.Err(conf.Get(group, "listfloat", &olf), "get listfloat")
	log.Err(conf.Get(group, "liststring", &ols), "get liststring")

	assert.Equal(t, ii, oi, "get Source Get int")
	assert.Equal(t, ib, ob, "get Source Get bool")
	assert.Equal(t, it, ot, "get Source Get float64")
	assert.Equal(t, is, os, "get Source Get string")
	assert.Equal(t, ilb, olb, "get Source Get list bool")
	assert.Equal(t, ili, oli, "get Source Get list int")
	assert.Equal(t, ilf, olf, "get Source Get list float")
	assert.Equal(t, ils, ols, "get Source Get list string")

	// Test get from Source directly.

	oi, _ = conf.Int(group, "int")
	ob, _ = conf.Bool(group, "bool")
	ot, _ = conf.Float(group, "float")
	os, _ = conf.String(group, "string")
	olb, _ = conf.ListBool(group, "listbool")
	oli, _ = conf.ListInt(group, "listint")
	olf, _ = conf.ListFloat(group, "listfloat")
	ols, _ = conf.ListString(group, "liststring")

	assert.Equal(t, ii, oi, "get Source fields int")
	assert.Equal(t, ib, ob, "get Source fields bool")
	assert.Equal(t, it, ot, "get Source fields float64")
	assert.Equal(t, is, os, "get Source fields string")
	assert.Equal(t, ili, oli, "get Source fields list int")
	assert.Equal(t, ilb, olb, "get Source fields list bool")
	assert.Equal(t, ilf, olf, "get Source fields list float")
	assert.Equal(t, ils, ols, "get Source fields list string")

}