bf9b614a47f1dce3f89c4dcd2ea3989c5b800e88
[platform/core/csapi/media-content.git] / tct-mediacontent-tizen-tests / src / Testcase / TSPlayList.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using TestFramework;
7 using Tizen.Content.MediaContent;
8
9 namespace TizenTest.PlayListT
10 {
11
12     [TestFixture]
13     [Description("Tizen.Content.MediaContent.PlayList Tests")]
14     class PlayListT
15     {
16         private static ContentFilter audioFilter;
17         private static PlayList playList = null;
18         private static MediaInformation[] audioArray = new MediaInformation[1000];
19         private static IEnumerable<MediaInformation> audioList;
20         static async Task PlayListSetup()
21         {
22             //Get files from the media folder
23             await ContentManager.ScanFolderAsync("/home/owner/content", true);
24             audioFilter = new ContentFilter();
25             audioFilter.Condition = "MEDIA_TYPE = 3";
26             Task<IEnumerable<MediaInformation>> getAudioListTask = ContentManager.Database.SelectAsync<MediaInformation>(audioFilter);
27             audioList = await getAudioListTask;
28             int i = 0;
29             foreach (MediaInformation audio in audioList)
30             {
31                 audioArray[i++] = audio;
32             }
33             Task<IEnumerable<PlayList>> getPlayListsTask = ContentManager.Database.SelectAsync<PlayList>(null);
34             IEnumerable<PlayList> allPlayLists = await getPlayListsTask;
35             foreach (PlayList p in allPlayLists)
36             {
37                 ContentManager.Database.Delete(p);
38             }
39         }
40
41         [SetUp]
42         public static void Init()
43         {
44             //get a mediainformation  object
45
46             //LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for each TEST");
47         }
48
49         [TearDown]
50         public static void Destroy()
51         {
52
53             //LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for each TEST");
54         }
55
56         [Test]
57         [Category("P1")]
58         [Description("Test PlayList constructor")]
59         [Property("SPEC", " Tizen.Content.MediaContent.PlayList.PlayList C")]
60         [Property("SPEC_URL", "-")]
61         [Property("CRITERIA", "CONSTR")]
62         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
63         public static async Task PlayList_CONSTRUCTOR()
64         {
65             await PlayListSetup();
66             string playListName = "playlist_work";
67             playList = new PlayList(playListName);
68             Assert.IsInstanceOf<PlayList>(playList);
69             Assert.IsTrue(playListName.CompareTo(playList.Name) == 0);
70             Assert.IsTrue(playList.Id == 0);
71             ContentManager.Database.Insert(playList);
72             Assert.IsFalse(playList.Id == 0);
73         }
74
75         [Test]
76         [Category("P1")]
77         [Description("Test if get for PlayList:Id is working properly")]
78         [Property("SPEC", " Tizen.Content.MediaContent.PlayList.Id A")]
79         [Property("SPEC_URL", "-")]
80         [Property("CRITERIA", "PRO")]
81         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
82         public static void Id_READ_ONLY()
83         {
84             Assert.IsFalse(playList.Id == 0);
85         }
86
87         [Test]
88         [Category("P1")]
89         [Description("Test if get/set for PlayList:Name is working properly")]
90         [Property("SPEC", "Tizen.Content.MediaContent.PlayList.Name A")]
91         [Property("SPEC_URL", "-")]
92         [Property("CRITERIA", "PRW")]
93         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
94         public static void Name_READ_WRITE()
95         {
96             try
97             {
98                 string name = playList.Name;
99                 string setValue = name + "_Modified";
100                 playList.Name = setValue;
101                 ContentManager.Database.Update(playList);
102                 Assert.IsTrue(setValue.CompareTo(playList.Name) == 0, "Set value and get value of the property should be same");
103             }
104             catch (Exception e)
105             {
106                 Assert.Fail();
107                 Tizen.Log.Info("TCT", "Name_READ_WRITE Exception: " + e.Message);
108             }
109         }
110
111         [Test]
112         [Category("P1")]
113         [Description("Test if get/set for PlayList:ThumbnailPath is working properly")]
114         [Property("SPEC", "Tizen.Content.MediaContent.PlayList.ThumbnailPath A")]
115         [Property("SPEC_URL", "-")]
116         [Property("CRITERIA", "PRW")]
117         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
118         public static void ThumbnailPath_READ_WRITE()
119         {
120             Assert.IsFalse(playList.Id == 0);
121             // TODO dummy thumbnail path value. instead push a jpg in test case preperation
122             string setValue = "/home/owner/content/Camera/20150103-101850.jpg";
123             playList.ThumbnailPath = setValue;
124             ContentManager.Database.Update(playList);
125             string getValue = playList.ThumbnailPath;
126             Assert.IsTrue(setValue.CompareTo(playList.ThumbnailPath) == 0, "Set value and get value of the property should be same");
127         }
128
129         [Test]
130         [Category("P1")]
131         [Description("Test if PlayList:AddItem & PlayList:GetMediaInformationCount APIs are working properly")]
132         [Property("SPEC", "Tizen.Content.MediaContent.PlayList.AddItem Tizen.Content.MediaContent.PlayList.GetMediaInformationCount M")]
133         [Property("SPEC_URL", "-")]
134         [Property("CRITERIA", "MR MCST")]
135         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
136         public static void AddItem_CHECK_LENGTH()
137         {
138             Assert.IsFalse(playList.Id == 0 && audioArray.Length == 0);
139             playList.AddItem(audioArray[0]);
140             ContentManager.Database.Update(playList);
141             Assert.IsTrue(1 == playList.GetMediaInformationCount(null));
142             playList.AddItem(audioArray[1]);
143             ContentManager.Database.Update(playList);
144             Assert.IsTrue(2 == playList.GetMediaInformationCount(null));
145             playList.AddItem(audioArray[2]);
146             ContentManager.Database.Update(playList);
147             Assert.IsTrue(3 == playList.GetMediaInformationCount(null));
148
149         }
150
151         [Test]
152         [Category("P1")]
153         [Description("Test if PlayList:RemoveItem & PlayList:GetMediaInformationCount APIs are working properly")]
154         [Property("SPEC", "Tizen.Content.MediaContent.PlayList.RemoveItem Tizen.Content.MediaContent.PlayList.GetMediaInformationCount M")]
155         [Property("SPEC_URL", "-")]
156         [Property("CRITERIA", "MCST")]
157         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
158         public static void RemoveItem_CHECK_LENGTH()
159         {
160             try
161             {
162                 Assert.IsFalse(playList.Id == 0 && playList.GetMediaInformationCount(null) == 0);
163                 playList.RemoveItem(audioArray[2]);
164                 ContentManager.Database.Update(playList);
165                 Assert.IsTrue(2 == playList.GetMediaInformationCount(null));
166                 playList.RemoveItem(audioArray[1]);
167                 ContentManager.Database.Update(playList);
168                 Assert.IsTrue(1 == playList.GetMediaInformationCount(null));
169                 playList.RemoveItem(audioArray[0]);
170                 ContentManager.Database.Update(playList);
171                 Assert.IsTrue(0 == playList.GetMediaInformationCount(null));
172             }
173             catch (Exception e)
174             {
175                 Assert.Fail();
176                 Tizen.Log.Info("TCT", "RemoveItem_CHECK_LENGTH Exception: " + e.Message);
177             }
178         }
179
180         //[Test]
181         //[Category("P1")]
182         //[Description("Test if PlayList:SetPlayOrder & PlayList:GetPlayOrder APIs are working properly")]
183         //[Property("SPEC", "Tizen.Content.MediaContent.PlayList.SetPlayOrder Tizen.Content.MediaContent.PlayList.GetPlayOrder M")]
184         //[Property("SPEC_URL", "-")]
185         //[Property("CRITERIA", "MR MCST")]
186         //[Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
187         //public static void PlayOrder_READ_WRITE()
188         //{
189         //    Assert.IsFalse(playList.Id == 0);
190         //    playList.AddItem(audioArray[0]);
191         //    ContentManager.Database.Update(playList);
192         //    playList.AddItem(audioArray[1]);
193         //    ContentManager.Database.Update(playList);
194         //    playList.AddItem(audioArray[2]);
195         //    ContentManager.Database.Update(playList);
196         //    Tizen.Log.Info("TCT", "PlayList member count: " + playList.GetMediaInformationCount(null));
197         //    Tizen.Log.Info("TCT", "******Setting play order*****");
198         //    playList.SetPlayOrder(audioArray[0], 2);
199         //    Tizen.Log.Info("TCT", "******play order set*****");
200         //    ContentManager.Database.Update(playList);
201         //    Tizen.Log.Info("TCT", "******play order updated to database*****");
202         //    int p = playList.GetPlayOrder(audioArray[0]);
203         //    Tizen.Log.Info("TCT", "Got play order as " + p);
204         //    Assert.IsTrue(2 == p);
205         //}
206
207         //[Test]
208         //[Category("P1")]
209         //[Description("Test if PlayList:Import & PlayList:Export APIs are working properly")]
210         //[Property("SPEC", "Tizen.Content.MediaContent.PlayList.Import Tizen.Content.MediaContent.PlayList.Export M")]
211         //[Property("SPEC_URL", "-")]
212         //[Property("CRITERIA", "MR MCST")]
213         //[Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
214         //public static void PlayList_READ_WRITE()
215         //{
216         //    Assert.IsFalse(playList.Id == 0);
217         //    Tizen.Log.Info("TCT", "#########Export#####");
218         //    string path = "/home/owner/content/Music/playlist_work_imported.m3u";
219         //    PlayList.Export(playList, path);
220         //    Tizen.Log.Info("TCT", "#########Import#####");
221         //    PlayList importedPlayList = PlayList.Import("playlist_work_imported", path);
222         //    Assert.IsTrue(playList.GetMediaInformationCount(null) == importedPlayList.GetMediaInformationCount(null));
223         //    Assert.IsTrue(playList.Name.CompareTo(importedPlayList.Name) == 0);
224         //    Assert.IsTrue(playList.ThumbnailPath.CompareTo(importedPlayList.ThumbnailPath) == 0);
225         //}
226
227         [Test]
228         [Category("P1")]
229         [Description("Test if PlayList:GetMediaInformationsAsync is working properly")]
230         [Property("SPEC", "Tizen.Content.MediaContent.PlayList.GetMediaInformationsAsync M")]
231         [Property("SPEC_URL", "-")]
232         [Property("CRITERIA", "MR")]
233         [Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
234         public static async Task GetMediaInformationsAsync_MEDIA_INFORMATION()
235         {
236             playList.AddItem(audioArray[0]);
237             playList.AddItem(audioArray[1]);
238             playList.AddItem(audioArray[2]);
239             ContentManager.Database.Update(playList);
240             Assert.IsFalse(playList.Id == 0 && playList.GetMediaInformationCount(null) == 0);
241             IEnumerable<MediaInformation> extract = null;
242             Task<IEnumerable<MediaInformation>> getMembersTask = playList.GetMediaInformationsAsync(null);
243             extract = await getMembersTask;
244             Assert.IsTrue(3 == extract.Count<MediaInformation>());
245         }
246     }
247 }