Skip to content

Commit 9b20964

Browse files
authored
Merge pull request #1861 from aarongreig/aaron/addSetDataToMockHandle
Add getData/setData to mock dummy handle
2 parents fa6bf97 + 65b4431 commit 9b20964

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/mock/ur_mock_helpers.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ur_api.h"
1616

1717
#include <atomic>
18+
#include <cassert>
1819
#include <cstddef>
1920
#include <string>
2021
#include <unordered_map>
@@ -36,6 +37,16 @@ struct dummy_handle_t_ {
3637
std::vector<unsigned char> MStorage;
3738
unsigned char *MData = nullptr;
3839
size_t MSize;
40+
41+
template <typename T> T getDataAs() {
42+
assert(MStorage.size() >= sizeof(T));
43+
return *reinterpret_cast<T *>(MStorage.data());
44+
}
45+
46+
template <typename T> T setDataAs(T Val) {
47+
assert(MStorage.size() >= sizeof(T));
48+
return *reinterpret_cast<T *>(MStorage.data()) = Val;
49+
}
3950
};
4051

4152
using dummy_handle_t = dummy_handle_t_ *;

0 commit comments

Comments
 (0)