Skip to content

Commit

Permalink
Added unit tests for v2 and cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
William Taylor committed May 2, 2016
1 parent 3dbb625 commit 03b1fa1
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 236 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ The library is a simple wrapper on top of DirectShow and replaces a lot of boile
## Example

```c++
#include "../WPL/WPL.h"

#include "SDL2/SDL.h"
#include "SDL2/SDL_syswm.h"

#pragma comment(lib, "SDL2/SDL2main.lib")
#pragma comment(lib, "SDL2/SDL2.lib")
#pragma comment(lib, "WPL.lib")
#include "../WPL/WPL.h"

using namespace std;
using namespace wpl;
Expand Down
9 changes: 9 additions & 0 deletions WPL.Sample/WPL.Sample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>xcopy /Y "$(SolutionDir)WPL.Sample\demo.wmv" "$(OutDir)"</Command>
</PreBuildEvent>
<PreLinkEvent>
<Command>xcopy /Y "$(SolutionDir)WPL.Sample\demo.wmv" "$(OutDir)"</Command>
</PreLinkEvent>
<PostBuildEvent>
<Command>xcopy /Y "$(SolutionDir)WPL.Sample\demo.wmv" "$(OutDir)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand Down
Binary file modified WPL.Sample/demo.wmv
Binary file not shown.
12 changes: 9 additions & 3 deletions WPL.Sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char * argv[])
SDL_GetWindowWMInfo(window, &wmInfo);

VideoPlayer videoPlayer(wmInfo.info.win.window);
videoPlayer.openVideo(L"demo.wmv");
videoPlayer.openVideo("demo.wmv");
videoPlayer.play();

while(!exit) {
Expand All @@ -40,16 +40,22 @@ int main(int argc, char * argv[])
case SDLK_LEFT: videoPlayer.pause(); break;
case SDLK_DOWN: videoPlayer.stop(); break;

default: break;
default:
break;
}
}
}

videoPlayer.updateVideoWindow();
videoPlayer.repaint();

if(videoPlayer.hasFinished())
{
SDL_ShowSimpleMessageBox(NULL, "Done", "Video has finished", window);
}
}

SDL_DestroyWindow(window);
SDL_Quit();
return 0;
return 0 ;
}
8 changes: 7 additions & 1 deletion WPL.Tests/ErrorTests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "CppUnitTest.h"
#include "Tests.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

Expand All @@ -10,7 +11,12 @@ namespace WPLTests
public:
TEST_METHOD(TestCannotFindFile)
{

wpl::VideoPlayer videoPlayer;

if(videoPlayer.openVideo("doesntexists.wmv"))
{
Assert::Fail(L"Error this file doesnt exist and should return false to indicate failure");
}
}
};
}
110 changes: 110 additions & 0 deletions WPL.Tests/StateTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

#include "CppUnitTest.h"
#include "Tests.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

auto timeout = [](Uint32 interval, void * ptr) -> Uint32 {
SDL_Event e;
e.type = SDL_QUIT;
SDL_PushEvent(&e);
return 0;
};

namespace WPLTests
{
TEST_CLASS(StateTests)
{
public:
TEST_METHOD(PlayTest)
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window = SDL_CreateWindow("Playback Demo", 100, 100, 800, 500, SDL_WINDOW_SHOWN);

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

wpl::VideoPlayer videoPlayer(wmInfo.info.win.window);

Assert::IsTrue(videoPlayer.openVideo("demo.wmv"), L"Error didnt load file");
Assert::IsTrue(videoPlayer.play(), L"Error couldnt play file");

SDL_DestroyWindow(window);
SDL_Quit();
}

TEST_METHOD(PauseTest)
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window = SDL_CreateWindow("", 100, 100, 800, 500, SDL_WINDOW_SHOWN);

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

wpl::VideoPlayer videoPlayer(wmInfo.info.win.window);

Assert::IsTrue(videoPlayer.openVideo("demo.wmv"), L"Error didnt load file");
Assert::IsTrue(videoPlayer.play(), L"Error couldnt play file");
Assert::IsTrue(videoPlayer.pause(), L"Error couldnt pause file");

SDL_DestroyWindow(window);
SDL_Quit();
}

TEST_METHOD(Stoptest)
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window = SDL_CreateWindow("", 100, 100, 800, 500, SDL_WINDOW_SHOWN);

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

wpl::VideoPlayer videoPlayer(wmInfo.info.win.window);

Assert::IsTrue(videoPlayer.openVideo("demo.wmv"), L"Error didnt load file");
Assert::IsTrue(videoPlayer.play(), L"Error couldnt play file");
Assert::IsTrue(videoPlayer.stop(), L"Error couldnt stop file");

SDL_DestroyWindow(window);
SDL_Quit();
}

TEST_METHOD(FinishedTest)
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window = SDL_CreateWindow("", 100, 100, 800, 500, SDL_WINDOW_SHOWN);

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

wpl::VideoPlayer videoPlayer(wmInfo.info.win.window);

Assert::IsTrue(videoPlayer.openVideo("demo.wmv"), L"Error didnt load file");
Assert::IsTrue(videoPlayer.play(), L"Error couldnt play file");

SDL_AddTimer(PLAYBACK_TIMEOUT, timeout, nullptr);

auto quit = false;

while (!quit) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
Assert::Fail();
quit = true;
}
}

if (videoPlayer.hasFinished())
quit = true;
}

SDL_DestroyWindow(window);
SDL_Quit();
}
};
}
25 changes: 25 additions & 0 deletions WPL.Tests/Tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#pragma once

#include <windows.h>//different header file in linux
#include <future>

#include "../WPL/WPL.h"
#include "../WPL.Sample/SDL2/SDL.h"
#include "../WPL.Sample/SDL2/SDL_syswm.h"

#pragma comment(lib, "../WPL.Sample/SDL2/SDL2main.lib")
#pragma comment(lib, "../WPL.Sample/SDL2/SDL2.lib")
#pragma comment(lib, "WPL.lib")

#define PLAYBACK_TIMEOUT 15000

template <typename... ParamTypes>
void setTimeout(int milliseconds, std::function<void()> func)
{
std::async(std::launch::async, [=]()
{
Sleep(milliseconds);
func();
});
};
5 changes: 5 additions & 0 deletions WPL.Tests/WPL.Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(OutDir);$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(IncludePath);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -158,6 +160,9 @@
<ClCompile Include="ErrorTests.cpp" />
<ClCompile Include="StateTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Tests.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 5 additions & 0 deletions WPL.Tests/WPL.Tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Tests.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading

0 comments on commit 03b1fa1

Please sign in to comment.