SROptions.Test.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. //#define ENABLE_TEST_SROPTIONS
  2. using System;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. #if !DISABLE_SRDEBUGGER
  6. using SRDebugger;
  7. using SRDebugger.Services;
  8. #endif
  9. using SRF;
  10. using SRF.Service;
  11. using Debug = UnityEngine.Debug;
  12. using Random = UnityEngine.Random;
  13. public partial class SROptions
  14. {
  15. // Uncomment the #define at the top of file to enable test options
  16. #if ENABLE_TEST_SROPTIONS
  17. public enum TestValues
  18. {
  19. TestValue1,
  20. TestValue2,
  21. TestValue3LongerThisTime
  22. }
  23. private bool _testBoolean = true;
  24. private string _testString = "Test String Value";
  25. private short _testShort = -10;
  26. private byte _testByte = 2;
  27. private int _testInt = 30000;
  28. private double _testDouble = 406002020d;
  29. private float _testFloat = 0.1f;
  30. private sbyte _testSByte = -10;
  31. private uint _testUInt = 32450;
  32. private TestValues _testEnum;
  33. private float _test01Range;
  34. private float _testFractionIncrement;
  35. private int _testLargeIncrement;
  36. [Category("Test")]
  37. public float TestFloat
  38. {
  39. get { return _testFloat; }
  40. set
  41. {
  42. _testFloat = value;
  43. OnValueChanged("TestFloat", value);
  44. }
  45. }
  46. [Category("Test")]
  47. public double TestDouble
  48. {
  49. get { return _testDouble; }
  50. set
  51. {
  52. _testDouble = value;
  53. OnValueChanged("TestDouble", value);
  54. }
  55. }
  56. [Category("Test")]
  57. public int TestInt
  58. {
  59. get { return _testInt; }
  60. set
  61. {
  62. _testInt = value;
  63. OnValueChanged("TestInt", value);
  64. }
  65. }
  66. [Category("Test")]
  67. public byte TestByte
  68. {
  69. get { return _testByte; }
  70. set
  71. {
  72. _testByte = value;
  73. OnValueChanged("TestByte", value);
  74. }
  75. }
  76. [Category("Test")]
  77. public short TestShort
  78. {
  79. get { return _testShort; }
  80. set
  81. {
  82. _testShort = value;
  83. OnValueChanged("TestShort", value);
  84. }
  85. }
  86. [Category("Test")]
  87. public string TestString
  88. {
  89. get { return _testString; }
  90. set
  91. {
  92. _testString = value;
  93. OnValueChanged("TestString", value);
  94. }
  95. }
  96. [Category("Test")]
  97. public bool TestBoolean
  98. {
  99. get { return _testBoolean; }
  100. set
  101. {
  102. _testBoolean = value;
  103. OnValueChanged("TestBoolean", value);
  104. }
  105. }
  106. [Category("Test")]
  107. public TestValues TestEnum
  108. {
  109. get { return _testEnum; }
  110. set
  111. {
  112. _testEnum = value;
  113. OnValueChanged("TestEnum", value);
  114. }
  115. }
  116. [Category("Test")]
  117. public sbyte TestSByte
  118. {
  119. get { return _testSByte; }
  120. set
  121. {
  122. _testSByte = value;
  123. OnValueChanged("TestSByte", value);
  124. }
  125. }
  126. [Category("Test")]
  127. public uint TestUInt
  128. {
  129. get { return _testUInt; }
  130. set
  131. {
  132. _testUInt = value;
  133. OnValueChanged("TestUInt", value);
  134. }
  135. }
  136. [Category("Test")]
  137. [NumberRange(0, 1)]
  138. public float Test01Range
  139. {
  140. get { return _test01Range; }
  141. set
  142. {
  143. _test01Range = value;
  144. OnValueChanged("Test01Range", value);
  145. }
  146. }
  147. [Category("Test")]
  148. [Increment(0.2)]
  149. public float TestFractionIncrement
  150. {
  151. get { return _testFractionIncrement; }
  152. set
  153. {
  154. _testFractionIncrement = value;
  155. OnValueChanged("TestFractionIncrement", value);
  156. }
  157. }
  158. [Category("Test")]
  159. [Increment(25)]
  160. public int TestLargeIncrement
  161. {
  162. get { return _testLargeIncrement; }
  163. set
  164. {
  165. _testLargeIncrement = value;
  166. OnValueChanged("TestLargeIncrement", value);
  167. }
  168. }
  169. [Category("Test")]
  170. public void TestAction()
  171. {
  172. Debug.Log("[SRDebug] TestAction() invoked");
  173. }
  174. [Category("Test"), DisplayName("Test Action Renamed")]
  175. public void TestRenamedAction()
  176. {
  177. Debug.Log("[SRDebug] TestRenamedAction() invoked");
  178. }
  179. private void OnValueChanged(string n, object newValue)
  180. {
  181. Debug.LogFormat("[SRDebug] {0} value changed to {1}", n, newValue);
  182. OnPropertyChanged(n);
  183. }
  184. #if !DISABLE_SRDEBUGGER
  185. [Category("SRDebugger")]
  186. public PinAlignment TriggerPosition
  187. {
  188. get { return SRServiceManager.GetService<IDebugTriggerService>().Position; }
  189. set { SRServiceManager.GetService<IDebugTriggerService>().Position = value; }
  190. }
  191. #endif
  192. private static readonly string[] SampleLogs =
  193. {
  194. "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  195. "Mauris id mauris interdum tellus luctus posuere.",
  196. "Donec eget velit nec risus bibendum condimentum ut in velit.",
  197. "Aenean et augue non eros interdum fringilla.",
  198. "Nam vulputate justo quis nulla ultricies placerat.",
  199. "Etiam id libero sed quam elementum suscipit.",
  200. "Nulla sollicitudin purus nec mauris congue tincidunt.",
  201. "Nam sit amet neque vestibulum, vehicula lorem sed, ultricies dui.",
  202. "Aenean a eros fringilla, luctus est et, bibendum lorem.",
  203. "Integer bibendum metus in lectus finibus sagittis.",
  204. "Quisque a lacus ac massa interdum sagittis nec id sapien.",
  205. "Phasellus a ipsum volutpat, lobortis velit eu, consectetur nunc.",
  206. "Nulla elementum justo malesuada lacus mollis lobortis.",
  207. "Nullam sodales nisi vitae tortor lacinia, in pulvinar mauris accumsan.",
  208. "Nullam maximus dolor suscipit magna lobortis, eu finibus felis ornare.",
  209. "Sed eget nisl ac lorem eleifend fermentum ac quis nunc.",
  210. "Fusce vitae sapien quis turpis faucibus aliquet sit amet et risus.",
  211. "Nunc faucibus arcu ut purus fringilla bibendum.",
  212. "Phasellus pretium justo vel eros facilisis varius.",
  213. "In efficitur quam dapibus nulla commodo, in aliquam nulla bibendum."
  214. };
  215. private int _consoleTestQuantity = 190;
  216. [Category("Console Test")]
  217. public int ConsoleTestQuantity
  218. {
  219. get { return _consoleTestQuantity; }
  220. set { _consoleTestQuantity = value; }
  221. }
  222. [Category("Console Test")]
  223. public void ConsoleTest()
  224. {
  225. var sw = new Stopwatch();
  226. sw.Start();
  227. for (var i = 0; i < ConsoleTestQuantity; i++)
  228. {
  229. var sample = SampleLogs[Random.Range(0, SampleLogs.Length)];
  230. var mode = Random.Range(0, 3);
  231. switch (mode)
  232. {
  233. case 0:
  234. Debug.Log(sample);
  235. break;
  236. case 1:
  237. Debug.LogWarning(sample);
  238. break;
  239. case 2:
  240. Debug.LogError(sample);
  241. break;
  242. }
  243. }
  244. sw.Stop();
  245. Debug.LogFormat("Posted {0} log messages in {1}s", ConsoleTestQuantity, sw.Elapsed.TotalSeconds);
  246. }
  247. [Category("Console Test")]
  248. public void TestThrowException()
  249. {
  250. throw new Exception("This is certainly a test.");
  251. }
  252. [Category("Console Test")]
  253. public void TestLogError()
  254. {
  255. Debug.LogError("Test Error");
  256. }
  257. [Category("Console Test")]
  258. public void TestLogWarning()
  259. {
  260. Debug.LogWarning("Test Warning");
  261. }
  262. [Category("Console Test")]
  263. public void TestLogInfo()
  264. {
  265. Debug.Log("Test Info");
  266. }
  267. [Category("Console Test")]
  268. public void TestRichText()
  269. {
  270. Debug.Log(
  271. "<b>Rich text</b> is <i>supported</i> in the <b><i>console</i></b>. <color=#7fc97a>Color tags, too!</color>");
  272. }
  273. [Category("Console Test")]
  274. public void TestLongMessage()
  275. {
  276. var m = SampleLogs[0];
  277. for (var i = 0; i < 2; ++i)
  278. {
  279. m = m + m;
  280. }
  281. var s = m;
  282. for (var i = 0; i < 13; ++i)
  283. {
  284. s = s + "\n" + m;
  285. }
  286. Debug.Log(s);
  287. }
  288. [Category("Sorting Test"), Sort(2)]
  289. public float ShouldAppearLast { get; set; }
  290. [Category("Sorting Test"), Sort(-1)]
  291. public float ShouldAppearFirst { get; set; }
  292. [Category("Sorting Test")]
  293. public float ShouldAppearMiddle { get; set; }
  294. private float _updateTest;
  295. public float UpdateTest
  296. {
  297. get { return _updateTest; }
  298. set
  299. {
  300. _updateTest = value;
  301. OnPropertyChanged("UpdateTest");
  302. }
  303. }
  304. [DisplayName("Modified Name")]
  305. public float DisplayNameTest { get; set; }
  306. [Category("Read Only")]
  307. public bool ReadOnlyBool { get; private set; }
  308. [Category("Read Only")]
  309. public float ReadOnlyNumber { get; private set; }
  310. [Category("Read Only")]
  311. public string ReadOnlyString { get; private set; }
  312. [Category("Read Only")]
  313. public TestValues ReadOnlyEnum { get; private set; }
  314. [Category("Read Only")]
  315. public string TestLongReadOnlyString
  316. {
  317. get { return "This is a really long string with no reason other than to test long strings."; }
  318. }
  319. #endif
  320. }