unit-tests-live-ds-common.h
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00005 // This set of tests is valid only for the DS-device camera //
00007 #pragma once
00008 #ifndef LIBREALSENSE_UNITTESTS_LIVE_DS_COMMON_H
00009 #define LIBREALSENSE_UNITTESTS_LIVE_DS_COMMON_H
00010 
00011 #include "catch/catch.hpp"
00012 
00013 #include "unit-tests-common.h"
00014 
00015 #include <algorithm>
00016 #include <iostream>
00017 #include <limits>
00018 
00019 // noexcept is not accepted by Visual Studio 2013 yet, but noexcept(false) is require on throwing destructors on gcc and clang
00020 // It is normally advisable not to throw in a destructor, however, this usage is safe for require_error/require_no_error because
00021 // they will only ever be created as temporaries immediately before being passed to a C ABI function. All parameters and return
00022 // types are vanilla C types, and thus nothrow-copyable, and the function itself cannot throw because it is a C ABI function.
00023 // Therefore, when a temporary require_error/require_no_error is destructed immediately following one of these C ABI function
00024 // calls, we should not have any exceptions in flight, and can freely throw (perhaps indirectly by calling Catch's REQUIRE() 
00025 // macro) to indicate postcondition violations.
00026 #ifdef WIN32
00027 #define NOEXCEPT_FALSE
00028 #else
00029 #define NOEXCEPT_FALSE noexcept(false)
00030 #endif
00031 
00032 #include "unit-tests-common.h"
00033 
00034 // TODO consider to expose cameras id strings in rs.hpp via <PID:NAME> construct
00035 static const std::vector<std::string> ds_names = { "Intel RealSense R200" ,"Intel RealSense LR200", "Intel RealSense ZR300" };
00036 enum { Intel_R200, Intel_LR200, Intel_ZR300};
00037 
00038 enum { BEFORE_START_DEVICE = 1, AFTER_START_DEVICE = 2 };
00039 
00040 inline void test_ds_device_option(rs_option option, std::initializer_list<int> values, std::initializer_list<int> bad_values, int when)
00041 {
00042     safe_context ctx;
00043     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00044 
00045     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00046     REQUIRE(dev != nullptr);
00047     REQUIRE(std::any_of(ds_names.begin(), ds_names.end(), [&](std::string const& s) {return s == rs_get_device_name(dev, require_no_error()); }));
00048 
00049     if (when & BEFORE_START_DEVICE)
00050     {
00051         test_option(dev, option, values, bad_values);
00052     }
00053 
00054     if (when & AFTER_START_DEVICE)
00055     {
00056         rs_enable_stream_preset(dev, RS_STREAM_DEPTH, RS_PRESET_BEST_QUALITY, require_no_error());
00057         rs_start_device(dev, require_no_error());
00058 
00059         // Currently, setting/getting options immediately after streaming frequently raises hardware errors
00060         // todo - Internally block or retry failed calls within the first few seconds after streaming
00061         std::this_thread::sleep_for(std::chrono::seconds(1));
00062         test_option(dev, option, values, bad_values);
00063     }
00064 }
00065 
00066 
00067 inline void test_ds_device_streaming(std::initializer_list<stream_mode> modes)
00068 {
00069     safe_context ctx;
00070     REQUIRE(rs_get_device_count(ctx, require_no_error()) == 1);
00071 
00072     rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00073     REQUIRE(dev != nullptr);
00074     REQUIRE(std::any_of(ds_names.begin(), ds_names.end(), [&](std::string const& s) {return s == rs_get_device_name(dev, require_no_error()); }));
00075 
00076     test_streaming(dev, modes);
00077 }
00078 
00079 
00080 #endif


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:39