diff options
author | Gilles Khouzam <gillesk@microsoft.com> | 2014-08-28 13:53:24 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-09-02 14:17:03 (GMT) |
commit | 39fefde25d49b92d8b03eaf13c1b39478e053140 (patch) | |
tree | a1925ec988526102f94e97f5f3aecc1f95530a20 /Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h | |
parent | 89da84657a250b1a1510f49180abc886148facd0 (diff) | |
download | CMake-39fefde25d49b92d8b03eaf13c1b39478e053140.zip CMake-39fefde25d49b92d8b03eaf13c1b39478e053140.tar.gz CMake-39fefde25d49b92d8b03eaf13c1b39478e053140.tar.bz2 |
VS: Add test case for Windows Phone and Windows Store
Add tests to build for each version of each system when the
corresponding tools are available.
Diffstat (limited to 'Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h')
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h new file mode 100644 index 0000000..d411a9b --- /dev/null +++ b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h @@ -0,0 +1,45 @@ +#pragma once + +#include <wrl/client.h> +#include <ppl.h> +#include <ppltasks.h> + +namespace DX +{ + inline void ThrowIfFailed(HRESULT hr) + { + if (FAILED(hr)) + { + // Set a breakpoint on this line to catch Win32 API errors. + throw Platform::Exception::CreateException(hr); + } + } + + // Function that reads from a binary file asynchronously. + inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename) + { + using namespace Windows::Storage; + using namespace Concurrency; + + auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation; + + return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) + { +#if !PHONE + return FileIO::ReadBufferAsync(file); +#else + return file->OpenReadAsync(); + }).then([](Streams::IRandomAccessStreamWithContentType^ stream) + { + unsigned int bufferSize = static_cast<unsigned int>(stream->Size); + auto fileBuffer = ref new Streams::Buffer(bufferSize); + return stream->ReadAsync(fileBuffer, bufferSize, Streams::InputStreamOptions::None); +#endif + }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ + { + auto fileData = ref new Platform::Array<byte>(fileBuffer->Length); + Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData); + return fileData; + }); + } +} |