[MediaContent][TCSACR-239] Change Delete() method behavior to remove the risk of... 66/203166/4
authorHaesu Gwon <haesu.gwon@samsung.com>
Wed, 10 Apr 2019 08:36:19 +0000 (17:36 +0900)
committerHaesu Gwon <haesu.gwon@samsung.com>
Wed, 17 Apr 2019 01:29:37 +0000 (10:29 +0900)
Change-Id: If04a68e5eca8dc8db47fc6c2d8cdd3a8d2419511

tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSCountArguments.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSMediaDatabase.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSMediaInfoCommand.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSMediaInfoCommand_DetectFace.cs
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSSelectArguments.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/support/BookmarkTestBase.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/support/MediaInfoCommandTestBase.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/support/TestBase.cs [changed mode: 0755->0644]
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/support/TestConstants.cs
tct-suite-vs/Tizen.Mediacontent.Tests/testcase/support/TestSupport.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 00347d4..4c9798f
@@ -1,4 +1,5 @@
 using NUnit.Framework;
+using System.IO;
 
 namespace Tizen.Content.MediaContent.Tests
 {
@@ -13,6 +14,9 @@ namespace Tizen.Content.MediaContent.Tests
         public void SetUp()
         {
             _mediaInfoCmd = new MediaInfoCommand(_database);
+
+            TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
             _mediaInfo = _mediaInfoCmd.Add(TestConstants.AudioFile);
 
             var bookmarkCmd = new BookmarkCommand(_database);
old mode 100755 (executable)
new mode 100644 (file)
index ade8eef..8bb6e0a
@@ -118,8 +118,9 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public async Task MediaInfoUpdated_INSERT_CHECK()
         {
+            TestSupport.ClearDatabase(_database, TestConstants.ImageFile, true);
+
             var cmd = new MediaInfoCommand(_database);
-            cmd.Delete(cmd.Add(TestConstants.ImageFile).Id);
 
             TaskCompletionSource<OperationType> tcs = new TaskCompletionSource<OperationType>();
 
old mode 100755 (executable)
new mode 100644 (file)
index 64762e1..e3ddc55
@@ -562,7 +562,16 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public void Delete_RETURN()
         {
-            Assert.That(() => _cmd.Delete(_mediaInfo.Id), Is.True);
+            var path = TestSupport.BackupFileWithMediaId(_database, _mediaInfo.Id);
+
+            try
+            {
+                Assert.That(() => _cmd.Delete(_mediaInfo.Id), Is.True);
+            }
+            finally
+            {
+                TestSupport.RestoreFile(path);
+            }
         }
 
         [Test]
@@ -1090,7 +1099,11 @@ namespace Tizen.Content.MediaContent.Tests
         {
             var dest = TestConstants.RootPath + "/temp.jpg";
             File.Copy(TestConstants.ImageFile, dest, true);
-            _cmd.Delete(_cmd.Add(dest).Id);
+
+            var mediaId = _cmd.Add(dest).Id;
+            var path = TestSupport.ClearDatabaseWithMediaId(_database, mediaId);
+            _cmd.Delete(mediaId);
+            TestSupport.RestoreFile(path);
 
             Assert.That(_cmd.Move(_mediaInfo.Id, dest), Is.True);
         }
@@ -1253,8 +1266,17 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public void CreateThumbnailAsync_THROWS_IF_MEDIA_DELETED()
         {
+            var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
             _cmd.Delete(_mediaInfo.Id);
-            Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id), Throws.ArgumentException);
+
+            try
+            {
+                Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id), Throws.ArgumentException);
+            }
+            finally
+            {
+                TestSupport.RestoreFile(path);
+            }
         }
 
         [Test]
@@ -1377,6 +1399,7 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public void CreateThumbnailAsync_WITH_CANCELLATION_THROWS_IF_MEDIA_NOT_EXIST()
         {
+            TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id, true);
             _cmd.Delete(_mediaInfo.Id);
             Assert.That(() => _cmd.CreateThumbnailAsync(_mediaInfo.Id, CancellationToken.None),
                 Throws.ArgumentException);
index 9bf6f3f..2de0395 100644 (file)
@@ -130,8 +130,17 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public void DetectFaceAsync_THROWS_IF_MEDIA_DELETED()
         {
-            _cmd.Delete(_mediaInfo.Id);
-            Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id), Throws.ArgumentException);
+            var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
+
+            try
+            {
+                _cmd.Delete(_mediaInfo.Id);
+                Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id), Throws.ArgumentException);
+            }
+            finally
+            {
+                TestSupport.RestoreFile(path);
+            }
         }
 
         [Test]
@@ -256,9 +265,18 @@ namespace Tizen.Content.MediaContent.Tests
         [Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
         public void DetectFaceAsync_WITH_CANCELLATION_THROWS_IF_MEDIA_NOT_EXIST()
         {
-            _cmd.Delete(_mediaInfo.Id);
-            Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id, CancellationToken.None),
-                Throws.ArgumentException);
+            var path = TestSupport.ClearDatabaseWithMediaId(_database, _mediaInfo.Id);
+
+            try
+            {
+                _cmd.Delete(_mediaInfo.Id);
+                Assert.That(() => _cmd.DetectFaceAsync(_mediaInfo.Id, CancellationToken.None),
+                    Throws.ArgumentException);
+            }
+            finally
+            {
+                TestSupport.RestoreFile(path);
+            }
         }
 
         [Test]
old mode 100755 (executable)
new mode 100644 (file)
index c07a833..d816981
@@ -14,6 +14,9 @@ namespace Tizen.Content.MediaContent.Tests
         public void SetUp()
         {
             _mediaInfoCmd = new MediaInfoCommand(_database);
+
+            TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
             _mediaInfo = _mediaInfoCmd.Add(TestConstants.AudioFile);
 
             var bookmarkCmd = new BookmarkCommand(_database);
old mode 100755 (executable)
new mode 100644 (file)
index fbad939..78d304a
@@ -14,7 +14,11 @@ namespace Tizen.Content.MediaContent.Tests
         [SetUp]
         public new void SetUpBase()
         {
-            _mediaInfo = new MediaInfoCommand(_database).Add(TestConstants.AudioFile);
+            var mediaCmd = new MediaInfoCommand(_database);
+
+            TestSupport.ClearDatabase(_database, TestConstants.AudioFile, true);
+
+            _mediaInfo = mediaCmd.Add(TestConstants.AudioFile);
 
             _bookmark = new BookmarkCommand(_database).
                 Insert(_mediaInfo.Id, Offset, BookmarkName, ThumbnailPath);
old mode 100755 (executable)
new mode 100644 (file)
index efcf212..0d652e7
@@ -13,6 +13,8 @@ namespace Tizen.Content.MediaContent.Tests
         {
             _cmd = new MediaInfoCommand(_database);
 
+            TestSupport.ClearDatabase(_database, TestConstants.FaceImageFile, true);
+
             _mediaInfo = _cmd.Add(TestConstants.FaceImageFile);
         }
     }
old mode 100755 (executable)
new mode 100644 (file)
index 63dcfdb..14e99fc
@@ -1,3 +1,5 @@
+using System.IO;
+using System.Collections.Generic;
 using NUnit.Framework;
 
 namespace Tizen.Content.MediaContent.Tests
@@ -6,26 +8,6 @@ namespace Tizen.Content.MediaContent.Tests
     {
         protected MediaDatabase _database;
 
-        private void ClearDatabase()
-        {
-            var mediaInfoCmd = new MediaInfoCommand(_database);
-            var reader = mediaInfoCmd.SelectMedia();
-
-            while (reader.Read())
-            {
-                mediaInfoCmd.Delete(reader.Current.Id);
-            }
-
-            var tagCmd = new TagCommand(_database);
-
-            var tagReader = tagCmd.Select();
-
-            while (tagReader.Read())
-            {
-                tagCmd.Delete(tagReader.Current.Id);
-            }
-        }
-
         [SetUp]
         public void SetUpBase()
         {
@@ -45,5 +27,78 @@ namespace Tizen.Content.MediaContent.Tests
         {
             _database.Dispose();
         }
+
+        private void ClearDatabase()
+        {
+            var mediaInfoCmd = new MediaInfoCommand(_database);
+
+            var filter = new SelectArguments
+            {
+                FilterExpression = $"{MediaInfoColumns.Path}='{TestConstants.RootPath}'"
+            };
+
+            var reader = mediaInfoCmd.SelectMedia(filter);
+
+            BackupTestFiles();
+
+            try
+            {
+                while (reader.Read())
+                {
+                    mediaInfoCmd.Delete(reader.Current.Id);
+                }
+
+                var tagCmd = new TagCommand(_database);
+
+                var tagReader = tagCmd.Select();
+
+                while (tagReader.Read())
+                {
+                    tagCmd.Delete(tagReader.Current.Id);
+                }
+            }
+            finally
+            {
+                RestoreTestFiles();
+            }
+        }
+
+        private void BackupTestFiles()
+        {
+            var _testFiles = new Dictionary<string, string>
+            {
+                { TestConstants.AudioFile, TestConstants.AudioFileBackup},
+                { TestConstants.VideoFile, TestConstants.VideoFileBackup },
+                { TestConstants.ImageFile, TestConstants.ImageFileBackup },
+                { TestConstants.ImageFileForFolder, TestConstants.ImageFileForFolderBackup }
+            };
+
+            foreach (var file in _testFiles)
+            {
+                if (File.Exists(file.Key))
+                {
+                    File.Move(file.Key, file.Value);
+                }
+            }
+        }
+
+        private void RestoreTestFiles()
+        {
+            var _testFilesBackup = new Dictionary<string, string>
+            {
+                { TestConstants.AudioFileBackup, TestConstants.AudioFile},
+                { TestConstants.VideoFileBackup, TestConstants.VideoFile },
+                { TestConstants.ImageFileBackup, TestConstants.ImageFile },
+                { TestConstants.ImageFileForFolderBackup, TestConstants.ImageFileForFolder }
+            };
+
+            foreach (var file in _testFilesBackup)
+            {
+                if (File.Exists(file.Key))
+                {
+                    File.Move(file.Key, file.Value);
+                }
+            }
+        }
     }
 }
index 9b104ad..49b8296 100644 (file)
@@ -13,33 +13,29 @@ namespace Tizen.Content.MediaContent.Tests
             StorageManager.Storages.Where(s => s.StorageType == StorageArea.External).FirstOrDefault();
 
         internal static readonly string ImageFileName = "image.jpg";
-
         internal static readonly string WavFile = RootPath + "/test.wav";
-
         internal static readonly string ImageFile = RootPath + "/image.jpg";
-
         internal static readonly string FaceImageFile = RootPath + "/face_image.jpg";
-
         internal static readonly string FaceImageFileUnSupported = RootPath + "/face_image_unsupported.gif";
-
         internal static readonly string AudioFile = RootPath + "/sound.mp3";
-
         internal static readonly string VideoFile = RootPath + "/movie.mp4";
-
         internal static readonly string PlaylistFile = RootPath + "/tmp.m3u";
-
         internal static readonly string FolderPath = RootPath + "/test";
-
         internal static readonly string ImageFileForFolder = FolderPath + "/test.jpg";
-
         internal static readonly string IgnorePath = RootPath + "/ignore";
-
         internal static readonly string HiddenPath = RootPath + "/.hidden";
-
         internal static readonly string OtherPath = RootPath + "/other";
-
         internal static readonly string OtherFile = OtherPath + "/other.txt";
 
+        internal static readonly string WavFileBackup = RootPath + "/test.bak";
+        internal static readonly string ImageFileBackup = RootPath + "/image.bak";
+        internal static readonly string FaceImageFileBackup = RootPath + "/face_image.bak";
+        internal static readonly string AudioFileBackup = RootPath + "/sound.bak";
+        internal static readonly string VideoFileBackup = RootPath + "/movie.bak";
+        internal static readonly string PlaylistFileBackup = RootPath + "/tmp.bak";
+        internal static readonly string ImageFileForFolderBackup = FolderPath + "/test.bak";
+        internal static readonly string OtherFileBackup = OtherPath + "/other.bak";
+
         internal const string OthersFeature = "http://tizen.org/feature/content.scanning.others";
     }
 }
old mode 100755 (executable)
new mode 100644 (file)
index d4610ee..4b62f98
@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using System.IO;
 using System.Threading.Tasks;
 using Tizen.System;
 
@@ -40,5 +41,75 @@ namespace Tizen.Content.MediaContent.Tests
         {
             return Information.TryGetValue(Feature, out bool isSupported) ? isSupported : false;
         }
+
+        public static void ClearDatabase(MediaDatabase database, string path, bool needRestore = false)
+        {
+            var mediaInfoCmd = new MediaInfoCommand(database);
+
+            var filter = new SelectArguments
+            {
+                FilterExpression = $"{MediaInfoColumns.Path}='{path}'"
+            };
+
+            var reader = mediaInfoCmd.SelectMedia(filter);
+
+            if (File.Exists(path))
+            {
+                File.Move(path, path + ".bak");
+            }
+
+            while (reader.Read())
+            {
+                mediaInfoCmd.Delete(reader.Current.Id);
+            }
+
+            if (needRestore)
+            {
+                RestoreFile(path);
+            }
+        }
+
+        public static string ClearDatabaseWithMediaId(MediaDatabase database, string mediaId, bool needRestore = false)
+        {
+            var mediaInfoCmd = new MediaInfoCommand(database);
+
+            var reader = mediaInfoCmd.SelectMedia(mediaId);
+            string path = reader.Path;
+
+            if (File.Exists(path))
+            {
+                File.Move(path, path + ".bak");
+            }
+
+            mediaInfoCmd.Delete(reader.Id);
+
+            if (needRestore)
+            {
+                RestoreFile(path);
+            }
+
+            return path;
+        }
+
+        public static string BackupFileWithMediaId(MediaDatabase database, string mediaId)
+        {
+            var mediaInfoCmd = new MediaInfoCommand(database);
+
+            var reader = mediaInfoCmd.SelectMedia(mediaId);
+            string path = reader.Path;
+
+            if (File.Exists(path))
+            {
+                File.Move(path, path + ".bak");
+            }
+
+            return path;
+        }
+
+        public static void RestoreFile(string path)
+        {
+            Log.Info("Tizen.Mediacontent.Tests", path + ".bak");
+            File.Move(path + ".bak", path);
+        }
     }
 }