File: streaminfo.cpp

package info (click to toggle)
liblsl 1.16.2b1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,724 kB
  • sloc: cpp: 12,515; ansic: 666; python: 28; sh: 25; makefile: 18
file content (29 lines) | stat: -rw-r--r-- 970 bytes parent folder | download
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
#include <catch2/catch.hpp>
#include <lsl_cpp.h>
#include <thread>

// clazy:excludeall=non-pod-global-static

namespace {

TEST_CASE("streaminfo", "[streaminfo][basic]") {
	CHECK_THROWS(lsl::stream_info("", "emptyname"));
	REQUIRE(std::string("The name of a stream must be non-empty.") == lsl_last_error());
}

TEST_CASE("multithreaded lsl_last_error", "[threading][basic]") {
	CHECK_THROWS(lsl::stream_info("", "emptyname"));
	std::thread([](){
		CHECK_THROWS(lsl::stream_info("hasname","type", -1));
		REQUIRE(std::string("The channel_count of a stream must be nonnegative.") == lsl_last_error());
	}).join();
	REQUIRE(std::string("The name of a stream must be non-empty.") == lsl_last_error());
}

/// Ensure that an overly long error message won't overflow the buffer
TEST_CASE("lsl_last_error size", "[basic]") {
	std::string invalidquery(511, '\'');
	CHECK_THROWS(lsl::resolve_stream(invalidquery, 1, 0.1));
	REQUIRE(lsl_last_error()[511] == 0);
}
} // namespace