--- /dev/null
+// Copyright 2022 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace Tizen.Multimedia.Vision.Tests
+{
+ [TestFixture]
+ [Description("Tizen.Multimedia.Vision.DeepLearningFaceRecognizer test class")]
+ public class DeepLearningFaceRecognizerTests
+ {
+ private DeepLearningFaceRecognizer _recognizer;
+ private MediaVisionSource _source;
+
+ private async Task PrepareModelAndSourceAsync()
+ {
+ _source = await TestHelper.GetMediaSourceFromImage(TestHelper.ResourcePath + "face_recog/P1/04.jpg");
+ }
+
+ [SetUp]
+ public void Init()
+ {
+ try
+ {
+ Task t = Task.Run(async () => await PrepareModelAndSourceAsync());
+ t.Wait();
+
+ _recognizer = new DeepLearningFaceRecognizer();
+ }
+ catch (NotSupportedException) when (FeatureChecker.IsSupported(Features.FaceRecognition) == false)
+ {
+ Assert.Pass("Face recognition is not supported");
+ }
+ }
+
+ [TearDown]
+ public void Destroy()
+ {
+ _recognizer?.Dispose();
+ _source?.Dispose();
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Object should not be null after initializing")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.DeepLearningFaceRecognizer C")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "CONSTR")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void DeepLearningFaceRecognizer_INIT()
+ {
+ var recognizer = new DeepLearningFaceRecognizer();
+
+ Assert.IsNotNull(recognizer, "Should not be null");
+ Assert.IsInstanceOf<DeepLearningFaceRecognizer>(recognizer, "It should be the instance of DeepLearningFaceRecognizer.");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test RegisterFace whether throws exception or not.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.RegisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void RegisterFace_NO_EXCEPTION()
+ {
+ Assert.That(() => _recognizer.RegisterFace(_source, "tc_test"), Throws.Nothing,
+ "Should not throw exception");
+
+ _recognizer.UnregisterFace("tc_test");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test RegisterFace whether throws ObjectDisposedException if DeepLearningFaceRecognizer is already disposed.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.RegisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void RegisterFace_THROWS_IF_ALREADY_DISPOSED()
+ {
+ _recognizer.Dispose();
+
+ Assert.That(() => _recognizer.RegisterFace(_source, "test"),
+ Throws.TypeOf<ObjectDisposedException>(), "Should throw ObjectDisposedException");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test RegisterFace whether throws ArgumentNullException if argument is null.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.RegisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void RegisterFace_THROWS_IF_NULL_PARAM()
+ {
+ Assert.That(() => _recognizer.RegisterFace(null, "test"),
+ Throws.ArgumentNullException, "Should throw ArgumentNullException");
+
+ Assert.That(() => _recognizer.RegisterFace(_source, null),
+ Throws.ArgumentNullException, "Should throw ArgumentNullException");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test UnregisterFace whether throws exception or not.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.UnregisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void UnregisterFace_NO_EXCEPTION()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+
+ Assert.That(() => _recognizer.UnregisterFace("tc_test"), Throws.Nothing,
+ "Should not throw exception");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test UnregisterFace whether throws ObjectDisposedException if DeepLearningFaceRecognizer is already disposed.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.UnregisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void UnregisterFace_THROWS_IF_ALREADY_DISPOSED()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+
+ _recognizer.Dispose();
+
+ Assert.That(() => _recognizer.UnregisterFace("tc_test"),
+ Throws.TypeOf<ObjectDisposedException>(), "Should throw ObjectDisposedException");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test UnregisterFace whether throws ArgumentNullException if argument is null.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.UnregisterFace M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void UnregisterFace_THROWS_IF_NULL_PARAM()
+ {
+ Assert.That(() => _recognizer.UnregisterFace(null),
+ Throws.ArgumentNullException, "Should throw ArgumentNullException");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test Recognize whether throws exception or not.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.Recognize M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void Recognize_NO_EXCEPTION()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+
+ Assert.That(() => _recognizer.Recognize(_source), Throws.Nothing,
+ "Should not throw exception");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test Recognize whether throws ObjectDisposedException if DeepLearningFaceRecognizer is already disposed.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.Recognize M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void Recognize_THROWS_IF_ALREADY_DISPOSED()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+
+ _recognizer.Dispose();
+
+ Assert.That(() => _recognizer.Recognize(_source),
+ Throws.TypeOf<ObjectDisposedException>(), "Should throw ObjectDisposedException");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test Recognize whether throws ArgumentNullException if argument is null.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognizer.Recognize M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void Recognize_THROWS_IF_NULL_PARAM()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+
+ Assert.That(() => _recognizer.Recognize(null),
+ Throws.ArgumentNullException, "Should throw ArgumentNullException");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Check whether Label returns expected value or not.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognitionResult.Label M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void Label_READ_ONLY()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+ var result = _recognizer.Recognize(_source);
+
+ Assert.That(() => result.Label, Throws.Nothing,
+ "Should not throw nothing");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Check whether ToString returns expected value or not.")]
+ [Property("SPEC", "Tizen.Multimedia.Vision.DeepLearningFaceRecognitionResult.ToString M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+ public void ToString_CHECK_VALUE()
+ {
+ _recognizer.RegisterFace(_source, "tc_test");
+ var result = _recognizer.Recognize(_source);
+
+ Assert.AreEqual($"Label={result.Label}", result.ToString(),
+ "Should be same string");
+ }
+ }
+}