|
1 | 1 | #include "catch.hpp" |
2 | 2 | #include "helpers.h" |
| 3 | +#include "helper_type.hpp" |
3 | 4 | #include <cstdint> |
4 | 5 | #include <lsl_cpp.h> |
5 | 6 |
|
6 | | - |
7 | | -namespace { |
8 | | -template <typename T> void test_DataType(const char *name, lsl::channel_format_t cf) { |
9 | | - const int numBounces = sizeof(T) * 8; |
| 7 | +TEMPLATE_TEST_CASE("datatransfer", "[datatransfer][basic]", char, int16_t, int32_t, int64_t, float, double) { |
| 8 | + const int numBounces = sizeof(TestType) * 8; |
10 | 9 | double timestamps[numBounces][2]; |
| 10 | + const char* name = SampleType<TestType>::fmt_string(); |
| 11 | + lsl::channel_format_t cf = (lsl::channel_format_t) SampleType<TestType>::chan_fmt; |
11 | 12 |
|
12 | 13 | Streampair sp(create_streampair( |
13 | | - lsl::stream_info(name, "Bounce", 1, lsl::IRREGULAR_RATE, cf, "streamid"))); |
| 14 | + lsl::stream_info(name, "Bounce", 2, lsl::IRREGULAR_RATE, cf, "streamid"))); |
14 | 15 | lsl::stream_inlet &inlet = sp.in_; |
15 | 16 | lsl::stream_outlet &outlet = sp.out_; |
16 | 17 |
|
17 | 18 | inlet.open_stream(2); |
18 | 19 | outlet.wait_for_consumers(2); |
19 | 20 |
|
20 | | - T sent_data = 0x1; |
| 21 | + TestType sent_data[2] = {0x1, 0x1}; |
21 | 22 | for (int32_t counter = 0; counter < numBounces; counter++) { |
22 | | - T received_data; |
| 23 | + TestType received_data[2]; |
23 | 24 | timestamps[counter][0] = lsl::local_clock(); |
24 | | - outlet.push_sample(&sent_data, timestamps[counter][0], true); |
| 25 | + sent_data[1] = -sent_data[0] + 1; |
| 26 | + outlet.push_sample(sent_data, timestamps[counter][0], true); |
25 | 27 |
|
26 | | - CHECK(inlet.pull_sample(&received_data, 1, .5) != 0.0); |
| 28 | + CHECK(inlet.pull_sample(received_data, 2, .5) != 0.0); |
27 | 29 |
|
28 | 30 | timestamps[counter][1] = lsl::local_clock(); |
29 | | - CHECK(received_data == sent_data); |
30 | | - sent_data = static_cast<T>(sent_data << 1); |
31 | | - } |
32 | | -} |
33 | | - |
34 | | -TEST_CASE("data type int8", "[datatransfer][basic]") { test_DataType<char>("cf_int8", lsl::cf_int8); } |
35 | | -TEST_CASE("data type int16", "[datatransfer][basic]") { test_DataType<int16_t>("cf_int16", lsl::cf_int16); } |
36 | | -TEST_CASE("data type int32", "[datatransfer][basic]") { test_DataType<int32_t>("cf_int32", lsl::cf_int32); } |
37 | | -TEST_CASE("data type int64", "[datatransfer][basic]") { test_DataType<int64_t>("cf_int64", lsl::cf_int64); } |
38 | | - |
39 | | -template <typename T> void test_DataTypeMulti(const char *name, lsl::channel_format_t cf) { |
40 | | - const int numChannels = sizeof(T) * 8; |
41 | | - |
42 | | - Streampair sp(create_streampair( |
43 | | - lsl::stream_info(name, "Bounce", numChannels, lsl::IRREGULAR_RATE, cf, "streamid"))); |
44 | | - lsl::stream_inlet &inlet = sp.in_; |
45 | | - lsl::stream_outlet &outlet = sp.out_; |
46 | | - |
47 | | - std::vector<T> sent_data(numChannels); |
48 | | - T data = 0x1LL; |
49 | | - for (uint32_t counter = 0; counter < numChannels; counter++) { |
50 | | - sent_data[counter] = data; |
51 | | - data = static_cast<T>(data << 1LL); |
| 31 | + CHECK(received_data[0] == sent_data[0]); |
| 32 | + CHECK(received_data[1] == sent_data[1]); |
| 33 | + sent_data[0] = static_cast<TestType>(static_cast<int64_t>(sent_data[0]) << 1); |
52 | 34 | } |
53 | | - |
54 | | - std::vector<T> received_data(numChannels); |
55 | | - outlet.push_sample(sent_data, lsl::local_clock(), true); |
56 | | - CHECK(inlet.pull_sample(received_data, 0.5) != 0.0); |
57 | | - CHECK(received_data == sent_data); |
58 | 35 | } |
59 | 36 |
|
60 | | -TEST_CASE("data type int8 multi", "[datatransfer][multi]") { test_DataTypeMulti<char>("cf_int8", lsl::cf_int8); } |
61 | | -TEST_CASE("data type int16 multi", "[datatransfer][multi]") { test_DataTypeMulti<int16_t>("cf_int16", lsl::cf_int16); } |
62 | | -TEST_CASE("data type int32 multi", "[datatransfer][multi]") { test_DataTypeMulti<int32_t>("cf_int32", lsl::cf_int32); } |
63 | | -TEST_CASE("data type int64 multi", "[datatransfer][multi]") { test_DataTypeMulti<int64_t>("cf_int64", lsl::cf_int64); } |
64 | | - |
65 | 37 | TEST_CASE("data datatransfer", "[datatransfer][multi][string]") { |
66 | 38 | const std::size_t numChannels = 2; |
67 | 39 |
|
@@ -104,4 +76,3 @@ TEST_CASE("data typeconversion", "[datatransfer][types][basic]") { |
104 | 76 | } |
105 | 77 | } |
106 | 78 |
|
107 | | -} // namespace |
0 commit comments