Example #1
0
func TestFps(t *testing.T) {
	assert.False(t, theio.RegexFps1.MatchString(streams[0]))

	// --- fps ---
	assert.True(t, theio.RegexFps1.MatchString(streams[1]))
	matched := theio.RegexFps1.ReplaceAllString(streams[1],
		fmt.Sprintf("${%s}", theio.RegexFps1.SubexpNames()[2]))
	assert.Equal(t, matched, "29.97 fps,", "")

	assert.True(t, theio.RegexFps1.MatchString(streams[2]))
	matched = theio.RegexFps1.ReplaceAllString(streams[2],
		fmt.Sprintf("${%s}", theio.RegexFps1.SubexpNames()[2]))
	assert.Equal(t, matched, "23.97 fps,", "")

	// --- tbr ---
	assert.True(t, theio.RegexFps2.MatchString(streams[0]))
	matched = theio.RegexFps2.ReplaceAllString(streams[0],
		fmt.Sprintf("${%s}", theio.RegexFps2.SubexpNames()[2]))
	assert.Equal(t, matched, "25 tbr,", "")

	assert.True(t, theio.RegexFps2.MatchString(streams[2]))
	matched = theio.RegexFps2.ReplaceAllString(streams[2],
		fmt.Sprintf("${%s}", theio.RegexFps2.SubexpNames()[2]))
	assert.Equal(t, matched, "23.97 tbr,", "")

	for k, v := range mapf {
		if d, _ := theio.ParseFps(k); d != v {
			t.Errorf("tsk tsk: Fps")
		}
	}
}
Example #2
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 #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 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 #5
0
func TestPreprocessSpeed(t *testing.T) {
	assert.Equal(t, "1", "1")
	for i, tt := range speedFixtures {
		a := NewArguments()
		err := preprocessSpeed(a, tt.in)
		switch {
		case err == nil:
			if tt.err {
				t.Errorf("%d. Error out(%t), want %t", i, err != nil, tt.err)
			}
		default:
			if !tt.err {
				t.Errorf("%d. Error out(%t), want %t", i, err != nil, tt.err)
			}
		}
		if a.SpeedSpec != tt.out {
			t.Errorf("%d. in(%q) => out(%q), want %q", i, tt.in, a.SpeedSpec, tt.out)
		}
	}
}
Example #6
0
func TestPreprocessingScale(t *testing.T) {
	a := NewArguments()
	assert.NoError(t, preprocessScale(a, "_:600"))
	assert.Equal(t, a.NeedScaling, true)
	assert.Equal(t, a.ScaleFilter, "scale=trunc(oh*a/2)*2:600")

	a = NewArguments()
	assert.NoError(t, preprocessScale(a, "300:600"))
	assert.Equal(t, a.NeedScaling, true)
	assert.Equal(t, a.ScaleFilter, "scale=300:600")

	a = NewArguments()
	assert.NoError(t, preprocessScale(a, "300:_"))
	assert.Equal(t, a.NeedScaling, true)
	assert.Equal(t, a.ScaleFilter, "scale=300:trunc(ow/a/2)*2")
}
Example #7
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")
}