|
1 |
| -using NamespacesDerived; |
| 1 | +using System.IO; |
| 2 | +using System.Xml.Linq; |
| 3 | +using System.Linq; |
| 4 | +using System; |
| 5 | +using System.Reflection; |
2 | 6 | using NUnit.Framework;
|
| 7 | +using NamespacesDerived; |
3 | 8 |
|
4 | 9 | [TestFixture]
|
5 | 10 | public class NamespaceDerivedTests
|
@@ -39,6 +44,137 @@ public void TestOverrideMethodFromDependency()
|
39 | 44 | }
|
40 | 45 | }
|
41 | 46 |
|
| 47 | + [Test] |
| 48 | + public void TestComments() |
| 49 | + { |
| 50 | + Type testCommentsType = typeof(TestComments); |
| 51 | + Assembly assembly = testCommentsType.Assembly; |
| 52 | + string dir = Path.GetDirectoryName(assembly.Location); |
| 53 | + string xml = Path.ChangeExtension(Path.GetFileName(assembly.Location), ".xml"); |
| 54 | + XDocument xmlDoc = XDocument.Load(Path.Combine(dir, xml)); |
| 55 | + XElement members = xmlDoc.Root.Element("members"); |
| 56 | + |
| 57 | + TestClassComment(testCommentsType, members); |
| 58 | + TestGetIOHandlerControlSequence(testCommentsType, members); |
| 59 | + TestSBAttachInfo(testCommentsType, members); |
| 60 | + TestGlfwDestroyWindow(testCommentsType, members); |
| 61 | + } |
| 62 | + |
| 63 | + private static void TestClassComment(Type testCommentsType, XElement members) |
| 64 | + { |
| 65 | + string testCommentsName = $"T:{testCommentsType.FullName}"; |
| 66 | + XElement testComments = members.Elements().Single( |
| 67 | + m => m.Attribute("name").Value == testCommentsName); |
| 68 | + Assert.That(testComments.Element("summary").Elements().Select(p => p.Value), Is.EquivalentTo( |
| 69 | + new[] |
| 70 | + { |
| 71 | + "Hash set/map base class.", |
| 72 | + "Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor", |
| 73 | + "and therefore %HashBase pointers should never be used." |
| 74 | + })); |
| 75 | + } |
| 76 | + |
| 77 | + private static void TestGetIOHandlerControlSequence(Type testCommentsType, XElement members) |
| 78 | + { |
| 79 | + const string name = "GetIOHandlerControlSequence"; |
| 80 | + XElement method = FindMethod(testCommentsType, members, name); |
| 81 | + Assert.That(method.Element("summary").Elements("para").Select(p => p.Value), |
| 82 | + Is.EquivalentTo( |
| 83 | + new[] |
| 84 | + { |
| 85 | + "Get the string that needs to be written to the debugger stdin file", |
| 86 | + "handle when a control character is typed." |
| 87 | + })); |
| 88 | + Assert.That(method.Element("returns").Elements("para").Select(p => p.Value), |
| 89 | + Is.EquivalentTo( |
| 90 | + new[] |
| 91 | + { |
| 92 | + "The string that should be written into the file handle that is", |
| 93 | + "feeding the input stream for the debugger, or NULL if there is", |
| 94 | + "no string for this control key." |
| 95 | + })); |
| 96 | + Assert.That(method.Element("remarks").Elements("para").Select(p => p.Value), |
| 97 | + Is.EquivalentTo( |
| 98 | + new[] |
| 99 | + { |
| 100 | + "Some GUI programs will intercept \"control + char\" sequences and want", |
| 101 | + "to have them do what normally would happen when using a real", |
| 102 | + "terminal, so this function allows GUI programs to emulate this", |
| 103 | + "functionality." |
| 104 | + })); |
| 105 | + XElement ch = method.Element("param"); |
| 106 | + Assert.That(ch.Attribute("name").Value, |
| 107 | + Is.EqualTo(testCommentsType.GetMethod(name).GetParameters()[0].Name)); |
| 108 | + Assert.That(ch.Value, Is.EqualTo("The character that was typed along with the control key")); |
| 109 | + } |
| 110 | + |
| 111 | + private static void TestSBAttachInfo(Type testCommentsType, XElement members) |
| 112 | + { |
| 113 | + const string name = "SBAttachInfo"; |
| 114 | + XElement method = FindMethod(testCommentsType, members, name); |
| 115 | + Assert.That(method.Element("remarks").Elements("para").Select(p => p.Value), |
| 116 | + Is.EquivalentTo( |
| 117 | + new[] |
| 118 | + { |
| 119 | + "This function implies that a future call to SBTarget::Attach(...)", |
| 120 | + "will be synchronous." |
| 121 | + })); |
| 122 | + |
| 123 | + ParameterInfo[] @params = testCommentsType.GetMethod(name).GetParameters(); |
| 124 | + |
| 125 | + XElement path = method.Element("param"); |
| 126 | + Assert.That(path.Attribute("name").Value, |
| 127 | + Is.EqualTo(@params[0].Name)); |
| 128 | + Assert.That(path.Value, Is.EqualTo("A full or partial name for the process to attach to.")); |
| 129 | + |
| 130 | + XElement wait_for = (XElement) path.NextNode; |
| 131 | + Assert.That(wait_for.Attribute("name").Value, Is.EqualTo(@params[1].Name)); |
| 132 | + Assert.That(wait_for.Elements("para").Select(p => string.Concat(p.Nodes())), |
| 133 | + Is.EquivalentTo( |
| 134 | + new[] |
| 135 | + { |
| 136 | + "If <c>false,</c> attach to an existing process whose name matches.", |
| 137 | + "If <c>true,</c> then wait for the next process whose name matches." |
| 138 | + })); |
| 139 | + } |
| 140 | + |
| 141 | + private static void TestGlfwDestroyWindow(Type testCommentsType, XElement members) |
| 142 | + { |
| 143 | + const string name = "GlfwDestroyWindow"; |
| 144 | + XElement method = FindMethod(testCommentsType, members, name); |
| 145 | + Assert.That(method.Element("summary").Value, |
| 146 | + Is.EqualTo("Destroys the specified window and its context.")); |
| 147 | + Assert.That(method.Element("remarks").Elements("para").Select(p => p.Value), |
| 148 | + Is.EquivalentTo( |
| 149 | + new[] |
| 150 | + { |
| 151 | + "This function destroys the specified window and its context. On calling", |
| 152 | + "this function, no further callbacks will be called for that window.", |
| 153 | + "If the context of the specified window is current on the main thread, it is", |
| 154 | + "detached before being destroyed.", |
| 155 | + "The context of the specified window must not be current on any other", |
| 156 | + "thread when this function is called.", |
| 157 | + "This function must not be called from a callback.", |
| 158 | + "_safety This function must only be called from the main thread.", |
| 159 | + "Added in version 3.0. Replaces `glfwCloseWindow`." |
| 160 | + })); |
| 161 | + XElement window = method.Element("param"); |
| 162 | + Assert.That(window.Attribute("name").Value, |
| 163 | + Is.EqualTo(testCommentsType.GetMethod(name).GetParameters()[0].Name)); |
| 164 | + Assert.That(window.Value, Is.EqualTo("The window to destroy.")); |
| 165 | + } |
| 166 | + |
| 167 | + private static XElement FindMethod(Type testCommentsType, XElement members, string name) |
| 168 | + { |
| 169 | + string fullName = $"M:{testCommentsType.FullName}.{name}"; |
| 170 | + return members.Elements().Single( |
| 171 | + m => |
| 172 | + { |
| 173 | + string name = m.Attribute("name").Value; |
| 174 | + return name.Substring(0, Math.Max(name.IndexOf('('), 0)) == fullName; |
| 175 | + }); |
| 176 | + } |
| 177 | + |
42 | 178 | private class OverrideMethodFromDependency : HasVirtualInDependency
|
43 | 179 | {
|
44 | 180 | public override int VirtualInCore(int parameter) => 2;
|
|
0 commit comments