Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions WebRtcInterop.UnitTests/Marshaling/MarshalMediaTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "gtest/gtest.h"

#include "Media/Marshaling/MarshalMedia.h"
#include "Marshaling/MarshalMediaConstraints.h"

using namespace msclr::interop;
using namespace System;
Expand Down Expand Up @@ -100,3 +101,105 @@ TEST(marshal_media_track_kind_tests, marshal_native_track_kind_invalid_throws)
{
}
}

TEST(marshal_media_mode_value_tests, marshal_unknown_native_facing_mode_preserves_raw_value)
{
auto result = marshal_as<VideoFacingModeValue>(std::string("vendor-facing-mode"));
ASSERT_EQ(result.IsKnown, false);
ASSERT_EQ(marshal_as<std::string>(result.RawValue), "vendor-facing-mode");
}

TEST(marshal_media_mode_value_tests, marshal_unknown_native_resize_mode_preserves_raw_value)
{
auto result = marshal_as<VideoResizeModeValue>(std::string("vendor-resize-mode"));
ASSERT_EQ(result.IsKnown, false);
ASSERT_EQ(marshal_as<std::string>(result.RawValue), "vendor-resize-mode");
}

TEST(marshal_media_mode_value_tests, marshal_unknown_managed_facing_mode_to_native_throws)
{
try
{
VideoFacingModeValue value(gcnew String("vendor-facing-mode"));
const auto _ = marshal_video_facing_mode_value_to_native(value);
FAIL();
}
catch (InvalidCastException^)
{
}
}

TEST(marshal_media_mode_value_tests, marshal_unknown_managed_resize_mode_to_native_throws)
{
try
{
VideoResizeModeValue value(gcnew String("vendor-resize-mode"));
const auto _ = marshal_video_resize_mode_value_to_native(value);
FAIL();
}
catch (InvalidCastException^)
{
}
}

TEST(marshal_media_constraints_tests, marshal_media_stream_constraints_includes_advanced_and_echo_cancellation)
{
auto videoTrackConstraints = gcnew MediaTrackConstraints();
videoTrackConstraints->Width = gcnew MediaTrackConstraints::PositiveUIntRangeConstraint();
videoTrackConstraints->Width->Min = 640;
videoTrackConstraints->Width->Max = 1280;
videoTrackConstraints->Width->Ideal = 800;

videoTrackConstraints->EchoCancellation = gcnew EchoCancellationConstraint();
videoTrackConstraints->EchoCancellation->Ideal = EchoCancellationValue(EchoCancellationMode::Software);

videoTrackConstraints->Advanced = gcnew System::Collections::Generic::List<MediaTrackConstraintSet^>();
auto advancedSet = gcnew MediaTrackConstraintSet();
advancedSet->BackgroundBlur = gcnew MediaTrackConstraints::Constraint<bool>(true);
videoTrackConstraints->Advanced->Add(advancedSet);

auto streamConstraints = gcnew MediaStreamConstraints(true, videoTrackConstraints);
auto marshaled = marshal_as(streamConstraints);

ASSERT_EQ(marshaled.audio_requested, true);
ASSERT_EQ(marshaled.video_requested, true);
ASSERT_TRUE(marshaled.video_constraints.has_value());
ASSERT_EQ(marshaled.video_constraints->advanced.size(), 1u);
ASSERT_TRUE(marshaled.video_constraints->basic.width.has_value());
ASSERT_TRUE(marshaled.video_constraints->basic.echo_cancellation.has_value());
ASSERT_TRUE(marshaled.video_constraints->basic.echo_cancellation->ideal.has_value());
ASSERT_TRUE(marshaled.video_constraints->basic.echo_cancellation->ideal->mode_value.has_value());
ASSERT_EQ(marshaled.video_constraints->basic.echo_cancellation->ideal->mode_value.value(), "software");
}

TEST(media_stream_track_constraint_plumbing_tests, apply_constraints_with_unknown_facing_mode_throws)
{
auto constraints = gcnew MediaTrackConstraints();
constraints->FacingMode = gcnew MediaTrackConstraints::Constraint<VideoFacingModeValue>(VideoFacingModes::User);
constraints->FacingMode->Exact = VideoFacingModeValue(gcnew String("vendor-facing-mode"));

try
{
const auto _ = marshal_as(constraints);
FAIL();
}
catch (InvalidCastException^)
{
}
}

TEST(media_stream_track_constraint_plumbing_tests, apply_constraints_with_unknown_resize_mode_throws)
{
auto constraints = gcnew MediaTrackConstraints();
constraints->ResizeMode = gcnew MediaTrackConstraints::Constraint<VideoResizeModeValue>(VideoResizeModes::None);
constraints->ResizeMode->Exact = VideoResizeModeValue(gcnew String("vendor-resize-mode"));

try
{
const auto _ = marshal_as(constraints);
FAIL();
}
catch (InvalidCastException^)
{
}
}
7 changes: 2 additions & 5 deletions WebRtcInterop/Marshaling/MarshalEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ managed_type marshal_mapped_native_type(const std::map<const native_type, const
auto entry = map.find(from);
if (entry == map.end())
{
throw gcnew System::InvalidCastException(System::String::Format("Unable to convert {0} value '{1}' to {2}",
native_type::typeid->FullName, static_cast<int>(from), managed_type::typeid->FullName));
throw gcnew System::InvalidCastException("Unable to convert native value to managed type.");
}

return entry->second;
Expand All @@ -23,7 +22,5 @@ native_type marshal_mapped_managed_type(const std::map<const native_type, const
if (value == from) return key;
}

throw gcnew System::InvalidCastException(System::String::Format("Unable to convert {0} value '{1}' to {2}",
managed_type::typeid->FullName, System::Enum::GetName(managed_type::typeid, from),
native_type::typeid->FullName));
throw gcnew System::InvalidCastException("Unable to convert managed value to native type.");
}
Loading
Loading