|
21 | 21 | using System;
|
22 | 22 | using System.Globalization;
|
23 | 23 | using System.IO;
|
| 24 | +using System.Net.Http; |
24 | 25 | using System.Numerics;
|
25 | 26 | using System.Runtime.InteropServices;
|
26 | 27 | using System.Runtime.Intrinsics;
|
| 28 | +using System.Text; |
27 | 29 | using System.Text.RegularExpressions;
|
28 | 30 | using System.Threading;
|
| 31 | +using System.Threading.Tasks; |
29 | 32 | using WebAssembly;
|
30 | 33 |
|
31 | 34 | namespace Uno.Wasm.Sample
|
32 | 35 | {
|
33 | 36 | public static class Program
|
34 | 37 | {
|
35 |
| - static void Main() |
| 38 | + static async Task Main() |
36 | 39 | {
|
37 |
| - // Validate mono tracing with __Native special pinvoke library name |
38 |
| - InternalImportTest.mono_trace_enable(1); |
39 |
| - |
40 |
| - var runtimeMode = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE"); |
41 |
| - Console.WriteLine($"Mono Runtime Mode: " + runtimeMode); |
42 |
| - |
43 |
| - Console.WriteLine($"test_add:{SideModule1.test_add(21, 21)}"); |
44 |
| - Console.WriteLine($"test_float:{SideModule1.test_add_float1(21, 21)}"); |
45 |
| - Console.WriteLine($"test_add_double:{SideModule1.test_add_double(21, 21)}"); |
46 |
| - |
47 |
| - Console.WriteLine($"Before now"); |
48 |
| - var now = DateTime.Now; |
49 |
| - Console.WriteLine($"now:{now} +1:{now.AddDays(1)} -1:{now.AddDays(-1)}"); |
50 |
| - |
51 |
| - var validateEmAddFunctionResult = int.Parse(Imports.ValidateEmAddFunction()) != 0; |
52 |
| - |
53 |
| - var idbFSValidation = Imports.ValidateIDBFS(); |
54 |
| - Console.WriteLine($"idbFSValidation: {idbFSValidation}"); |
55 |
| - |
56 |
| - var requireAvailable = Imports.RequireAvailable(); |
57 |
| - Console.WriteLine($"requireAvailable: {requireAvailable}"); |
58 |
| - |
59 |
| - var glAvailable = Imports.GLAvailable(); |
60 |
| - Console.WriteLine($"glAvailable: {glAvailable}"); |
61 |
| - |
62 |
| - var functionsExportsAvailable = Imports.FunctionsExportsAvailable(); |
63 |
| - Console.WriteLine($"functionsExportsAvailable: {functionsExportsAvailable}"); |
64 |
| - |
65 |
| - var jsInteropResult = Imports.TestCallback(); |
66 |
| - |
67 |
| - var jsTimeZone = Imports.GetJSTimeZone(); |
68 |
| - var clrTimeZone = TimeZoneInfo.Local.DisplayName; |
69 |
| - var timezoneValidation = |
70 |
| -#if NET5_0_OR_GREATER |
71 |
| - true; // Timezone support is not yet enabled for NET 5 |
72 |
| -#else |
73 |
| - jsTimeZone == clrTimeZone; |
74 |
| -#endif |
75 |
| - |
76 |
| - Console.WriteLine($"Timezone: {jsTimeZone};{clrTimeZone}"); |
77 |
| - |
78 |
| - Console.WriteLine($"SIMD: {Vector.IsHardwareAccelerated}"); |
79 |
| - |
80 |
| -#if NET7_0_OR_GREATER |
81 |
| - Console.WriteLine($"Vector64: {Vector64.IsHardwareAccelerated}"); |
82 |
| - Console.WriteLine($"Vector128: {Vector128.IsHardwareAccelerated}"); |
83 |
| -#endif |
84 |
| - |
85 |
| - File.WriteAllText("/tmp/test.txt", "test.txt"); |
86 |
| - var chmodRes = AdditionalImportTest.chmod("/tmp/test.txt", AdditionalImportTest.UGO_RWX); |
87 |
| - |
88 |
| - var additionalNativeAdd = AdditionalImportTest.additional_native_add(21, 21); |
89 |
| - var additionalNativeAdd2 = AdditionalImportTest.additional_native_add2(21, 21); |
90 |
| - |
91 |
| - var resManager = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly); |
92 |
| - var s1 = resManager.GetString("WebDescriptionMissing", new CultureInfo("en-US")); |
93 |
| - var s2 = resManager.GetString("WebDescriptionMissing", new CultureInfo("fr-CA")); |
94 |
| - Console.WriteLine($"Res(en-US): {s1}"); |
95 |
| - Console.WriteLine($"Res(fr-CA): {s2}"); |
96 |
| - |
97 |
| - var satelliteValidation = |
98 |
| - s1 == "Cannot find definition for {0}. Service Description with namespace {1} is missing." |
99 |
| - && s2 == "Impossible de localiser une définition pour {0}. Description du service manquante avec l'espace de noms {1}." |
100 |
| - ; |
101 |
| - |
102 |
| - var res = $"{runtimeMode};" + |
103 |
| - $"{SideModule1.test_add(21, 21)};" + |
104 |
| - $"{SideModule1.test_add_float1(21.1f, 21.2f):.00};" + |
105 |
| - $"{SideModule1.test_add_double(21.3, 21.4)};" + |
106 |
| - $"e{SideModule1.test_exception()};" + |
107 |
| - $"{validateEmAddFunctionResult};" + |
108 |
| - $"{idbFSValidation};" + |
109 |
| - $"{timezoneValidation};" + |
110 |
| - $"{SideModule2.side2_getCustomVersion()};" + |
111 |
| - $"{SideModule3.side3_getCustomVersion()};" + |
112 |
| - $"{SideModule4.side4_getCustomVersion()};" + |
113 |
| - $"{chmodRes};" + |
114 |
| - $"{additionalNativeAdd};" + |
115 |
| - $"requireJs:{requireAvailable};" + |
116 |
| - $"jsInterop:{jsInteropResult};" + |
117 |
| - $"gl:{glAvailable};"+ |
118 |
| - $"functionsExportsAvailable:{functionsExportsAvailable};"+ |
119 |
| - $"sat:{satelliteValidation};" |
120 |
| - ; |
121 |
| - |
122 |
| - var r = Imports.AppendResult(res); |
123 |
| - |
124 |
| - SideModule1.test_png(); |
| 40 | + try |
| 41 | + { |
| 42 | + // Validate mono tracing with __Native special pinvoke library name |
| 43 | + InternalImportTest.mono_trace_enable(1); |
| 44 | + |
| 45 | + var runtimeMode = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE"); |
| 46 | + Console.WriteLine($"Mono Runtime Mode: " + runtimeMode); |
| 47 | + |
| 48 | + var appBase = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_APP_BASE"); |
| 49 | + var webAppBase = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_WEBAPP_BASE_PATH"); |
| 50 | + |
| 51 | + Console.WriteLine($"test_add:{SideModule1.test_add(21, 21)}"); |
| 52 | + Console.WriteLine($"test_float:{SideModule1.test_add_float1(21, 21)}"); |
| 53 | + Console.WriteLine($"test_add_double:{SideModule1.test_add_double(21, 21)}"); |
| 54 | + |
| 55 | + Console.WriteLine($"Before now"); |
| 56 | + var now = DateTime.Now; |
| 57 | + Console.WriteLine($"now:{now} +1:{now.AddDays(1)} -1:{now.AddDays(-1)}"); |
| 58 | + |
| 59 | + var validateEmAddFunctionResult = int.Parse(Imports.ValidateEmAddFunction()) != 0; |
| 60 | + |
| 61 | + var idbFSValidation = Imports.ValidateIDBFS(); |
| 62 | + Console.WriteLine($"idbFSValidation: {idbFSValidation}"); |
| 63 | + |
| 64 | + var requireAvailable = Imports.RequireAvailable(); |
| 65 | + Console.WriteLine($"requireAvailable: {requireAvailable}"); |
| 66 | + |
| 67 | + var glAvailable = Imports.GLAvailable(); |
| 68 | + Console.WriteLine($"glAvailable: {glAvailable}"); |
| 69 | + |
| 70 | + var functionsExportsAvailable = Imports.FunctionsExportsAvailable(); |
| 71 | + Console.WriteLine($"functionsExportsAvailable: {functionsExportsAvailable}"); |
| 72 | + |
| 73 | + var jsInteropResult = Imports.TestCallback(); |
| 74 | + |
| 75 | + var jsTimeZone = Imports.GetJSTimeZone(); |
| 76 | + var clrTimeZone = TimeZoneInfo.Local.DisplayName; |
| 77 | + var timezoneValidation = |
| 78 | + #if NET5_0_OR_GREATER |
| 79 | + true; // Timezone support is not yet enabled for NET 5 |
| 80 | + #else |
| 81 | + jsTimeZone == clrTimeZone; |
| 82 | + #endif |
| 83 | + |
| 84 | + Console.WriteLine($"Timezone: {jsTimeZone};{clrTimeZone}"); |
| 85 | + |
| 86 | + Console.WriteLine($"SIMD: {Vector.IsHardwareAccelerated}"); |
| 87 | + |
| 88 | + #if NET7_0_OR_GREATER |
| 89 | + Console.WriteLine($"Vector64: {Vector64.IsHardwareAccelerated}"); |
| 90 | + Console.WriteLine($"Vector128: {Vector128.IsHardwareAccelerated}"); |
| 91 | + #endif |
| 92 | + |
| 93 | + File.WriteAllText("/tmp/test.txt", "test.txt"); |
| 94 | + var chmodRes = AdditionalImportTest.chmod("/tmp/test.txt", AdditionalImportTest.UGO_RWX); |
| 95 | + |
| 96 | + var additionalNativeAdd = AdditionalImportTest.additional_native_add(21, 21); |
| 97 | + var additionalNativeAdd2 = AdditionalImportTest.additional_native_add2(21, 21); |
| 98 | + |
| 99 | + var resManager = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly); |
| 100 | + var s1 = resManager.GetString("WebDescriptionMissing", new CultureInfo("en-US")); |
| 101 | + var s2 = resManager.GetString("WebDescriptionMissing", new CultureInfo("fr-CA")); |
| 102 | + Console.WriteLine($"Res(en-US): {s1}"); |
| 103 | + Console.WriteLine($"Res(fr-CA): {s2}"); |
| 104 | + |
| 105 | + var satelliteValidation = |
| 106 | + s1 == "Cannot find definition for {0}. Service Description with namespace {1} is missing." |
| 107 | + && s2 == "Impossible de localiser une définition pour {0}. Description du service manquante avec l'espace de noms {1}." |
| 108 | + ; |
| 109 | + |
| 110 | + var assetsUrl = $"{Imports.GetAppAddress()}{webAppBase}{appBase}/uno-assets.txt"; |
| 111 | + Console.WriteLine($"Reading assets from {assetsUrl}"); |
| 112 | + var assets = Encoding.UTF8.GetString(await new HttpClient().GetByteArrayAsync(assetsUrl)); |
| 113 | + |
| 114 | + var linkedAsset = assets.Contains("Linked/nuget.linked.config"); |
| 115 | + |
| 116 | + var res = $"{runtimeMode};" + |
| 117 | + $"{SideModule1.test_add(21, 21)};" + |
| 118 | + $"{SideModule1.test_add_float1(21.1f, 21.2f):.00};" + |
| 119 | + $"{SideModule1.test_add_double(21.3, 21.4)};" + |
| 120 | + $"e{SideModule1.test_exception()};" + |
| 121 | + $"{validateEmAddFunctionResult};" + |
| 122 | + $"{idbFSValidation};" + |
| 123 | + $"{timezoneValidation};" + |
| 124 | + $"{SideModule2.side2_getCustomVersion()};" + |
| 125 | + $"{SideModule3.side3_getCustomVersion()};" + |
| 126 | + $"{SideModule4.side4_getCustomVersion()};" + |
| 127 | + $"{chmodRes};" + |
| 128 | + $"{additionalNativeAdd};" + |
| 129 | + $"requireJs:{requireAvailable};" + |
| 130 | + $"jsInterop:{jsInteropResult};" + |
| 131 | + $"gl:{glAvailable};"+ |
| 132 | + $"ex:{functionsExportsAvailable};"+ |
| 133 | + $"sat:{satelliteValidation};" + |
| 134 | + $"la:{linkedAsset};" |
| 135 | + ; |
| 136 | + |
| 137 | + Console.WriteLine($"Test Results={res}"); |
| 138 | + |
| 139 | + var r = Imports.AppendResult(res); |
| 140 | + |
| 141 | + SideModule1.test_png(); |
| 142 | + } |
| 143 | + catch (Exception e) |
| 144 | + { |
| 145 | + Console.WriteLine($"Test run failed with {e}"); |
| 146 | + } |
125 | 147 | }
|
126 | 148 | }
|
127 | 149 |
|
@@ -209,6 +231,10 @@ public static partial string ValidateIDBFS()
|
209 | 231 |
|
210 | 232 | public static partial string ValidateIDBFS();
|
211 | 233 |
|
| 234 | + [System.Runtime.InteropServices.JavaScript.JSImport("globalThis.getLocation")] |
| 235 | + |
| 236 | + public static partial string GetAppAddress(); |
| 237 | + |
212 | 238 | #if !USE_JSIMPORT
|
213 | 239 | public static partial string RequireAvailable()
|
214 | 240 | => Runtime.InvokeJS($"requireAvailable()");
|
|
0 commit comments