##// END OF EJS Templates
ported tests to mono
cin -
r77:91362ffbecf8 v2
parent child
Show More
@@ -0,0 +1,80
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <PropertyGroup>
4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 <ProductVersion>8.0.30703</ProductVersion>
7 <SchemaVersion>2.0</SchemaVersion>
8 <ProjectGuid>{2BD05F84-E067-4B87-9477-FDC2676A21C6}</ProjectGuid>
9 <OutputType>Library</OutputType>
10 <RootNamespace>Implab.Fx.Test</RootNamespace>
11 <AssemblyName>Implab.Fx.Test</AssemblyName>
12 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13 </PropertyGroup>
14 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 <DebugSymbols>true</DebugSymbols>
16 <DebugType>full</DebugType>
17 <Optimize>false</Optimize>
18 <OutputPath>bin\Debug</OutputPath>
19 <DefineConstants>DEBUG;MONO</DefineConstants>
20 <ErrorReport>prompt</ErrorReport>
21 <WarningLevel>4</WarningLevel>
22 <ConsolePause>false</ConsolePause>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 <Optimize>true</Optimize>
26 <OutputPath>bin\Release</OutputPath>
27 <ErrorReport>prompt</ErrorReport>
28 <WarningLevel>4</WarningLevel>
29 <ConsolePause>false</ConsolePause>
30 <DefineConstants>MONO</DefineConstants>
31 </PropertyGroup>
32 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
33 <DebugSymbols>true</DebugSymbols>
34 <DebugType>full</DebugType>
35 <Optimize>false</Optimize>
36 <OutputPath>bin\Debug</OutputPath>
37 <DefineConstants>DEBUG;TRACE;NET_4_5;MONO</DefineConstants>
38 <ErrorReport>prompt</ErrorReport>
39 <WarningLevel>4</WarningLevel>
40 <ConsolePause>false</ConsolePause>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
43 <Optimize>true</Optimize>
44 <OutputPath>bin\Release</OutputPath>
45 <DefineConstants>NET_4_5;MONO</DefineConstants>
46 <ErrorReport>prompt</ErrorReport>
47 <WarningLevel>4</WarningLevel>
48 <ConsolePause>false</ConsolePause>
49 </PropertyGroup>
50 <ItemGroup>
51 <Reference Include="System" />
52 <Reference Include="nunit.framework" />
53 <Reference Include="System.Windows.Forms" />
54 <Reference Include="System.Drawing" />
55 <Reference Include="System.Data" />
56 </ItemGroup>
57 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
58 <ItemGroup>
59 <ProjectReference Include="..\Implab.Fx\Implab.Fx.csproj">
60 <Project>{06E706F8-6881-43EB-927E-FFC503AF6ABC}</Project>
61 <Name>Implab.Fx</Name>
62 </ProjectReference>
63 <ProjectReference Include="..\Implab\Implab.csproj">
64 <Project>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</Project>
65 <Name>Implab</Name>
66 </ProjectReference>
67 </ItemGroup>
68 <ItemGroup>
69 <Compile Include="OverlayTest.cs" />
70 <Compile Include="Properties\AssemblyInfo.cs" />
71 <Compile Include="Sample\MainForm.Designer.cs" />
72 <Compile Include="Sample\MainForm.cs" />
73 <Compile Include="Sample\OverlayForm.Designer.cs" />
74 <Compile Include="Sample\OverlayForm.cs" />
75 </ItemGroup>
76 <ItemGroup>
77 <None Include="Sample\MainForm.resx" />
78 <None Include="Sample\OverlayForm.resx" />
79 </ItemGroup>
80 </Project> No newline at end of file
@@ -0,0 +1,66
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <PropertyGroup>
4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 <ProductVersion>8.0.30703</ProductVersion>
7 <SchemaVersion>2.0</SchemaVersion>
8 <ProjectGuid>{2BD05F84-E067-4B87-9477-FDC2676A21C6}</ProjectGuid>
9 <OutputType>Library</OutputType>
10 <RootNamespace>Implab.Test</RootNamespace>
11 <AssemblyName>Implab.Test</AssemblyName>
12 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13 </PropertyGroup>
14 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 <DebugSymbols>true</DebugSymbols>
16 <DebugType>full</DebugType>
17 <Optimize>false</Optimize>
18 <OutputPath>bin\Debug</OutputPath>
19 <DefineConstants>DEBUG;MONO</DefineConstants>
20 <ErrorReport>prompt</ErrorReport>
21 <WarningLevel>4</WarningLevel>
22 <ConsolePause>false</ConsolePause>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 <Optimize>true</Optimize>
26 <OutputPath>bin\Release</OutputPath>
27 <ErrorReport>prompt</ErrorReport>
28 <WarningLevel>4</WarningLevel>
29 <ConsolePause>false</ConsolePause>
30 <DefineConstants>MONO</DefineConstants>
31 </PropertyGroup>
32 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
33 <DebugSymbols>true</DebugSymbols>
34 <DebugType>full</DebugType>
35 <Optimize>false</Optimize>
36 <OutputPath>bin\Debug</OutputPath>
37 <DefineConstants>DEBUG;TRACE;NET_4_5;MONO</DefineConstants>
38 <ErrorReport>prompt</ErrorReport>
39 <WarningLevel>4</WarningLevel>
40 <ConsolePause>false</ConsolePause>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
43 <Optimize>true</Optimize>
44 <OutputPath>bin\Release</OutputPath>
45 <DefineConstants>NET_4_5;MONO</DefineConstants>
46 <ErrorReport>prompt</ErrorReport>
47 <WarningLevel>4</WarningLevel>
48 <ConsolePause>false</ConsolePause>
49 </PropertyGroup>
50 <ItemGroup>
51 <Reference Include="System" />
52 <Reference Include="nunit.framework" />
53 </ItemGroup>
54 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
55 <ItemGroup>
56 <Compile Include="AsyncTests.cs" />
57 <Compile Include="PromiseHelper.cs" />
58 <Compile Include="Properties\AssemblyInfo.cs" />
59 </ItemGroup>
60 <ItemGroup>
61 <ProjectReference Include="..\Implab\Implab.csproj">
62 <Project>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</Project>
63 <Name>Implab</Name>
64 </ProjectReference>
65 </ItemGroup>
66 </Project> No newline at end of file
@@ -0,0 +1,290
1 
2 Microsoft Visual Studio Solution File, Format Version 11.00
3 # Visual Studio 2010
4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab", "Implab\Implab.csproj", "{F550F1F8-8746-4AD0-9614-855F4C4B7F05}"
5 EndProject
6 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE8D8D18-437A-445C-B662-4C2CE79A76F6}"
7 ProjectSection(SolutionItems) = preProject
8 Implab.vsmdi = Implab.vsmdi
9 Local.testsettings = Local.testsettings
10 TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
11 EndProjectSection
12 EndProject
13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Fx", "Implab.Fx\Implab.Fx.csproj", "{06E706F8-6881-43EB-927E-FFC503AF6ABC}"
14 EndProject
15 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BCA337C3-BFDC-4825-BBDB-E6D467E4E452}"
16 EndProject
17 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Test.mono", "Implab.Test\Implab.Test.mono.csproj", "{2BD05F84-E067-4B87-9477-FDC2676A21C6}"
18 EndProject
19 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Fx.Test.mono", "Implab.Fx.Test\Implab.Fx.Test.mono.csproj", "{2BD05F84-E067-4B87-9477-FDC2676A21C6}"
20 EndProject
21 Global
22 GlobalSection(SolutionConfigurationPlatforms) = preSolution
23 Debug|Any CPU = Debug|Any CPU
24 Release|Any CPU = Release|Any CPU
25 Debug 4.5|Any CPU = Debug 4.5|Any CPU
26 Release 4.5|Any CPU = Release 4.5|Any CPU
27 EndGlobalSection
28 GlobalSection(ProjectConfigurationPlatforms) = postSolution
29 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
30 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
31 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
34 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
35 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.Build.0 = Release|Any CPU
37 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
38 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
39 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
40 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
41 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
45 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
46 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
47 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
48 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
49 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
50 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.Build.0 = Release|Any CPU
52 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.Build.0 = Release|Any CPU
53 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
54 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
55 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.Build.0 = Debug|Any CPU
57 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
58 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
59 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.ActiveCfg = Release|Any CPU
60 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.Build.0 = Release|Any CPU
61 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
62 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
63 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
64 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
65 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
66 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
67 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
68 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.Build.0 = Release|Any CPU
69 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
70 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
71 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
72 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
73 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
74 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
75 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
76 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.Build.0 = Release|Any CPU
77 EndGlobalSection
78 GlobalSection(NestedProjects) = preSolution
79 {2BD05F84-E067-4B87-9477-FDC2676A21C6} = {BCA337C3-BFDC-4825-BBDB-E6D467E4E452}
80 {2BD05F84-E067-4B87-9477-FDC2676A21C6} = {BCA337C3-BFDC-4825-BBDB-E6D467E4E452}
81 EndGlobalSection
82 GlobalSection(MonoDevelopProperties) = preSolution
83 StartupItem = Implab\Implab.csproj
84 Policies = $0
85 $0.CSharpFormattingPolicy = $1
86 $1.IndentSwitchBody = True
87 $1.NamespaceBraceStyle = EndOfLine
88 $1.ClassBraceStyle = EndOfLine
89 $1.InterfaceBraceStyle = EndOfLine
90 $1.StructBraceStyle = EndOfLine
91 $1.EnumBraceStyle = EndOfLine
92 $1.MethodBraceStyle = EndOfLine
93 $1.ConstructorBraceStyle = EndOfLine
94 $1.DestructorBraceStyle = EndOfLine
95 $1.BeforeMethodDeclarationParentheses = False
96 $1.BeforeMethodCallParentheses = False
97 $1.BeforeConstructorDeclarationParentheses = False
98 $1.NewLineBeforeConstructorInitializerColon = NewLine
99 $1.NewLineAfterConstructorInitializerColon = SameLine
100 $1.BeforeIndexerDeclarationBracket = False
101 $1.BeforeDelegateDeclarationParentheses = False
102 $1.NewParentheses = False
103 $1.SpacesBeforeBrackets = False
104 $1.inheritsSet = Mono
105 $1.inheritsScope = text/x-csharp
106 $1.scope = text/x-csharp
107 $0.TextStylePolicy = $2
108 $2.FileWidth = 120
109 $2.EolMarker = Unix
110 $2.inheritsSet = VisualStudio
111 $2.inheritsScope = text/plain
112 $2.scope = text/x-csharp
113 $0.DotNetNamingPolicy = $3
114 $3.DirectoryNamespaceAssociation = PrefixedHierarchical
115 $3.ResourceNamePolicy = MSBuild
116 $0.TextStylePolicy = $4
117 $4.FileWidth = 120
118 $4.TabsToSpaces = False
119 $4.inheritsSet = VisualStudio
120 $4.inheritsScope = text/plain
121 $4.scope = application/xml
122 $0.XmlFormattingPolicy = $5
123 $5.inheritsSet = Mono
124 $5.inheritsScope = application/xml
125 $5.scope = application/xml
126 $0.TextStylePolicy = $6
127 $6.FileWidth = 120
128 $6.TabsToSpaces = False
129 $6.inheritsSet = VisualStudio
130 $6.inheritsScope = text/plain
131 $6.scope = text/plain
132 $0.NameConventionPolicy = $7
133 $7.Rules = $8
134 $8.NamingRule = $9
135 $9.Name = Namespaces
136 $9.AffectedEntity = Namespace
137 $9.VisibilityMask = VisibilityMask
138 $9.NamingStyle = PascalCase
139 $9.IncludeInstanceMembers = True
140 $9.IncludeStaticEntities = True
141 $8.NamingRule = $10
142 $10.Name = Types
143 $10.AffectedEntity = Class, Struct, Enum, Delegate
144 $10.VisibilityMask = VisibilityMask
145 $10.NamingStyle = PascalCase
146 $10.IncludeInstanceMembers = True
147 $10.IncludeStaticEntities = True
148 $8.NamingRule = $11
149 $11.Name = Interfaces
150 $11.RequiredPrefixes = $12
151 $12.String = I
152 $11.AffectedEntity = Interface
153 $11.VisibilityMask = VisibilityMask
154 $11.NamingStyle = PascalCase
155 $11.IncludeInstanceMembers = True
156 $11.IncludeStaticEntities = True
157 $8.NamingRule = $13
158 $13.Name = Attributes
159 $13.RequiredSuffixes = $14
160 $14.String = Attribute
161 $13.AffectedEntity = CustomAttributes
162 $13.VisibilityMask = VisibilityMask
163 $13.NamingStyle = PascalCase
164 $13.IncludeInstanceMembers = True
165 $13.IncludeStaticEntities = True
166 $8.NamingRule = $15
167 $15.Name = Event Arguments
168 $15.RequiredSuffixes = $16
169 $16.String = EventArgs
170 $15.AffectedEntity = CustomEventArgs
171 $15.VisibilityMask = VisibilityMask
172 $15.NamingStyle = PascalCase
173 $15.IncludeInstanceMembers = True
174 $15.IncludeStaticEntities = True
175 $8.NamingRule = $17
176 $17.Name = Exceptions
177 $17.RequiredSuffixes = $18
178 $18.String = Exception
179 $17.AffectedEntity = CustomExceptions
180 $17.VisibilityMask = VisibilityMask
181 $17.NamingStyle = PascalCase
182 $17.IncludeInstanceMembers = True
183 $17.IncludeStaticEntities = True
184 $8.NamingRule = $19
185 $19.Name = Methods
186 $19.AffectedEntity = Methods
187 $19.VisibilityMask = VisibilityMask
188 $19.NamingStyle = PascalCase
189 $19.IncludeInstanceMembers = True
190 $19.IncludeStaticEntities = True
191 $8.NamingRule = $20
192 $20.Name = Static Readonly Fields
193 $20.AffectedEntity = ReadonlyField
194 $20.VisibilityMask = Internal, Protected, Public
195 $20.NamingStyle = PascalCase
196 $20.IncludeInstanceMembers = False
197 $20.IncludeStaticEntities = True
198 $8.NamingRule = $21
199 $21.Name = Fields (Non Private)
200 $21.AffectedEntity = Field
201 $21.VisibilityMask = Internal, Public
202 $21.NamingStyle = CamelCase
203 $21.IncludeInstanceMembers = True
204 $21.IncludeStaticEntities = True
205 $8.NamingRule = $22
206 $22.Name = ReadOnly Fields (Non Private)
207 $22.AffectedEntity = ReadonlyField
208 $22.VisibilityMask = Internal, Public
209 $22.NamingStyle = CamelCase
210 $22.IncludeInstanceMembers = True
211 $22.IncludeStaticEntities = False
212 $8.NamingRule = $23
213 $23.Name = Fields (Private)
214 $23.RequiredPrefixes = $24
215 $24.String = m_
216 $23.AffectedEntity = Field, ReadonlyField
217 $23.VisibilityMask = Private, Protected
218 $23.NamingStyle = CamelCase
219 $23.IncludeInstanceMembers = True
220 $23.IncludeStaticEntities = False
221 $8.NamingRule = $25
222 $25.Name = Static Fields (Private)
223 $25.RequiredPrefixes = $26
224 $26.String = _
225 $25.AffectedEntity = Field
226 $25.VisibilityMask = Private
227 $25.NamingStyle = CamelCase
228 $25.IncludeInstanceMembers = False
229 $25.IncludeStaticEntities = True
230 $8.NamingRule = $27
231 $27.Name = ReadOnly Fields (Private)
232 $27.RequiredPrefixes = $28
233 $28.String = m_
234 $27.AffectedEntity = ReadonlyField
235 $27.VisibilityMask = Private, Protected
236 $27.NamingStyle = CamelCase
237 $27.IncludeInstanceMembers = True
238 $27.IncludeStaticEntities = False
239 $8.NamingRule = $29
240 $29.Name = Constant Fields
241 $29.AffectedEntity = ConstantField
242 $29.VisibilityMask = VisibilityMask
243 $29.NamingStyle = AllUpper
244 $29.IncludeInstanceMembers = True
245 $29.IncludeStaticEntities = True
246 $8.NamingRule = $30
247 $30.Name = Properties
248 $30.AffectedEntity = Property
249 $30.VisibilityMask = VisibilityMask
250 $30.NamingStyle = PascalCase
251 $30.IncludeInstanceMembers = True
252 $30.IncludeStaticEntities = True
253 $8.NamingRule = $31
254 $31.Name = Events
255 $31.AffectedEntity = Event
256 $31.VisibilityMask = VisibilityMask
257 $31.NamingStyle = PascalCase
258 $31.IncludeInstanceMembers = True
259 $31.IncludeStaticEntities = True
260 $8.NamingRule = $32
261 $32.Name = Enum Members
262 $32.AffectedEntity = EnumMember
263 $32.VisibilityMask = VisibilityMask
264 $32.NamingStyle = PascalCase
265 $32.IncludeInstanceMembers = True
266 $32.IncludeStaticEntities = True
267 $8.NamingRule = $33
268 $33.Name = Parameters
269 $33.AffectedEntity = Parameter, LocalVariable
270 $33.VisibilityMask = VisibilityMask
271 $33.NamingStyle = CamelCase
272 $33.IncludeInstanceMembers = True
273 $33.IncludeStaticEntities = True
274 $8.NamingRule = $34
275 $34.Name = Type Parameters
276 $34.RequiredPrefixes = $35
277 $35.String = T
278 $34.AffectedEntity = TypeParameter
279 $34.VisibilityMask = VisibilityMask
280 $34.NamingStyle = PascalCase
281 $34.IncludeInstanceMembers = True
282 $34.IncludeStaticEntities = True
283 EndGlobalSection
284 GlobalSection(TestCaseManagementSettings) = postSolution
285 CategoryFile = Implab.vsmdi
286 EndGlobalSection
287 GlobalSection(SolutionProperties) = preSolution
288 HideSolutionNode = FALSE
289 EndGlobalSection
290 EndGlobal
@@ -1,12 +1,18
1 using System;
2 using System.Text;
3 using System.Collections.Generic;
4 using System.Linq;
1 using System.Windows.Forms;
2 using Implab.Fx.Test.Sample;
3 using Implab.Fx;
4
5 #if MONO
6
7 using NUnit.Framework;
8 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
9 using TestMethod = NUnit.Framework.TestAttribute;
10
11 #else
12
5 13 using Microsoft.VisualStudio.TestTools.UnitTesting;
6 using System.Windows.Forms;
7 using Implab.Fx.Test.Sample;
8 using System.Drawing;
9 using Implab.Fx;
14
15 #endif
10 16
11 17 namespace Implab.Fx.Test
12 18 {
@@ -22,10 +28,7 namespace Implab.Fx.Test
22 28 {
23 29 var overlay = new OverlayForm();
24 30 mainForm.OverlayFadeIn(overlay).Then(
25 o => o.ButtonEvent += (s2, args2) =>
26 {
27 o.CloseFadeOut();
28 }
31 o => o.ButtonEvent += (s2, args2) => o.CloseFadeOut()
29 32 );
30 33 };
31 34
This diff has been collapsed as it changes many lines, (857 lines changed) Show them Hide them
@@ -1,423 +1,434
1 using System;
2 using Microsoft.VisualStudio.TestTools.UnitTesting;
3 using System.Reflection;
4 using System.Threading;
5 using Implab.Parallels;
6
7 namespace Implab.Test {
8 [TestClass]
9 public class AsyncTests {
10 [TestMethod]
11 public void ResolveTest() {
12 int res = -1;
13 var p = new Promise<int>();
14 p.Then(x => res = x);
15 p.Resolve(100);
16
17 Assert.AreEqual(100, res);
18 }
19
20 [TestMethod]
21 public void RejectTest() {
22 int res = -1;
23 Exception err = null;
24
25 var p = new Promise<int>();
26 p.Then(
27 x => res = x,
28 e => {
29 err = e;
30 return -2;
31 }
32 );
33 p.Reject(new ApplicationException("error"));
34
35 Assert.AreEqual(res, -1);
36 Assert.AreEqual(err.Message, "error");
37
38 }
39
40 [TestMethod]
41 public void CancelExceptionTest() {
42 var p = new Promise<bool>();
43 p.Cancel();
44
45 var p2 = p.Cancelled(() => {
46 throw new ApplicationException("CANCELLED");
47 });
48
49 try {
50 p2.Join();
51 Assert.Fail();
52 } catch (ApplicationException err) {
53 Assert.AreEqual("CANCELLED", err.InnerException.Message);
54 }
55
56 }
57
58 [TestMethod]
59 public void ContinueOnCancelTest() {
60 var p = new Promise<bool>();
61 p.Cancel();
62
63 var p2 = p
64 .Cancelled(() => {
65 throw new ApplicationException("CANCELLED");
66 })
67 .Error(e => true);
68
69 Assert.AreEqual(true, p2.Join());
70 }
71
72 [TestMethod]
73 public void JoinSuccessTest() {
74 var p = new Promise<int>();
75 p.Resolve(100);
76 Assert.AreEqual(p.Join(), 100);
77 }
78
79 [TestMethod]
80 public void JoinFailTest() {
81 var p = new Promise<int>();
82 p.Reject(new ApplicationException("failed"));
83
84 try {
85 p.Join();
86 throw new ApplicationException("WRONG!");
87 } catch (TargetInvocationException err) {
88 Assert.AreEqual(err.InnerException.Message, "failed");
89 } catch {
90 Assert.Fail("Got wrong excaption");
91 }
92 }
93
94 [TestMethod]
95 public void MapTest() {
96 var p = new Promise<int>();
97
98 var p2 = p.Then(x => x.ToString());
99 p.Resolve(100);
100
101 Assert.AreEqual(p2.Join(), "100");
102 }
103
104 [TestMethod]
105 public void FixErrorTest() {
106 var p = new Promise<int>();
107
108 var p2 = p.Error(e => 101);
109
110 p.Reject(new Exception());
111
112 Assert.AreEqual(p2.Join(), 101);
113 }
114
115 [TestMethod]
116 public void ChainTest() {
117 var p1 = new Promise<int>();
118
119 var p3 = p1.Chain(x => {
120 var p2 = new Promise<string>();
121 p2.Resolve(x.ToString());
122 return p2;
123 });
124
125 p1.Resolve(100);
126
127 Assert.AreEqual(p3.Join(), "100");
128 }
129
130 [TestMethod]
131 public void PoolTest() {
132 var pid = Thread.CurrentThread.ManagedThreadId;
133 var p = AsyncPool.Invoke(() => Thread.CurrentThread.ManagedThreadId);
134
135 Assert.AreNotEqual(pid, p.Join());
136 }
137
138 [TestMethod]
139 public void WorkerPoolSizeTest() {
140 var pool = new WorkerPool(5, 10, 0);
141
142 Assert.AreEqual(5, pool.PoolSize);
143
144 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
145 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
146 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
147
148 Assert.AreEqual(5, pool.PoolSize);
149
150 for (int i = 0; i < 100; i++)
151 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
152 Thread.Sleep(200);
153 Assert.AreEqual(10, pool.PoolSize);
154
155 pool.Dispose();
156 }
157
158 [TestMethod]
159 public void WorkerPoolCorrectTest() {
160 var pool = new WorkerPool(0,1000,100);
161
162 int iterations = 1000;
163 int pending = iterations;
164 var stop = new ManualResetEvent(false);
165
166 var count = 0;
167 for (int i = 0; i < iterations; i++) {
168 pool
169 .Invoke(() => 1)
170 .Then(x => Interlocked.Add(ref count, x))
171 .Then(x => Math.Log10(x))
172 .Anyway(() => {
173 Interlocked.Decrement(ref pending);
174 if (pending == 0)
175 stop.Set();
176 });
177 }
178
179 stop.WaitOne();
180
181 Assert.AreEqual(iterations, count);
182 Console.WriteLine("Max threads: {0}", pool.MaxRunningThreads);
183 pool.Dispose();
184
185 }
186
187 [TestMethod]
188 public void WorkerPoolDisposeTest() {
189 var pool = new WorkerPool(5, 20);
190 Assert.AreEqual(5, pool.PoolSize);
191 pool.Dispose();
192 Thread.Sleep(500);
193 Assert.AreEqual(0, pool.PoolSize);
194 pool.Dispose();
195 }
196
197 [TestMethod]
198 public void MTQueueTest() {
199 var queue = new MTQueue<int>();
200 int res;
201
202 queue.Enqueue(10);
203 Assert.IsTrue(queue.TryDequeue(out res));
204 Assert.AreEqual(10, res);
205 Assert.IsFalse(queue.TryDequeue(out res));
206
207 for (int i = 0; i < 1000; i++)
208 queue.Enqueue(i);
209
210 for (int i = 0; i < 1000; i++) {
211 queue.TryDequeue(out res);
212 Assert.AreEqual(i, res);
213 }
214
215 int writers = 0;
216 int readers = 0;
217 var stop = new ManualResetEvent(false);
218 int total = 0;
219
220 int itemsPerWriter = 10000;
221 int writersCount = 10;
222
223 for (int i = 0; i < writersCount; i++) {
224 Interlocked.Increment(ref writers);
225 var wn = i;
226 AsyncPool
227 .InvokeNewThread(() => {
228 for (int ii = 0; ii < itemsPerWriter; ii++) {
229 queue.Enqueue(1);
230 }
231 return 1;
232 })
233 .Anyway(() => Interlocked.Decrement(ref writers));
234 }
235
236 for (int i = 0; i < 10; i++) {
237 Interlocked.Increment(ref readers);
238 var wn = i;
239 AsyncPool
240 .InvokeNewThread(() => {
241 int t;
242 do {
243 while (queue.TryDequeue(out t))
244 Interlocked.Add(ref total, t);
245 } while (writers > 0);
246 return 1;
247 })
248 .Anyway(() => {
249 Interlocked.Decrement(ref readers);
250 if (readers == 0)
251 stop.Set();
252 });
253 }
254
255 stop.WaitOne();
256
257 Assert.AreEqual(itemsPerWriter * writersCount, total);
258 }
259
260 [TestMethod]
261 public void ParallelMapTest() {
262
263 int count = 100000;
264
265 double[] args = new double[count];
266 var rand = new Random();
267
268 for (int i = 0; i < count; i++)
269 args[i] = rand.NextDouble();
270
271 var t = Environment.TickCount;
272 var res = args.ParallelMap(x => Math.Sin(x*x), 4).Join();
273
274 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
275
276 t = Environment.TickCount;
277 for (int i = 0; i < count; i++)
278 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
279 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
280 }
281
282 [TestMethod]
283 public void ChainedMapTest() {
284
285 using (var pool = new WorkerPool(0,100,100)) {
286 int count = 10000;
287
288 double[] args = new double[count];
289 var rand = new Random();
290
291 for (int i = 0; i < count; i++)
292 args[i] = rand.NextDouble();
293
294 var t = Environment.TickCount;
295 var res = args
296 .ChainedMap(
297 x => pool.Invoke(
298 () => Math.Sin(x * x)
299 ),
300 4
301 )
302 .Join();
303
304 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
305
306 t = Environment.TickCount;
307 for (int i = 0; i < count; i++)
308 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
309 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
310 Console.WriteLine("Max workers: {0}", pool.MaxRunningThreads);
311 }
312 }
313
314 [TestMethod]
315 public void ParallelForEachTest() {
316
317 int count = 100000;
318
319 int[] args = new int[count];
320 var rand = new Random();
321
322 for (int i = 0; i < count; i++)
323 args[i] = (int)(rand.NextDouble() * 100);
324
325 int result = 0;
326
327 var t = Environment.TickCount;
328 args.ParallelForEach(x => Interlocked.Add(ref result, x), 4).Join();
329
330 Console.WriteLine("Iteration complete in {0} ms, result: {1}", Environment.TickCount - t, result);
331
332 int result2 = 0;
333
334 t = Environment.TickCount;
335 for (int i = 0; i < count; i++)
336 result2 += args[i];
337 Assert.AreEqual(result2, result);
338 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
339 }
340
341 [TestMethod]
342 public void ComplexCase1Test() {
343 var flags = new bool[3];
344
345 // op1 (aync 200ms) => op2 (async 200ms) => op3 (sync map)
346
347 var p = PromiseHelper
348 .Sleep(200, "Alan")
349 .Cancelled(() => flags[0] = true)
350 .Chain(x =>
351 PromiseHelper
352 .Sleep(200, "Hi, " + x)
353 .Then(y => y)
354 .Cancelled(() => flags[1] = true)
355 )
356 .Cancelled(() => flags[2] = true);
357 Thread.Sleep(300);
358 p.Cancel();
359 try {
360 Assert.AreEqual(p.Join(), "Hi, Alan");
361 Assert.Fail("Shouldn't get here");
362 } catch (OperationCanceledException) {
363 }
364
365 Assert.IsFalse(flags[0]);
366 Assert.IsTrue(flags[1]);
367 Assert.IsTrue(flags[2]);
368 }
369
370 [TestMethod]
371 public void ChainedCancel1Test() {
372 // при отмене сцепленной асинхронной операции все обещание должно
373 // завершаться ошибкой OperationCanceledException
374 var p = PromiseHelper
375 .Sleep(1, "Hi, HAL!")
376 .Then(x => {
377 // запускаем две асинхронные операции
378 var result = PromiseHelper.Sleep(1000, "HEM ENABLED!!!");
379 // вторая операция отменяет первую до завершения
380 PromiseHelper
381 .Sleep(100, "HAL, STOP!")
382 .Then(() => result.Cancel());
383 return result;
384 });
385 try {
386 p.Join();
387 } catch (TargetInvocationException err) {
388 Assert.IsTrue(err.InnerException is OperationCanceledException);
389 }
390 }
391
392 [TestMethod]
393 public void ChainedCancel2Test() {
394 // при отмене цепочки обещаний, вложенные операции также должны отменяться
395 var pSurvive = new Promise<bool>();
396 var hemStarted = new ManualResetEvent(false);
397 var p = PromiseHelper
398 .Sleep(1, "Hi, HAL!")
399 .Chain(x => {
400 hemStarted.Set();
401 // запускаем две асинхронные операции
402 var result = PromiseHelper
403 .Sleep(10000, "HEM ENABLED!!!")
404 .Then(s => pSurvive.Resolve(false));
405
406 result
407 .Cancelled(() => pSurvive.Resolve(true));
408
409 return result;
410 });
411
412 hemStarted.WaitOne();
413 p.Cancel();
414
415 try {
416 p.Join();
417 } catch (OperationCanceledException) {
418 Assert.IsTrue(pSurvive.Join());
419 }
420 }
421 }
422 }
423
1 using System;
2 using System.Reflection;
3 using System.Threading;
4 using Implab.Parallels;
5
6 #if MONO
7
8 using NUnit.Framework;
9 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
10 using TestMethod = NUnit.Framework.TestAttribute;
11
12 #else
13
14 using Microsoft.VisualStudio.TestTools.UnitTesting;
15
16 #endif
17
18 namespace Implab.Test {
19 [TestClass]
20 public class AsyncTests {
21 [TestMethod]
22 public void ResolveTest() {
23 int res = -1;
24 var p = new Promise<int>();
25 p.Then(x => res = x);
26 p.Resolve(100);
27
28 Assert.AreEqual(100, res);
29 }
30
31 [TestMethod]
32 public void RejectTest() {
33 int res = -1;
34 Exception err = null;
35
36 var p = new Promise<int>();
37 p.Then(
38 x => res = x,
39 e => {
40 err = e;
41 return -2;
42 }
43 );
44 p.Reject(new ApplicationException("error"));
45
46 Assert.AreEqual(res, -1);
47 Assert.AreEqual(err.Message, "error");
48
49 }
50
51 [TestMethod]
52 public void CancelExceptionTest() {
53 var p = new Promise<bool>();
54 p.Cancel();
55
56 var p2 = p.Cancelled(() => {
57 throw new ApplicationException("CANCELLED");
58 });
59
60 try {
61 p2.Join();
62 Assert.Fail();
63 } catch (ApplicationException err) {
64 Assert.AreEqual("CANCELLED", err.InnerException.Message);
65 }
66
67 }
68
69 [TestMethod]
70 public void ContinueOnCancelTest() {
71 var p = new Promise<bool>();
72 p.Cancel();
73
74 var p2 = p
75 .Cancelled(() => {
76 throw new ApplicationException("CANCELLED");
77 })
78 .Error(e => true);
79
80 Assert.AreEqual(true, p2.Join());
81 }
82
83 [TestMethod]
84 public void JoinSuccessTest() {
85 var p = new Promise<int>();
86 p.Resolve(100);
87 Assert.AreEqual(p.Join(), 100);
88 }
89
90 [TestMethod]
91 public void JoinFailTest() {
92 var p = new Promise<int>();
93 p.Reject(new ApplicationException("failed"));
94
95 try {
96 p.Join();
97 throw new ApplicationException("WRONG!");
98 } catch (TargetInvocationException err) {
99 Assert.AreEqual(err.InnerException.Message, "failed");
100 } catch {
101 Assert.Fail("Got wrong excaption");
102 }
103 }
104
105 [TestMethod]
106 public void MapTest() {
107 var p = new Promise<int>();
108
109 var p2 = p.Then(x => x.ToString());
110 p.Resolve(100);
111
112 Assert.AreEqual(p2.Join(), "100");
113 }
114
115 [TestMethod]
116 public void FixErrorTest() {
117 var p = new Promise<int>();
118
119 var p2 = p.Error(e => 101);
120
121 p.Reject(new Exception());
122
123 Assert.AreEqual(p2.Join(), 101);
124 }
125
126 [TestMethod]
127 public void ChainTest() {
128 var p1 = new Promise<int>();
129
130 var p3 = p1.Chain(x => {
131 var p2 = new Promise<string>();
132 p2.Resolve(x.ToString());
133 return p2;
134 });
135
136 p1.Resolve(100);
137
138 Assert.AreEqual(p3.Join(), "100");
139 }
140
141 [TestMethod]
142 public void PoolTest() {
143 var pid = Thread.CurrentThread.ManagedThreadId;
144 var p = AsyncPool.Invoke(() => Thread.CurrentThread.ManagedThreadId);
145
146 Assert.AreNotEqual(pid, p.Join());
147 }
148
149 [TestMethod]
150 public void WorkerPoolSizeTest() {
151 var pool = new WorkerPool(5, 10, 0);
152
153 Assert.AreEqual(5, pool.PoolSize);
154
155 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
156 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
157 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
158
159 Assert.AreEqual(5, pool.PoolSize);
160
161 for (int i = 0; i < 100; i++)
162 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
163 Thread.Sleep(200);
164 Assert.AreEqual(10, pool.PoolSize);
165
166 pool.Dispose();
167 }
168
169 [TestMethod]
170 public void WorkerPoolCorrectTest() {
171 var pool = new WorkerPool(0,1000,100);
172
173 const int iterations = 1000;
174 int pending = iterations;
175 var stop = new ManualResetEvent(false);
176
177 var count = 0;
178 for (int i = 0; i < iterations; i++) {
179 pool
180 .Invoke(() => 1)
181 .Then(x => Interlocked.Add(ref count, x))
182 .Then(x => Math.Log10(x))
183 .Anyway(() => {
184 Interlocked.Decrement(ref pending);
185 if (pending == 0)
186 stop.Set();
187 });
188 }
189
190 stop.WaitOne();
191
192 Assert.AreEqual(iterations, count);
193 Console.WriteLine("Max threads: {0}", pool.MaxRunningThreads);
194 pool.Dispose();
195
196 }
197
198 [TestMethod]
199 public void WorkerPoolDisposeTest() {
200 var pool = new WorkerPool(5, 20);
201 Assert.AreEqual(5, pool.PoolSize);
202 pool.Dispose();
203 Thread.Sleep(500);
204 Assert.AreEqual(0, pool.PoolSize);
205 pool.Dispose();
206 }
207
208 [TestMethod]
209 public void MTQueueTest() {
210 var queue = new MTQueue<int>();
211 int res;
212
213 queue.Enqueue(10);
214 Assert.IsTrue(queue.TryDequeue(out res));
215 Assert.AreEqual(10, res);
216 Assert.IsFalse(queue.TryDequeue(out res));
217
218 for (int i = 0; i < 1000; i++)
219 queue.Enqueue(i);
220
221 for (int i = 0; i < 1000; i++) {
222 queue.TryDequeue(out res);
223 Assert.AreEqual(i, res);
224 }
225
226 int writers = 0;
227 int readers = 0;
228 var stop = new ManualResetEvent(false);
229 int total = 0;
230
231 const int itemsPerWriter = 10000;
232 const int writersCount = 10;
233
234 for (int i = 0; i < writersCount; i++) {
235 Interlocked.Increment(ref writers);
236 AsyncPool
237 .InvokeNewThread(() => {
238 for (int ii = 0; ii < itemsPerWriter; ii++) {
239 queue.Enqueue(1);
240 }
241 return 1;
242 })
243 .Anyway(() => Interlocked.Decrement(ref writers));
244 }
245
246 for (int i = 0; i < 10; i++) {
247 Interlocked.Increment(ref readers);
248 AsyncPool
249 .InvokeNewThread(() => {
250 int t;
251 do {
252 while (queue.TryDequeue(out t))
253 Interlocked.Add(ref total, t);
254 } while (writers > 0);
255 return 1;
256 })
257 .Anyway(() => {
258 Interlocked.Decrement(ref readers);
259 if (readers == 0)
260 stop.Set();
261 });
262 }
263
264 stop.WaitOne();
265
266 Assert.AreEqual(itemsPerWriter * writersCount, total);
267 }
268
269 [TestMethod]
270 public void ParallelMapTest() {
271
272 const int count = 100000;
273
274 var args = new double[count];
275 var rand = new Random();
276
277 for (int i = 0; i < count; i++)
278 args[i] = rand.NextDouble();
279
280 var t = Environment.TickCount;
281 var res = args.ParallelMap(x => Math.Sin(x*x), 4).Join();
282
283 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
284
285 t = Environment.TickCount;
286 for (int i = 0; i < count; i++)
287 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
288 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
289 }
290
291 [TestMethod]
292 public void ChainedMapTest() {
293
294 using (var pool = new WorkerPool(0,100,100)) {
295 const int count = 10000;
296
297 var args = new double[count];
298 var rand = new Random();
299
300 for (int i = 0; i < count; i++)
301 args[i] = rand.NextDouble();
302
303 var t = Environment.TickCount;
304 var res = args
305 .ChainedMap(
306 // Analysis disable once AccessToDisposedClosure
307 x => pool.Invoke(
308 () => Math.Sin(x * x)
309 ),
310 4
311 )
312 .Join();
313
314 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
315
316 t = Environment.TickCount;
317 for (int i = 0; i < count; i++)
318 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
319 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
320 Console.WriteLine("Max workers: {0}", pool.MaxRunningThreads);
321 }
322 }
323
324 [TestMethod]
325 public void ParallelForEachTest() {
326
327 const int count = 100000;
328
329 var args = new int[count];
330 var rand = new Random();
331
332 for (int i = 0; i < count; i++)
333 args[i] = (int)(rand.NextDouble() * 100);
334
335 int result = 0;
336
337 var t = Environment.TickCount;
338 args.ParallelForEach(x => Interlocked.Add(ref result, x), 4).Join();
339
340 Console.WriteLine("Iteration complete in {0} ms, result: {1}", Environment.TickCount - t, result);
341
342 int result2 = 0;
343
344 t = Environment.TickCount;
345 for (int i = 0; i < count; i++)
346 result2 += args[i];
347 Assert.AreEqual(result2, result);
348 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
349 }
350
351 [TestMethod]
352 public void ComplexCase1Test() {
353 var flags = new bool[3];
354
355 // op1 (aync 200ms) => op2 (async 200ms) => op3 (sync map)
356
357 var step1 = PromiseHelper
358 .Sleep(200, "Alan")
359 .Cancelled(() => flags[0] = true);
360 var p = step1
361 .Chain(x =>
362 PromiseHelper
363 .Sleep(200, "Hi, " + x)
364 .Then(y => y)
365 .Cancelled(() => flags[1] = true)
366 )
367 .Cancelled(() => flags[2] = true);
368 step1.Join();
369 p.Cancel();
370 try {
371 Assert.AreEqual(p.Join(), "Hi, Alan");
372 Assert.Fail("Shouldn't get here");
373 } catch (OperationCanceledException) {
374 }
375
376 Assert.IsFalse(flags[0]);
377 Assert.IsTrue(flags[1]);
378 Assert.IsTrue(flags[2]);
379 }
380
381 [TestMethod]
382 public void ChainedCancel1Test() {
383 // при отмене сцепленной асинхронной операции все обещание должно
384 // завершаться ошибкой OperationCanceledException
385 var p = PromiseHelper
386 .Sleep(1, "Hi, HAL!")
387 .Then(x => {
388 // запускаем две асинхронные операции
389 var result = PromiseHelper.Sleep(1000, "HEM ENABLED!!!");
390 // вторая операция отменяет первую до завершения
391 PromiseHelper
392 .Sleep(100, "HAL, STOP!")
393 .Then(result.Cancel);
394 return result;
395 });
396 try {
397 p.Join();
398 } catch (TargetInvocationException err) {
399 Assert.IsTrue(err.InnerException is OperationCanceledException);
400 }
401 }
402
403 [TestMethod]
404 public void ChainedCancel2Test() {
405 // при отмене цепочки обещаний, вложенные операции также должны отменяться
406 var pSurvive = new Promise<bool>();
407 var hemStarted = new ManualResetEvent(false);
408 var p = PromiseHelper
409 .Sleep(1, "Hi, HAL!")
410 .Chain(x => {
411 hemStarted.Set();
412 // запускаем две асинхронные операции
413 var result = PromiseHelper
414 .Sleep(10000, "HEM ENABLED!!!")
415 .Then(s => pSurvive.Resolve(false));
416
417 result
418 .Cancelled(() => pSurvive.Resolve(true));
419
420 return result;
421 });
422
423 hemStarted.WaitOne();
424 p.Cancel();
425
426 try {
427 p.Join();
428 } catch (OperationCanceledException) {
429 Assert.IsTrue(pSurvive.Join());
430 }
431 }
432 }
433 }
434
@@ -1,12 +1,8
1 1 using Implab.Parallels;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 2 using System.Threading;
7 3
8 4 namespace Implab.Test {
9 class PromiseHelper {
5 static class PromiseHelper {
10 6 public static IPromise<T> Sleep<T>(int timeout, T retVal) {
11 7 return AsyncPool.Invoke(() => {
12 8 Thread.Sleep(timeout);
@@ -31,5 +31,4 using System.Runtime.InteropServices;
31 31 //
32 32 // You can specify all the values or you can default the Build and Revision Numbers
33 33 // by using the '*' as shown below:
34 [assembly: AssemblyVersion("1.0.0.0")]
35 [assembly: AssemblyFileVersion("1.0.0.0")]
34 [assembly: AssemblyVersion("0.0.*")]
General Comments 0
You need to be logged in to leave comments. Login now