-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c10ba3
commit 3838f32
Showing
96 changed files
with
5,077 additions
and
4,750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
encoding = utf-8 | ||
|
||
[*.{xml,csproj,json}] | ||
indent_size = 4 | ||
tab_size = 4 | ||
|
||
[*.cs] | ||
indent_size = 4 | ||
tab_size = 4 | ||
|
||
dotnet_style_qualification_for_field = true | ||
dotnet_style_qualification_for_property = true | ||
dotnet_style_qualification_for_method = true | ||
dotnet_style_qualification_for_event = true | ||
csharp_prefer_simple_using_statement = false | ||
dotnet_style_require_accessibility_modifiers = true | ||
dotnet_style_predefined_type_for_locals_parameters_members = true | ||
dotnet_style_predefined_type_for_member_access = true | ||
dotnet_style_prefer_collection_expression = false | ||
|
||
csharp_style_var_for_built_in_types = true:silent | ||
csharp_style_var_when_type_is_apparent = true:silent | ||
csharp_style_var_elsewhere = false:silent | ||
csharp_style_conditional_delegate_call = true:silent | ||
csharp_style_prefer_primary_constructors = false:silent | ||
csharp_style_prefer_top_level_statements = false:silent | ||
|
||
dotnet_diagnostic.CS1998.severity = error | ||
dotnet_diagnostic.CS1591.severity = none | ||
dotnet_diagnostic.CA2255.severity = none | ||
dotnet_diagnostic.IDE0060.severity = none | ||
dotnet_diagnostic.IDE0280.severity = error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Authentication; | ||
using XmppSharp.Dom; | ||
using XmppSharp.Protocol.Sasl; | ||
using XmppSharp.Protocol.ServiceDiscovery.IdentityValues; | ||
using XmppSharp.Protocol.Tls; | ||
|
||
namespace XmppSharp.Test; | ||
|
||
[TestClass] | ||
public class AttributeHelperTests | ||
{ | ||
Element element = default!; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
=> element = new("root"); | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
=> element = null!; | ||
|
||
[TestMethod] | ||
public void WithXmppEnum() | ||
{ | ||
WithXmppEnum(TlsPolicy.Required, "required"); | ||
WithXmppEnum(TlsPolicy.Optional, "optional"); | ||
WithXmppEnum(MechanismType.Plain, "PLAIN"); | ||
WithXmppEnum(MechanismType.DigestMD5, "DIGEST-MD5"); | ||
WithXmppEnum(ConferenceValues.Text, "text"); | ||
WithXmppEnum(PubSubValues.Owned, "pep"); | ||
WithXmppEnum(PubSubValues.Service, "service"); | ||
WithXmppEnum(GatewayValues.Discord, "discord"); | ||
WithXmppEnum(GatewayValues.Facebook, "facebook"); | ||
WithXmppEnum(GatewayValues.AIM, "aim"); | ||
} | ||
|
||
void WithXmppEnum<T>(T value, string rawValue) where T : struct, Enum | ||
{ | ||
Debug.WriteLine($"WithXmppEnum<{typeof(T).Name}>: raw value={rawValue}"); | ||
|
||
element.SetAttribute("data", value.ToXmppName()); | ||
Assert.AreEqual(rawValue, element.GetAttribute("data")); | ||
|
||
var actual = XmppEnum.ParseOrThrow<T>(element.GetAttribute("data")!); | ||
Assert.AreEqual(value, actual); | ||
|
||
Debug.WriteLine($" {typeof(T).Name}.{actual}: parsed? {value.Equals(actual)}"); | ||
ParserTests.PrintResult(element); | ||
Debug.WriteLine(" ---------------------------------\n"); | ||
} | ||
|
||
enum EnumTestType | ||
{ | ||
CSharp, | ||
VisualBasic | ||
} | ||
|
||
[TestMethod] | ||
public void WithBitwise() | ||
{ | ||
WithBitwise(FileAccess.ReadWrite, true); | ||
WithBitwise(SslProtocols.Tls12 | SslProtocols.Tls13, true); | ||
} | ||
|
||
[TestMethod] | ||
public void WithBitwiseAsString() | ||
{ | ||
WithBitwise(FileAccess.ReadWrite, false); | ||
WithBitwise(SslProtocols.Tls12 | SslProtocols.Tls13, false); | ||
} | ||
|
||
[TestMethod] | ||
public void WithString() | ||
{ | ||
WithBitwise(EnumTestType.CSharp, false); | ||
WithBitwise(EnumTestType.VisualBasic, false); | ||
WithBitwise(ConferenceValues.Text, false); | ||
WithBitwise(TestTimeout.Infinite, false); | ||
WithBitwise(TestIdGenerationStrategy.FullyQualified, false); | ||
WithBitwise(ThreadWaitReason.ExecutionDelay, false); | ||
WithBitwise(ThreadWaitReason.LpcReply, false); | ||
WithBitwise(ThreadPriority.AboveNormal, false); | ||
WithBitwise(ThreadPriority.Highest, false); | ||
} | ||
|
||
void WithBitwise<T>(T value, bool isNumber, [CallerMemberName] string func = default!) where T : struct, Enum | ||
{ | ||
var typeName = typeof(T).Name; | ||
object rawValue = Convert.ChangeType(value, Enum.GetUnderlyingType(typeof(T))); | ||
|
||
element.SetAttributeEnum("data", (T?)value, isNumber); | ||
Assert.AreEqual(isNumber ? rawValue.ToString() : value.ToString(), element.GetAttribute("data")); | ||
|
||
var actual = element.GetAttributeEnum<T>("data", isNumber: isNumber); | ||
Debug.WriteLine($"{func}<{typeName}>: {value} ({rawValue} @ {rawValue.GetType().Name})"); | ||
|
||
var isParsed = value.Equals(actual); | ||
|
||
Debug.WriteLine($" {typeName}.{actual}: parsed? {isParsed}\n"); | ||
|
||
ParserTests.PrintResult(element); | ||
|
||
Debug.WriteLine("\n---------------------------------\n"); | ||
|
||
if (!isParsed) | ||
Assert.Fail(); | ||
} | ||
} |
Oops, something went wrong.