CngAlgorithmGroupTest.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // Unit tests for System.Security.Cryptography.CngAlgorithmGroup
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if !MOBILE
  29. using System;
  30. using System.Security.Cryptography;
  31. using NUnit.Framework;
  32. namespace MonoTests.System.Security.Cryptography {
  33. [TestFixture]
  34. public class CngAlgorithmGroupTest {
  35. [Test]
  36. public void StaticProperties ()
  37. {
  38. Assert.IsNotNull (CngAlgorithmGroup.DiffieHellman, "DiffieHellman");
  39. Assert.IsNotNull (CngAlgorithmGroup.Dsa, "Dsa");
  40. Assert.IsNotNull (CngAlgorithmGroup.ECDiffieHellman, "ECDiffieHellman");
  41. Assert.IsNotNull (CngAlgorithmGroup.ECDsa, "ECDsa");
  42. Assert.IsNotNull (CngAlgorithmGroup.Rsa, "Rsa");
  43. }
  44. [Test]
  45. [ExpectedException (typeof (ArgumentNullException))]
  46. public void ConstructorNull ()
  47. {
  48. new CngAlgorithmGroup (null);
  49. }
  50. [Test]
  51. [ExpectedException (typeof (ArgumentException))]
  52. public void ConstructorEmpty ()
  53. {
  54. new CngAlgorithmGroup (String.Empty);
  55. }
  56. static CngAlgorithmGroup mono = new CngAlgorithmGroup ("mono");
  57. private void Check (CngAlgorithmGroup group)
  58. {
  59. Assert.AreEqual (group.AlgorithmGroup, group.ToString (), "Algorithm/ToString");
  60. Assert.AreEqual (group.GetHashCode (), group.AlgorithmGroup.GetHashCode (), "GetHashCode");
  61. Assert.IsTrue (group.Equals (group), "Equals(self)");
  62. Assert.IsTrue (group.Equals ((object) group), "Equals((object)self)");
  63. CngAlgorithmGroup copy = new CngAlgorithmGroup (group.AlgorithmGroup);
  64. Assert.AreEqual (group.GetHashCode (), copy.GetHashCode (), "Copy");
  65. Assert.IsTrue (group.Equals (copy), "Equals(copy)");
  66. Assert.IsTrue (group.Equals ((object) copy), "Equals((object)copy)");
  67. Assert.IsTrue (group == copy, "algo==copy");
  68. Assert.IsFalse (group != copy, "algo!=copy");
  69. Assert.IsFalse (group.Equals (mono), "Equals(mono)");
  70. Assert.IsFalse (group.Equals ((object) mono), "Equals((object)mono)");
  71. Assert.IsFalse (group == mono, "algo==mono");
  72. Assert.IsTrue (group != mono, "algo!=mono");
  73. }
  74. [Test]
  75. public void ConstructorCustom ()
  76. {
  77. CngAlgorithmGroup group = new CngAlgorithmGroup ("custom");
  78. Check (group);
  79. Assert.IsFalse (group.Equals ((CngAlgorithmGroup) null), "Equals((CngAlgorithmGroup)null)");
  80. Assert.IsFalse (group.Equals ((object) null), "Equals((object)null)");
  81. }
  82. [Test]
  83. public void DiffieHellman ()
  84. {
  85. CngAlgorithmGroup group = CngAlgorithmGroup.DiffieHellman;
  86. Assert.AreEqual ("DH", group.AlgorithmGroup, "AlgorithmGroup");
  87. Assert.IsTrue (group.Equals (CngAlgorithmGroup.DiffieHellman), "Equals(static)");
  88. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.DiffieHellman), "ReferenceEquals");
  89. Check (group);
  90. }
  91. [Test]
  92. public void Dsa ()
  93. {
  94. CngAlgorithmGroup group = CngAlgorithmGroup.Dsa;
  95. Assert.AreEqual ("DSA", group.AlgorithmGroup, "AlgorithmGroup");
  96. Assert.IsTrue (group.Equals (CngAlgorithmGroup.Dsa), "Equals(static)");
  97. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Dsa), "ReferenceEquals");
  98. Check (group);
  99. }
  100. [Test]
  101. public void ECDiffieHellman ()
  102. {
  103. CngAlgorithmGroup group = CngAlgorithmGroup.ECDiffieHellman;
  104. Assert.AreEqual ("ECDH", group.AlgorithmGroup, "AlgorithmGroup");
  105. Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDiffieHellman), "Equals(static)");
  106. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDiffieHellman), "ReferenceEquals");
  107. Check (group);
  108. }
  109. [Test]
  110. public void ECDsa ()
  111. {
  112. CngAlgorithmGroup group = CngAlgorithmGroup.ECDsa;
  113. Assert.AreEqual ("ECDSA", group.AlgorithmGroup, "AlgorithmGroup");
  114. Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDsa), "Equals(static)");
  115. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDsa), "ReferenceEquals");
  116. Check (group);
  117. }
  118. [Test]
  119. public void Rsa ()
  120. {
  121. CngAlgorithmGroup group = CngAlgorithmGroup.Rsa;
  122. Assert.AreEqual ("RSA", group.AlgorithmGroup, "AlgorithmGroup");
  123. Assert.IsTrue (group.Equals (CngAlgorithmGroup.Rsa), "Equals(static)");
  124. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Rsa), "ReferenceEquals");
  125. Check (group);
  126. }
  127. }
  128. }
  129. #endif