2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Runtime.CompilerServices;
8 namespace SystemSettingsUnitTest
12 static public string result;
13 static public string errorMessage;
17 result = StrUtils.INIT;
21 static internal void SetExceptionMessage(Exception exception)
23 string errMessage = "Exception: " + exception.Message + Environment.NewLine;
24 errMessage += " Trace: " + exception.StackTrace + Environment.NewLine;
28 static public void Pass()
30 // If it was marked Failed before, keep the result fail.
31 if (result != StrUtils.FAIL) result = StrUtils.PASS;
34 static public void Fail(string message)
36 result = StrUtils.FAIL;
37 // To remember message from first failure
38 if (errorMessage == null) errorMessage = message;
39 LogUtils.Write(LogUtils.INFO, LogUtils.TAG, " " + message);
42 static public void Init()
44 result = StrUtils.INIT;
48 static public string GetResult()
53 static public void True(bool condition, string message = "Expects true, but got false.")
55 if (condition == true) Pass(); else Fail(message);
58 static public void IsTrue(bool condition, string message = "Expects true, but got false.")
60 if (condition == true) Pass(); else Fail(message);
63 static public void False(bool condition, string message = "Expects false, but got true.")
65 if (condition == false) Pass(); else Fail(message);
68 static public void IsFalse(bool condition, string message = "Expects false, but got true.")
70 if (condition == false) Pass(); else Fail(message);
73 static public void AreEqual<T>(T expected, T actual, string message = "Expects given values to be equal, but given values are not.")
75 if (EqualityComparer<T>.Default.Equals(expected, actual)) Pass(); else Fail(message);
78 static public void AreNotEqual<T>(T expected, T actual, string message = "Expects given values to be unequal, but given values are identical.")
80 if (!EqualityComparer<T>.Default.Equals(expected, actual)) Pass(); else Fail(message);
83 static public void NotNull(object anObject, string message = "Given object is not null.")
85 if (anObject != null) Pass(); else Fail(message);
88 static public void IsNull(object anObject, string message = "Given object is not null.")
90 if (anObject == null) Pass(); else Fail(message);
93 static public void IsNotNull(object anObject, string message = "Given object is null.")
95 if (anObject != null) Pass(); else Fail(message);
98 static public void IsA<T>(object actual, string message = "Given object is NOT an instance of specified type.")
100 if (actual is T) Pass(); else Fail(message);
103 static public void IsInstanceOf<T>(object actual, string message = "Given object is NOT an instance of specified type.")
105 if (actual.GetType() == typeof(T)) Pass(); else Fail(message);
108 static public void Greater<T>(T actual, T expected, string message) where T : IComparable<T>
110 if (actual.CompareTo(expected) > 0) Pass(); else Fail(message);
113 static public void Smaller<T>(T actual, T expected, string message) where T : IComparable<T>
115 if (actual.CompareTo(expected) < 0) Pass(); else Fail(message);
118 static public void IsNotEmpty(IEnumerable collection, string message)
120 foreach (object item in collection)
130 public class StrUtils
132 static public string PASS = "PASS";
133 static public string FAIL = "FAIL";
134 static public string INIT = "INIT";
137 public class LogUtils
139 // write with white font
140 static public string DEBUG = "D";
142 // write with blue font
143 static public string INFO = "I";
145 // write with red font
146 static public string ERROR = "E";
148 static public string TAG = "CS-SYSTEM-SETTINGS";
150 static public int ok_cnt = 0;
151 static public int chk_cnt = 0;
152 static public int not_support_cnt = 0;
154 static public void Write(string level, string tag, string msg)
156 foreach (string line in msg.Split('\n'))
158 Tizen.Log.Debug(TAG, line);
162 // Console.ForegroundColor = ConsoleColor.Blue;
163 //else if (level == DEBUG)
164 // Console.ForegroundColor = ConsoleColor.White;
165 //else if (level == ERROR)
166 // Console.ForegroundColor = ConsoleColor.Red;
168 //Console.WriteLine(tag + " : [" + level + "] | " + msg);
169 //Console.ResetColor();
171 static public void initWriteResult()
179 static public void StartTest()
182 int check_progress = (chk_cnt * 100) / 85;
183 if (check_progress < 100)
185 Program.testProgress.CurrentValue = check_progress;
186 string output = "Test progress " + check_progress + "%";
187 Program.text.Text = output;
191 static public void NotSupport()
196 static public void WriteOK([CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
198 Tizen.Log.Debug(TAG, "ok", file, func, line);
201 static public void WriteResult()
203 Program.testProgress.CurrentValue = 100;
204 string output = "Result : " + ok_cnt + " Pass / " + not_support_cnt + " Not Support / " + (chk_cnt - (ok_cnt + not_support_cnt)) + " Failed";
205 string output_display = ok_cnt + " Pass / " + not_support_cnt + " NS / " + (chk_cnt - (ok_cnt + not_support_cnt)) + " Failed";
206 Tizen.Log.Debug(TAG, output);
207 Program.text.Text = output_display;