From c13c0ba633375569fce631d1b2e8debb0c271d87 Mon Sep 17 00:00:00 2001 From: doronhi Date: Tue, 2 Mar 2021 08:45:00 +0200 Subject: [PATCH 1/5] test video_stream_profile operator== fails. --- unit-tests/types/test-profile-eq.cpp | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 unit-tests/types/test-profile-eq.cpp diff --git a/unit-tests/types/test-profile-eq.cpp b/unit-tests/types/test-profile-eq.cpp new file mode 100644 index 0000000000..5a8a8986df --- /dev/null +++ b/unit-tests/types/test-profile-eq.cpp @@ -0,0 +1,39 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2020 Intel Corporation. All Rights Reserved. + +#include "../func/func-common.h" +#include "../../include/librealsense2/hpp/rs_frame.hpp" +#include + +using namespace rs2; + +TEST_CASE("test video_stream_profile operator==", "[live]") +{ + auto devices = find_devices_by_product_line_or_exit(RS2_PRODUCT_LINE_ANY_INTEL); + auto dev = devices[0]; + + auto depth_sens = dev.first< rs2::depth_sensor >(); + + REQUIRE_NOTHROW(depth_sens.set_option(RS2_OPTION_EMITTER_ON_OFF, 1)); + + stream_profile profile0, profile1; + std::vector< stream_profile > stream_profiles; + REQUIRE_NOTHROW(stream_profiles = depth_sens.get_stream_profiles()); + profile0 = stream_profiles[0]; + video_stream_profile vprofile0 = profile0.as(); + + for (auto profile : stream_profiles) + { + if (profile == profile0) + { + video_stream_profile vprofile = profile.as(); + if (vprofile0.width() != vprofile.width() || + vprofile0.height() != vprofile.height()) + { + //std::cout << "compare: " << vprofile0.stream_type() << "(" << vprofile0.stream_index() << "):" << vprofile0.width() << "x" << vprofile0.height() << " with:" << + // vprofile.stream_type() << "(" << vprofile.stream_index() << "):" << vprofile.width() << "x" << vprofile.height() << std::endl; + REQUIRE(!(vprofile0 == vprofile)); + } + } + } +} \ No newline at end of file From 8e56675e20f50c9cc322600d9a605754d48693c3 Mon Sep 17 00:00:00 2001 From: doronhi Date: Tue, 2 Mar 2021 08:45:26 +0200 Subject: [PATCH 2/5] add video_stream_profile::operator== --- include/librealsense2/hpp/rs_frame.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/librealsense2/hpp/rs_frame.hpp b/include/librealsense2/hpp/rs_frame.hpp index c151209d98..4b70553683 100644 --- a/include/librealsense2/hpp/rs_frame.hpp +++ b/include/librealsense2/hpp/rs_frame.hpp @@ -244,6 +244,13 @@ namespace rs2 return intr; } + bool operator==(const video_stream_profile& other) const + { + return (((stream_profile&)*this)==other && + width() == other.width() && + height() == other.height()); + } + using stream_profile::clone; /** From bedec8bebc3a6e1025f0cf589876377e0547d81b Mon Sep 17 00:00:00 2001 From: doronhi Date: Mon, 8 Mar 2021 10:06:23 +0200 Subject: [PATCH 3/5] Add test for equal profiles. Clean. --- unit-tests/types/test-profile-eq.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/unit-tests/types/test-profile-eq.cpp b/unit-tests/types/test-profile-eq.cpp index 5a8a8986df..e95bde8bdb 100644 --- a/unit-tests/types/test-profile-eq.cpp +++ b/unit-tests/types/test-profile-eq.cpp @@ -9,16 +9,18 @@ using namespace rs2; TEST_CASE("test video_stream_profile operator==", "[live]") { + // Test that for 2 video_stream_profile objects, if width and height are different + // then, video_stream_profile.operator== returns false. + auto devices = find_devices_by_product_line_or_exit(RS2_PRODUCT_LINE_ANY_INTEL); auto dev = devices[0]; auto depth_sens = dev.first< rs2::depth_sensor >(); - REQUIRE_NOTHROW(depth_sens.set_option(RS2_OPTION_EMITTER_ON_OFF, 1)); - stream_profile profile0, profile1; std::vector< stream_profile > stream_profiles; REQUIRE_NOTHROW(stream_profiles = depth_sens.get_stream_profiles()); + REQUIRE_NOTHROW(stream_profiles.size() > 1); profile0 = stream_profiles[0]; video_stream_profile vprofile0 = profile0.as(); @@ -27,13 +29,15 @@ TEST_CASE("test video_stream_profile operator==", "[live]") if (profile == profile0) { video_stream_profile vprofile = profile.as(); - if (vprofile0.width() != vprofile.width() || - vprofile0.height() != vprofile.height()) + if (vprofile0.width() == vprofile.width() && + vprofile0.height() == vprofile.height()) + { + REQUIRE(vprofile0 == vprofile); + } + else { - //std::cout << "compare: " << vprofile0.stream_type() << "(" << vprofile0.stream_index() << "):" << vprofile0.width() << "x" << vprofile0.height() << " with:" << - // vprofile.stream_type() << "(" << vprofile.stream_index() << "):" << vprofile.width() << "x" << vprofile.height() << std::endl; REQUIRE(!(vprofile0 == vprofile)); } } } -} \ No newline at end of file +} From 0ae3b2409cc68009aed09f4d680bdb5998a69758 Mon Sep 17 00:00:00 2001 From: doronhi Date: Mon, 8 Mar 2021 10:33:32 +0200 Subject: [PATCH 4/5] quit test if no device found or if device has no depth profile. --- unit-tests/types/test-profile-eq.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/unit-tests/types/test-profile-eq.cpp b/unit-tests/types/test-profile-eq.cpp index e95bde8bdb..810da25686 100644 --- a/unit-tests/types/test-profile-eq.cpp +++ b/unit-tests/types/test-profile-eq.cpp @@ -13,6 +13,7 @@ TEST_CASE("test video_stream_profile operator==", "[live]") // then, video_stream_profile.operator== returns false. auto devices = find_devices_by_product_line_or_exit(RS2_PRODUCT_LINE_ANY_INTEL); + if (devices.size() == 0) return; auto dev = devices[0]; auto depth_sens = dev.first< rs2::depth_sensor >(); @@ -20,12 +21,19 @@ TEST_CASE("test video_stream_profile operator==", "[live]") stream_profile profile0, profile1; std::vector< stream_profile > stream_profiles; REQUIRE_NOTHROW(stream_profiles = depth_sens.get_stream_profiles()); - REQUIRE_NOTHROW(stream_profiles.size() > 1); - profile0 = stream_profiles[0]; + for (auto profile : stream_profiles) + { + if (profile.is()) + { + profile0 = profile; + } + } + if (!profile0) return; video_stream_profile vprofile0 = profile0.as(); for (auto profile : stream_profiles) { + if (!profile.is()) continue; if (profile == profile0) { video_stream_profile vprofile = profile.as(); From e45f44a7d17f250060205d9699afbbe03ba0097f Mon Sep 17 00:00:00 2001 From: doronhi Date: Mon, 8 Mar 2021 14:11:48 +0200 Subject: [PATCH 5/5] Run test on depth devices only. --- unit-tests/types/test-profile-eq.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit-tests/types/test-profile-eq.cpp b/unit-tests/types/test-profile-eq.cpp index 810da25686..63666970fd 100644 --- a/unit-tests/types/test-profile-eq.cpp +++ b/unit-tests/types/test-profile-eq.cpp @@ -12,7 +12,7 @@ TEST_CASE("test video_stream_profile operator==", "[live]") // Test that for 2 video_stream_profile objects, if width and height are different // then, video_stream_profile.operator== returns false. - auto devices = find_devices_by_product_line_or_exit(RS2_PRODUCT_LINE_ANY_INTEL); + auto devices = find_devices_by_product_line_or_exit(RS2_PRODUCT_LINE_DEPTH); if (devices.size() == 0) return; auto dev = devices[0];