-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtests.cpp
More file actions
38 lines (32 loc) · 1001 Bytes
/
tests.cpp
File metadata and controls
38 lines (32 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cassert>
#include <vector>
#include "NonWindows.hpp"
/** Convert raw array to SafeArray. */
template <class T>
CComSafeArray<T> ConvertToSafeArray (const T * input, size_t element_count) {
CComSafeArray<T> result(static_cast<ULONG>(element_count));
if (element_count > 0) {
T * out_ptr = &result.GetAt(0); // will fail if empty
for (size_t i = 0; i < element_count; ++i)
out_ptr[i] = input[i];
}
return result;
}
void TestCComSafeArray() {
std::vector<double> vals = {2.0, 3.0, 4.0};
{
printf("direct assigmnent...\n");
CComSafeArray<double> sa_vals = ConvertToSafeArray(vals.data(), vals.size());
assert(sa_vals.GetCount() == 3);
}
{
printf("copy-assignment...\n");
CComSafeArray<double> sa_vals;
sa_vals = ConvertToSafeArray(vals.data(), vals.size());
assert(sa_vals.GetCount() == 3);
}
}
int main() {
printf("Running tests...\n");
TestCComSafeArray();
}