Example #1
0
func TestVideoReader(t *testing.T) {
	var pathsep string = string(os.PathSeparator)

	vr := new(VideoReader)
	err := vr.reset2(4,
		func() string { return pathsep + filepath.Join([]string{"tmp"}...) },
		func() string { return pathsep },
		func() int64 { return int64(1234567) },
	)
	assert.Error(t, err, "")

	src := []string{"home", "putin", "crimea.mp4"}
	vr.Filename = pathsep + filepath.Join(src...)
	err = vr.reset2(4,
		func() string { return pathsep + filepath.Join([]string{"tmp"}...) },
		func() string { return pathsep },
		func() int64 { return int64(1234567) },
	)
	assert.Equal(t, vr.Gif, "crimea.gif")

	tmpdir := []string{"tmp", "seneca", "1234567"}
	assert.Equal(t, vr.TmpDir, pathsep+filepath.Join(tmpdir...))

	pngdir := []string{"tmp", "seneca", "1234567", "p"}
	assert.Equal(t, vr.PngDir, pathsep+filepath.Join(pngdir...))
	assert.Equal(t, vr.TmpFile, "img-%04d.png")
}
Example #2
0
func TestDurationRegex(t *testing.T) {
	_, err := theio.ParseDuration("")
	assert.Error(t, err, "")
	assert.Equal(t, err, theio.InvalidDuration, "empty duration should fail")

	for k, v := range mapd {
		if d, _ := theio.ParseDuration(k); d != v {
			t.Errorf("tsk tsk: Duration")
		}
	}
}
Example #3
0
func TestPreprocessFrom(t *testing.T) {
	var zerot time.Time
	a := NewArguments()
	tz := TimeCode(zerot)
	assert.Equal(t, a.From, tz)
	assert.Equal(t, tz.String(), "00:00:00")

	assert.Error(t, preprocessFrom(a, "13:01:5"))

	assert.NoError(t, preprocessFrom(a, "13:01:05"))
	ti, _ := time.Parse("15:04:05", "13:01:05")
	assert.Equal(t, tz.String(), "00:00:00")
	assert.Equal(t, a.From, TimeCode(ti))
	assert.Equal(t, TimeCode(ti).String(), "13:01:05")
}
Example #4
0
func TestScaleType(t *testing.T) {

	_, err := WidthOnly.Decode()
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrNoArgs)
	}

	_, err = ScaleType(5).Decode(100)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrScaleOutOfRange)
	}

	_, err = ScaleType(5).Decode(100, 200)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrScaleOutOfRange)
	}

	_, err = ScaleType(5).Decode(500, 300, 150)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrScaleOutOfRange)
	}

	a, _ := WidthOnly.Decode(100)
	assert.Equal(t, a, "scale=100:trunc(ow/a/2)*2")

	_, err = WidthOnly.Decode(101)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err.Error(), "101 is not even")
	}

	_, err = HeightOnly.Decode()
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrNoArgs)
	}

	a, _ = HeightOnly.Decode(666)
	assert.Equal(t, a, "scale=trunc(oh*a/2)*2:666")

	_, err = HeightOnly.Decode(661)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err.Error(), "661 is not even")
	}

	a, err = WidthHeight.Decode()
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrNoArgs)
	}

	a, err = WidthHeight.Decode(640)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err, ErrTwoArgs)
	}

	a, _ = WidthHeight.Decode(640, 480)
	assert.Equal(t, a, "scale=640:480")

	_, err = WidthHeight.Decode(641, 480)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err.Error(), "641 is not even")
	}

	_, err = WidthHeight.Decode(640, 481)
	if assert.Error(t, err, "An error was expected") {
		assert.Equal(t, err.Error(), "481 is not even")
	}

	a, _ = WidthHeight.Decode(1280, 760, 481, 211)
	assert.Equal(t, a, "scale=1280:760")
}