2 using System.Threading.Tasks;
3 using System.Threading;
4 using Tizen.Content.Download;
5 using System.Collections.Generic;
8 using System.Reflection;
9 using System.Collections;
10 using System.Runtime.CompilerServices;
11 using System.Diagnostics;
13 using Tizen.Applications;
15 using System.Collections.ObjectModel;
16 using System.Collections.Specialized;
17 using System.Runtime.InteropServices;
19 namespace TizenTest.Download {
22 [Description("Tizen.Content.Download.Request Tests.")]
23 public static class TSRequest {
24 public static Tizen.Content.Download.Request req;
25 public static string url;
26 public static string destinationPath;
27 public static string fileName;
28 public static Tizen.Content.Download.NetworkType type;
29 public static IDictionary<string, string> httpHeaders;
30 public static bool bFlag;
31 public static Request request;
32 public static Request testRequest;
33 public static async Task waitFlag()
38 await Task.Delay(1000);
42 Tizen.Log.Info("Tizen.Content.Download" , "bFlag is true");break;
45 {Tizen.Log.Info("Tizen.Content.Download" , "count is 8"); break;
51 public static void Init() {
52 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG , "Preconditions for each Test");
53 url = "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif";
54 destinationPath = "/opt/usr/";
55 fileName = "TestCaseDownload";
56 type = NetworkType.All;
57 httpHeaders = new Dictionary<string, string>();
58 httpHeaders.Add("Pragma", "no-cache");
63 public static void Destroy() {
64 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG , "Postconditions for each Test");
67 destinationPath = null;
72 static void OnProgressChanged(object sender, ProgressChangedEventArgs e)
74 Tizen.Log.Info("Tizen.Content.Download" , "OnProgressChanged");
78 static void OnStateChanged(object sender, StateChangedEventArgs e)
80 Tizen.Log.Info("Tizen.Content.Download" , "OnStateChanged"+e.State);
83 case DownloadState.None:
88 case DownloadState.Ready:
93 case DownloadState.Queued:
98 case DownloadState.Downloading:
103 case DownloadState.Paused:
108 case DownloadState.Completed:
113 case DownloadState.Canceled:
123 [Description("Test : Request constructor with url as parameter - Object should not be null after initialization")]
124 [Property("SPEC", "Tizen.Content.Download.Request C")]
125 [Property("SPEC_URL", "-")]
126 [Property("CRITERIA", "CONSTR")]
127 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
128 public static void Request_INIT1() {
130 req = new Tizen.Content.Download.Request(url);
131 Assert.IsNotNull(req, "Object should be not null after init");
136 [Description("Test : Request constructor with url, destination path, file name and network type as parameters - Object should not be null after initialization")]
137 [Property("SPEC", "Tizen.Content.Download.Request C")]
138 [Property("SPEC_URL", "-")]
139 [Property("CRITERIA", "CONSTR")]
140 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
141 public static void Request_INIT2()
144 req = new Tizen.Content.Download.Request(url, destinationPath, fileName, type);
145 Assert.IsNotNull(req, "Object should be not null after init");
150 [Description("Test : Request constructor with url, destination path, file name, network type and header as parameters - Object should not be null after initialization")]
151 [Property("SPEC", "Tizen.Content.Download.Request C")]
152 [Property("SPEC_URL", "-")]
153 [Property("CRITERIA", "CONSTR")]
154 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
155 public static void Request_INIT3()
158 req = new Tizen.Content.Download.Request(url, destinationPath, fileName, type, httpHeaders);
159 Assert.IsNotNull(req, "Object should be not null after init");
164 [Description("Test : StateChanged callback")]
165 [Property("SPEC", "Tizen.Content.Download.StateChanged E")]
166 [Property("SPEC_URL", "-")]
167 [Property("CRITERIA", "EVL")]
168 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
169 public static async Task StateChanged_CB()
173 * 1. Wifi or Data Network must be connected
175 string testUrl = "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif";
176 Request testRequest = new Tizen.Content.Download.Request(testUrl);
177 testRequest.StateChanged += OnStateChanged;
182 Assert.True(bFlag, "StateChanged event should occur");
183 Tizen.Log.Info("Tizen.Content.Download" , "TC Completed");
188 [Description("Test : ProgressChanged callback")]
189 [Property("SPEC", "Tizen.Content.Download.ProgressChanged E")]
190 [Property("SPEC_URL", "-")]
191 [Property("CRITERIA", "EVL")]
192 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
193 public static async Task ProgressChanged_CB()
197 * 1. Wifi or Data Network must be connected
199 string testUrl = "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif";
200 Request testRequest = new Tizen.Content.Download.Request(testUrl);
201 testRequest.ProgressChanged += OnProgressChanged;
206 Assert.True(bFlag, "ProgressChanged event should occur");
207 Tizen.Log.Info("Tizen.Content.Download" , "TC Completed");
212 [Description("Test : Request's Get Properties")]
213 [Property("SPEC", " Tizen.Content.Download.Request M")]
214 [Property("SPEC_URL", "-")]
215 [Property("CRITERIA", "MR")]
216 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
217 public static async Task Request_PROPERTIES_GET()
221 * 1. Wifi or Data Network must be connected
223 string testUrl = "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif";
224 testRequest = new Tizen.Content.Download.Request(testUrl);
225 Assert.IsNotNull(testRequest, "Object should not be null after initializing");
227 testRequest.StateChanged += OnStateChanged;
232 Assert.AreEqual(testUrl, testRequest.Url, "Propety \"URL\": the set value and the get value should be equal");
233 Assert.True(bFlag, "DownloadState should be Completed");
234 Assert.IsNotNull((string)testRequest.DownloadedPath, "DownloadedPath is null");
235 Assert.IsNotNull((string)testRequest.MimeType, "MimeType is null");
236 Assert.IsNotNull((DownloadState)testRequest.State, "State is null");
237 Assert.IsNotNull((string)testRequest.ContentName, "ContentName is null");
238 Assert.IsNotNull((ulong)testRequest.ContentSize, "ContentSize is null");
239 Assert.IsNotNull((int)testRequest.HttpStatus, "HttpStatus is null");
240 Assert.IsNotNull((string)testRequest.ETagValue, "ETagValue is null");
241 Assert.IsNotNull((string)testRequest.TempFilePath, "TempFilePath is null");
242 Tizen.Log.Info("Tizen.Content.Download" , "TC Completed");
247 [Description("Test : Request's Set/Get Properties")]
248 [Property("SPEC", " Tizen.Content.Download.Request A")]
249 [Property("SPEC_URL", "-")]
250 [Property("CRITERIA", "MR")]
251 [Property("AUTHOR", "Yuvaraj S, yuvaraj.s@samsung.com")]
252 public static void Request_PROPERTIES_SET_GET()
255 string testUrl = "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif";
256 NetworkType testType = NetworkType.All;
257 string testDestinationPath = "/home/owner/content/";
258 string testFileName = "SampleDownloadFile";
259 bool testAutoDownload = true;
260 IDictionary<string, string> testHttpHeaders = new Dictionary<string,string>();
261 testHttpHeaders.Add("Pragma","no-cache");
264 testRequest = new Tizen.Content.Download.Request(testUrl);
265 Assert.IsNotNull(testRequest, "Object should not be null after initializing");
267 testRequest.Url = testUrl;
268 Assert.AreEqual(testUrl, testRequest.Url, "Propety \"Url\": the set value and the get value should be equal");
270 testRequest.AllowedNetworkType = testType;
271 Assert.IsTrue(testType == testRequest.AllowedNetworkType, "Propety \"AllowedNetworkType\": the set value and the get value should be equal");
273 testRequest.DestinationPath = testDestinationPath;
274 Assert.IsTrue(testDestinationPath == testRequest.DestinationPath, "Propety \"DestinationPath\": the set value and the get value should be equal");
276 testRequest.FileName = testFileName;
277 Assert.AreEqual(testFileName, testRequest.FileName, "Propety \"FileName\": the set value and the get value should be equal");
279 testRequest.AutoDownload = testAutoDownload;
280 Assert.IsTrue(testAutoDownload == testRequest.AutoDownload, "Propety \"AutoDownload\": the set value and the get value should be equal");
282 Tizen.Log.Info("Tizen.Content.Download" , "TC Completed");