CngAlgorithmGroupTest.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. using System;
  29. using System.Security.Cryptography;
  30. using NUnit.Framework;
  31. namespace MonoTests.System.Security.Cryptography {
  32. [TestFixture]
  33. public class CngAlgorithmGroupTest {
  34. [Test]
  35. public void StaticProperties ()
  36. {
  37. Assert.IsNotNull (CngAlgorithmGroup.DiffieHellman, "DiffieHellman");
  38. Assert.IsNotNull (CngAlgorithmGroup.Dsa, "Dsa");
  39. Assert.IsNotNull (CngAlgorithmGroup.ECDiffieHellman, "ECDiffieHellman");
  40. Assert.IsNotNull (CngAlgorithmGroup.ECDsa, "ECDsa");
  41. Assert.IsNotNull (CngAlgorithmGroup.Rsa, "Rsa");
  42. }
  43. [Test]
  44. [ExpectedException (typeof (ArgumentNullException))]
  45. public void ConstructorNull ()
  46. {
  47. new CngAlgorithmGroup (null);
  48. }
  49. [Test]
  50. [ExpectedException (typeof (ArgumentException))]
  51. public void ConstructorEmpty ()
  52. {
  53. new CngAlgorithmGroup (String.Empty);
  54. }
  55. static CngAlgorithmGroup mono = new CngAlgorithmGroup ("mono");
  56. private void Check (CngAlgorithmGroup group)
  57. {
  58. Assert.AreEqual (group.AlgorithmGroup, group.ToString (), "Algorithm/ToString");
  59. Assert.AreEqual (group.GetHashCode (), group.AlgorithmGroup.GetHashCode (), "GetHashCode");
  60. Assert.IsTrue (group.Equals (group), "Equals(self)");
  61. Assert.IsTrue (group.Equals ((object) group), "Equals((object)self)");
  62. CngAlgorithmGroup copy = new CngAlgorithmGroup (group.AlgorithmGroup);
  63. Assert.AreEqual (group.GetHashCode (), copy.GetHashCode (), "Copy");
  64. Assert.IsTrue (group.Equals (copy), "Equals(copy)");
  65. Assert.IsTrue (group.Equals ((object) copy), "Equals((object)copy)");
  66. Assert.IsTrue (group == copy, "algo==copy");
  67. Assert.IsFalse (group != copy, "algo!=copy");
  68. Assert.IsFalse (group.Equals (mono), "Equals(mono)");
  69. Assert.IsFalse (group.Equals ((object) mono), "Equals((object)mono)");
  70. Assert.IsFalse (group == mono, "algo==mono");
  71. Assert.IsTrue (group != mono, "algo!=mono");
  72. }
  73. [Test]
  74. public void ConstructorCustom ()
  75. {
  76. CngAlgorithmGroup group = new CngAlgorithmGroup ("custom");
  77. Check (group);
  78. Assert.IsFalse (group.Equals ((CngAlgorithmGroup) null), "Equals((CngAlgorithmGroup)null)");
  79. Assert.IsFalse (group.Equals ((object) null), "Equals((object)null)");
  80. }
  81. [Test]
  82. public void DiffieHellman ()
  83. {
  84. CngAlgorithmGroup group = CngAlgorithmGroup.DiffieHellman;
  85. Assert.AreEqual ("DH", group.AlgorithmGroup, "AlgorithmGroup");
  86. Assert.IsTrue (group.Equals (CngAlgorithmGroup.DiffieHellman), "Equals(static)");
  87. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.DiffieHellman), "ReferenceEquals");
  88. Check (group);
  89. }
  90. [Test]
  91. public void Dsa ()
  92. {
  93. CngAlgorithmGroup group = CngAlgorithmGroup.Dsa;
  94. Assert.AreEqual ("DSA", group.AlgorithmGroup, "AlgorithmGroup");
  95. Assert.IsTrue (group.Equals (CngAlgorithmGroup.Dsa), "Equals(static)");
  96. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Dsa), "ReferenceEquals");
  97. Check (group);
  98. }
  99. [Test]
  100. public void ECDiffieHellman ()
  101. {
  102. CngAlgorithmGroup group = CngAlgorithmGroup.ECDiffieHellman;
  103. Assert.AreEqual ("ECDH", group.AlgorithmGroup, "AlgorithmGroup");
  104. Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDiffieHellman), "Equals(static)");
  105. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDiffieHellman), "ReferenceEquals");
  106. Check (group);
  107. }
  108. [Test]
  109. public void ECDsa ()
  110. {
  111. CngAlgorithmGroup group = CngAlgorithmGroup.ECDsa;
  112. Assert.AreEqual ("ECDSA", group.AlgorithmGroup, "AlgorithmGroup");
  113. Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDsa), "Equals(static)");
  114. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDsa), "ReferenceEquals");
  115. Check (group);
  116. }
  117. [Test]
  118. public void Rsa ()
  119. {
  120. CngAlgorithmGroup group = CngAlgorithmGroup.Rsa;
  121. Assert.AreEqual ("RSA", group.AlgorithmGroup, "AlgorithmGroup");
  122. Assert.IsTrue (group.Equals (CngAlgorithmGroup.Rsa), "Equals(static)");
  123. Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Rsa), "ReferenceEquals");
  124. Check (group);
  125. }
  126. }
  127. }