1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/win/winrt_storage_util.h"
6
7 #include <string.h>
8 #include <wrl/client.h>
9
10 #include <vector>
11
12 #include "base/strings/string_util.h"
13 #include "base/win/core_winrt_util.h"
14 #include "base/win/scoped_com_initializer.h"
15 #include "base/win/scoped_hstring.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace base {
19 namespace win {
20
TEST(WinrtStorageUtilTest,CreateBufferFromData)21 TEST(WinrtStorageUtilTest, CreateBufferFromData) {
22 ScopedCOMInitializer com_initializer(ScopedCOMInitializer::kMTA);
23
24 const std::vector<uint8_t> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
25 Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
26 ASSERT_HRESULT_SUCCEEDED(
27 CreateIBufferFromData(data.data(), data.size(), &buffer));
28
29 uint8_t* p_buffer_data;
30 uint32_t length;
31 ASSERT_HRESULT_SUCCEEDED(
32 GetPointerToBufferData(buffer.Get(), &p_buffer_data, &length));
33
34 ASSERT_EQ(data.size(), length);
35 EXPECT_EQ(0, memcmp(p_buffer_data, data.data(), data.size()));
36 }
37
38 } // namespace win
39 } // namespace base
40