Exemplo n.º 1
0
 public void EnsureTheSameInstanceOfPortAllocatorIsAlwaysUsedWhenOnceIsSpecifiedInTheConstructor()
 {
     var portAllocator = new PortAllocator(MockRepository.GenerateMock<ILogger>());
     var driver = new VlcDriver(null, portAllocator);
     var job = driver.CreateAudioJob();
     Assert.AreEqual(portAllocator, job.PortAllocator);
 }
Exemplo n.º 2
0
 public void TestAudioJobCreation()
 {
     var driver = new VlcDriver();
     var job = driver.CreateAudioJob();
     Assert.IsNotNull(job);
     Assert.AreEqual(8081, job.PortAllocator.StartPort);
 }
        public void TestVlcMp32WavJobActuallyGetsDone()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWavMp3128.mp3");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Wav
            };

            var portAllocator = MockRepository.GenerateMock<IPortAllocator>();
            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock<IStatusParser>(), MockRepository.GenerateMock<IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock<ILogger>());
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output2.wav");
            job.OutputFile = new FileInfo(expectedOutputFile);

            var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock<ILogger>()));
            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.IsFalse(job.OutputFile.Exists, "output file already exists, cannot run test");
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.IsNotNull(job.Instance);
            Assert.IsNotNull(job.Instance.Process);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            job.Instance.Process.WaitForExit();
            SleepToAllowEventHandler();
            Assert.AreEqual(VlcJob.JobState.Finished, job.State, "Job state was not set to finished afterwards");
            var newFileInfo = new FileInfo(job.OutputFile.FullName);
            Assert.IsTrue(newFileInfo.Exists);
            Assert.That(newFileInfo.Length, Is.EqualTo(368684).Within(AllowedOutputFileComparePercentage).Percent);
        }
Exemplo n.º 4
0
 public void EnsureTheSameInstanceOfPortAllocatorIsAlwaysUsedWhenOnceIsNotSpecifiedInTheConstructor()
 {
     var driver = new VlcDriver();
     var job1 = driver.CreateAudioJob();
     var job2 = driver.CreateAudioJob();
     Assert.AreNotEqual(job1, job2);
     Assert.AreEqual(job1.PortAllocator, job2.PortAllocator);
 }
Exemplo n.º 5
0
        public void EnsureWeAllocatePortAllocatorTheStartingPortFromSettings()
        {
            var oldPort = VLCDriver.Properties.Settings.Default.StartPort;

            VLCDriver.Properties.Settings.Default.StartPort = -3;
            var driver = new VlcDriver();
            var job = driver.CreateAudioJob();
            var actualPort = job.PortAllocator.StartPort;
            VLCDriver.Properties.Settings.Default.StartPort = oldPort;
            Assert.AreEqual(-3, actualPort);
        }
Exemplo n.º 6
0
 public static void SetVlcExeLocationOnNonStandardWindowsEnvironments(VlcDriver driver)
 {
     var osver = Environment.OSVersion;
     switch (osver.Platform)
     {
         case PlatformID.Win32NT:
             break;
         case PlatformID.Unix:
             driver.VlcExePath = new FileInfo("/usr/bin/vlc");
             break;
         default:
             throw new InvalidOperationException("I've not thought this through yet");
     }
 }
Exemplo n.º 7
0
        public void EnsureVlcLocationPathIsUsedByVlcDriver()
        {
            var locator = MockRepository.GenerateStub<IVlcLocator>();
            var location = Path.Combine(TestUtilities.GetTestDir(), "myfakevlc.exe");
            locator.Location = location;
            var starter = MockRepository.GenerateMock<IVlcStarter>();
            var driver = new VlcDriver(starter, null, locator);
            Assert.AreEqual(location, driver.VlcExePath.FullName);

            starter.Expect(x => x.Start(Arg<string>.Is.Anything, Arg<FileInfo>.Is.Anything)).Repeat.Once();
            driver.StartInstance();

            var args = starter.GetArgumentsForCallsMadeOn(x => x.Start(null, null), x => x.IgnoreArguments());
            var filePathArgument = args[0][1] as FileInfo;
            Assert.AreEqual(location, filePathArgument.FullName);

            starter.VerifyAllExpectations();
        }
Exemplo n.º 8
0
        static void Main()
        {
            #region This region is only for use in this console example as ending the console will leave VLC running
            handler = ConsoleEventCallback;
            var osver = Environment.OSVersion;
            switch (osver.Platform)
            {
                case PlatformID.Win32NT:
                    SetConsoleCtrlHandler(handler, true);
                    break;
            }

            #endregion

            var input = new FileInfo(@"c:\Temp\inputVideo.avi");
            var output = new FileInfo(@"c:\Temp\outputVideo.mpg");

            if (!input.Exists)
            {
                throw new FileNotFoundException("Example app needs a file to convert", input.FullName);
            }

            var driver = new VlcDriver();
            //driver.VlcExePath = new FileInfo("/usr/bin/vlc"); - Only on Non Windows environments
            Job = driver.CreateVideoJob();
            Job.InputFile = input;
            Job.OutputFile = output;
            Job.VideoConfiguration.Format = VideoConfiguration.VlcVideoFormat.Mpeg2;
            Job.AudioConfiguration.Format = AudioConfiguration.ConversionFormats.Mpg;

            driver.StartJob(Job);

            while (Job.State != VlcJob.JobState.Finished)
            {
                Job.UpdateProgress();
                Console.Clear();
                Console.SetCursorPosition(0,0);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("{0}% Complete. Remaining {1}", string.Format("{0:0.0#}", Job.PercentComplete * 100), Job.EstimatedTimeToCompletion.ToString(@"h\h\:m\m\:s\s", System.Globalization.CultureInfo.InvariantCulture));
                Thread.Sleep(1000);
            }
        }
        public void TestVlcConversionWithArguments()
        {
            var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock<ILogger>()));
            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);

            var jobArgument = string.Format("-I dummy \"{0}{2}NeedinYou2SecWavMp3128.mp3\" \":sout=#transcode{{vcodec=none,acodec=s16l,ab=128,channels=2,samplerate=44100}}:std{{dst='{1}{2}output.wav',access=file}}\" vlc://quit", TestUtilities.GetTestDir(), TestUtilities.GetTestOutputDir(), Path.DirectorySeparatorChar);
            Assert.IsFalse(File.Exists(Path.Combine(TestUtilities.GetTestOutputDir(), "output.wav")));
            var instance = driver.StartInstance(jobArgument);
            var exitedNotificationHappened = false;
            instance.OnExited += (sender, e) =>
            {
                exitedNotificationHappened = true;
            };

            instance.Process.WaitForExit();
            SleepToAllowEventHandler();
            Assert.IsTrue(exitedNotificationHappened);
            var expectedFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.wav");
            Assert.IsTrue(File.Exists(expectedFile));
            var fileInfo = new FileInfo(expectedFile);

            Assert.That(fileInfo.Length, Is.EqualTo(368684).Within(AllowedOutputFileComparePercentage).Percent);
        }
Exemplo n.º 10
0
 public void TestPathAssignment()
 {
     var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @"Foo.exe");
     var locator = MockRepository.GenerateMock<IVlcLocator>();
     var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock<ILogger>()), null, locator)
     {
         VlcExePath = new FileInfo(path)
     };
     Assert.AreEqual(path, driver.VlcExePath.FullName);
 }
Exemplo n.º 11
0
        public void TestWeGetJobStateChangedEventWhenConversionEnds()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Mp3
            };

            var portAllocator = MockRepository.GenerateMock<IPortAllocator>();
            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock<IStatusParser>(), MockRepository.GenerateMock<IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock<ILogger>());
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");
            job.OutputFile = new FileInfo(expectedOutputFile);

            var starter = MockRepository.GenerateMock<IVlcStarter>();
            var instance = MockRepository.GenerateMock<IVlcInstance>();
            starter.Expect(x => x.Start(Arg<string>.Is.Anything, Arg<FileInfo>.Is.Anything)).Return(instance);
            var driver = new VlcDriver(starter);
            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.AreEqual(0, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            var eventHandlerWasCalled = false;
            driver.OnJobStateChange += (source, args) =>
            {
                eventHandlerWasCalled = true;
                Assert.AreEqual(job, args.Job);
            };
            instance.Raise(x => x.OnExited += null, instance, new EventArgs());
            Assert.IsTrue(eventHandlerWasCalled);
        }
Exemplo n.º 12
0
 public void TestVlcStarts()
 {
     var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock<ILogger>()));
     TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
     var instance = driver.StartInstance();
     Thread.Sleep(500);
     var vlcProcesses = Process.GetProcessesByName("vlc");
     Assert.AreEqual(1, vlcProcesses.Length);
     instance.Process.Kill();
     instance.Process.WaitForExit();
     vlcProcesses = Process.GetProcessesByName("vlc");
     Assert.AreEqual(0, vlcProcesses.Length);
 }