From 812516d4f88e722888660d4f4ffc9f6176e62783 Mon Sep 17 00:00:00 2001 From: Paolo Oliveira Date: Tue, 23 Jul 2024 18:41:07 -0300 Subject: [PATCH] #10600 add tests --- test/media/ver10/fixtures/get_osds_empty.xml | 21 +++++ .../ver10/fixtures/get_osds_response.xml | 84 +++++++++++++++++++ test/media/ver10/get_osds.exs | 70 ++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 test/media/ver10/fixtures/get_osds_empty.xml create mode 100644 test/media/ver10/fixtures/get_osds_response.xml create mode 100644 test/media/ver10/get_osds.exs diff --git a/test/media/ver10/fixtures/get_osds_empty.xml b/test/media/ver10/fixtures/get_osds_empty.xml new file mode 100644 index 0000000..e850696 --- /dev/null +++ b/test/media/ver10/fixtures/get_osds_empty.xml @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/test/media/ver10/fixtures/get_osds_response.xml b/test/media/ver10/fixtures/get_osds_response.xml new file mode 100644 index 0000000..3938578 --- /dev/null +++ b/test/media/ver10/fixtures/get_osds_response.xml @@ -0,0 +1,84 @@ + + + + + + VideoSourceToken + Text + + Custom + + + + DateAndTime + MM/dd/yyyy + HH:mm:ss + 32 + + + + + false + + + + + VideoSourceToken + Text + + Custom + + + + Plain + 32 + + + + Camera 01 + + true + + + + + + \ No newline at end of file diff --git a/test/media/ver10/get_osds.exs b/test/media/ver10/get_osds.exs new file mode 100644 index 0000000..a40992e --- /dev/null +++ b/test/media/ver10/get_osds.exs @@ -0,0 +1,70 @@ +defmodule Onvif.Media.Ver10.GetOSDsTest do + use ExUnit.Case, async: true + + @moduletag capture_log: true + + describe "GetOSDs/1" do + test "should list 2 OSDs" do + xml_response = + File.read!( + "test/media/ver10/fixtures/get_osds_response.xml" + ) + + device = Onvif.Factory.device() + + Mimic.expect(Tesla, :request, fn _client, _opts -> + {:ok, %{status: 200, body: xml_response}} + end) + + osds = Onvif.Media.Ver10.GetOSDs.request(device) + + assert length(osds) == 2 + assert hd(osds) == %Onvif.Media.Ver10.OSD{ + image: nil, + position: %Onvif.Media.Ver10.OSD.Position{ + pos: %{x: 0.454545, y: -0.733333}, + type: :custom + }, + text_string: %Onvif.Media.Ver10.OSD.TextString{ + background_color: nil, + date_format: nil, + font_color: %Onvif.Media.Ver10.OSD.TextString.FontColor{ + color: %{ + colorspace: "http://www.onvif.org/ver10/colorspace/YCbCr", + x: 0.0, + y: 0.0, + z: 0.0 + }, + transparent: nil + }, + font_size: 32, + is_persistent_text: nil, + plain_text: "Camera 01", + time_format: nil, + type: :plain + }, + token: "OsdToken_100", + type: :text, + video_source_configuration_token: "VideoSourceToken" + } + end + + test "should have no OSD available" do + xml_response = + File.read!( + "test/media/ver10/fixtures/get_osds_empty.xml" + ) + + device = Onvif.Factory.device() + + Mimic.expect(Tesla, :request, fn _client, _opts -> + {:ok, %{status: 200, body: xml_response}} + end) + + osds = Onvif.Media.Ver10.GetOSDs.request(device) + + assert length(osds) == 0 + end + + end +end