(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Cryptography / ProtectedMemoryTest.cs
bloba8827ff41f1ed2cffd7b21037cf8c318650998a8
1 //
2 // ProtectedMemoryTest.cs - NUnit Test Cases for ProtectedMemory
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
10 #if NET_2_0
12 using NUnit.Framework;
14 using System;
15 using System.Security.Cryptography;
17 namespace MonoTests.System.Security.Cryptography {
19 // References:
20 // a.
22 [TestFixture]
23 public class ProtectedMemoryTest : Assertion {
25 private void ProtectUnprotect (MemoryProtectionScope scope)
27 byte[] data = new byte [16];
28 ProtectedMemory.Protect (data, scope);
29 int total = 0;
30 for (int i=0; i < 16; i++)
31 total += data [i];
32 Assert ("Protect", (total != 0));
34 ProtectedMemory.Unprotect (data, scope);
35 total = 0;
36 for (int i=0; i < 16; i++)
37 total += data [i];
38 Assert ("Unprotect", (total == 0));
41 [Test]
42 public void ProtectSameProcess ()
44 try {
45 // we're testing the MemoryProtectionScope definition but
46 // not if it's really limited to the scope specified
47 ProtectUnprotect (MemoryProtectionScope.SameProcess);
49 catch (PlatformNotSupportedException) {
50 Console.WriteLine ("Only supported under Windows XP and later");
54 [Test]
55 public void ProtectSameLogon ()
57 try {
58 // we're testing the MemoryProtectionScope definition but
59 // not if it's really limited to the scope specified
60 ProtectUnprotect (MemoryProtectionScope.SameLogon);
62 catch (PlatformNotSupportedException) {
63 Console.WriteLine ("Only supported under Windows XP and later");
67 [Test]
68 public void ProtectCrossProcess ()
70 try {
71 // we're testing the MemoryProtectionScope definition but
72 // not if it's really limited to the scope specified
73 ProtectUnprotect (MemoryProtectionScope.CrossProcess);
75 catch (PlatformNotSupportedException) {
76 Console.WriteLine ("Only supported under Windows XP and later");
80 [Test]
81 [ExpectedException (typeof (CryptographicException))]
82 public void ProtectBadDataLength ()
84 byte[] data = new byte [15];
85 ProtectedMemory.Protect (data, MemoryProtectionScope.SameProcess);
88 [Test]
89 [ExpectedException (typeof (ArgumentNullException))]
90 public void ProtectNull ()
92 ProtectedMemory.Protect (null, MemoryProtectionScope.SameProcess);
95 [Test]
96 [ExpectedException (typeof (CryptographicException))]
97 public void UnprotectBadDataLength ()
99 byte[] data = new byte [15];
100 ProtectedMemory.Unprotect (data, MemoryProtectionScope.SameProcess);
103 [Test]
104 [ExpectedException (typeof (ArgumentNullException))]
105 public void UnprotectNull ()
107 ProtectedMemory.Unprotect (null, MemoryProtectionScope.SameProcess);
112 #endif