unit-tests-live-ds-common.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
5 // This set of tests is valid only for the DS-device camera //
7 #pragma once
8 #ifndef LIBREALSENSE_UNITTESTS_LIVE_DS_COMMON_H
9 #define LIBREALSENSE_UNITTESTS_LIVE_DS_COMMON_H
10 
11 #include "catch/catch.hpp"
12 
13 #include "unit-tests-common.h"
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <limits>
18 
19 // noexcept is not accepted by Visual Studio 2013 yet, but noexcept(false) is require on throwing destructors on gcc and clang
20 // It is normally advisable not to throw in a destructor, however, this usage is safe for require_error/require_no_error because
21 // they will only ever be created as temporaries immediately before being passed to a C ABI function. All parameters and return
22 // types are vanilla C types, and thus nothrow-copyable, and the function itself cannot throw because it is a C ABI function.
23 // Therefore, when a temporary require_error/require_no_error is destructed immediately following one of these C ABI function
24 // calls, we should not have any exceptions in flight, and can freely throw (perhaps indirectly by calling Catch's REQUIRE()
25 // macro) to indicate postcondition violations.
26 #ifdef WIN32
27 #define NOEXCEPT_FALSE
28 #else
29 #define NOEXCEPT_FALSE noexcept(false)
30 #endif
31 
32 #include "unit-tests-common.h"
33 
34 // TODO consider to expose cameras id strings in rs.hpp via <PID:NAME> construct
35 static const std::vector<std::string> ds_names = { "Intel RealSense R200" ,"Intel RealSense LR200", "Intel RealSense ZR300" };
37 
39 
40 inline void test_ds_device_option(rs_option option, std::initializer_list<int> values, std::initializer_list<int> bad_values, int when)
41 {
44 
46  REQUIRE(dev != nullptr);
47  REQUIRE(std::any_of(ds_names.begin(), ds_names.end(), [&](std::string const& s) {return s == rs_get_device_name(dev, require_no_error()); }));
48 
49  if (when & BEFORE_START_DEVICE)
50  {
51  test_option(dev, option, values, bad_values);
52  }
53 
54  if (when & AFTER_START_DEVICE)
55  {
58 
59  // Currently, setting/getting options immediately after streaming frequently raises hardware errors
60  // todo - Internally block or retry failed calls within the first few seconds after streaming
61  std::this_thread::sleep_for(std::chrono::seconds(1));
62  test_option(dev, option, values, bad_values);
63  }
64 }
65 
66 
67 inline void test_ds_device_streaming(std::initializer_list<stream_mode> modes)
68 {
71 
73  REQUIRE(dev != nullptr);
74  REQUIRE(std::any_of(ds_names.begin(), ds_names.end(), [&](std::string const& s) {return s == rs_get_device_name(dev, require_no_error()); }));
75 
76  test_streaming(dev, modes);
77 }
78 
79 
80 #endif
int rs_get_device_count(const rs_context *context, rs_error **error)
Determines number of connected devices.
Definition: rs.cpp:113
GLsizei const GLchar *const * string
Definition: glext.h:683
#define REQUIRE(expr)
Definition: catch.hpp:9333
const char * rs_get_device_name(const rs_device *device, rs_error **error)
Retrieves human-readable device model string.
Definition: rs.cpp:128
rs_option
Defines general configuration controls.
Definition: rs.h:128
void test_ds_device_streaming(std::initializer_list< stream_mode > modes)
void test_streaming(rs_device *device, std::initializer_list< stream_mode > modes)
auto ctx
GLfloat seconds
Definition: wglext.h:657
void test_option(rs_device *device, rs_option option, std::initializer_list< int > good_values, std::initializer_list< int > bad_values)
GLenum GLsizei GLsizei GLint * values
Definition: glext.h:1484
GLdouble s
Definition: glext.h:231
rs_device * dev
rs_device * rs_get_device(rs_context *context, int index, rs_error **error)
Retrieves connected device by index.
Definition: rs.cpp:120
void rs_enable_stream_preset(rs_device *device, rs_stream stream, rs_preset preset, rs_error **error)
Enables a specific stream and requests properties using a preset.
Definition: rs.cpp:232
void rs_start_device(rs_device *device, rs_error **error)
Begins streaming on all enabled streams for this device.
Definition: rs.cpp:383
void test_ds_device_option(rs_option option, std::initializer_list< int > values, std::initializer_list< int > bad_values, int when)
static const std::vector< std::string > ds_names


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:18