Skip to content

Commit 125e4fd

Browse files
committed
Fixed tests
1 parent fee7eb5 commit 125e4fd

File tree

3 files changed

+140
-81
lines changed

3 files changed

+140
-81
lines changed

src/EmptyFlow.SciterAPI.UnitTest/SciterAPIHostIntegrationTests.cs

Lines changed: 132 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -889,34 +889,42 @@ public void SciterAPIHost_Completed_CreateValue_Map () {
889889
);
890890
host.CreateMainWindow ( 300, 300 );
891891
host.LoadFile ( "embedded://test.html" );
892-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
892+
string secondMapValueString = "";
893+
string thirdKeyString = "";
894+
IDictionary<string, SciterValue> resultMap = new Dictionary<string, SciterValue> ();
895+
IEnumerable<string> resultMapValues = new List<string> ();
896+
host.AddWindowEventHandler (
897+
new DocumentReadyHandler (
898+
() => {
899+
var map = new Dictionary<string, SciterValue> ();
900+
map.Add ( "first", host.CreateValue ( "First Item" ) );
901+
map.Add ( "second", host.CreateValue ( "Second Item" ) );
902+
map.Add ( "third", host.CreateValue ( "Third Item" ) );
903+
var valueMap = host.CreateValue ( map );
904+
905+
var secondMapValue = host.GetMapItem ( ref valueMap, "second" );
906+
secondMapValueString = host.GetValueString ( ref secondMapValue );
907+
resultMap = host.GetMapItems ( ref valueMap );
908+
var thirdKey = host.GetValueMapKey ( ref valueMap, 2 );
909+
thirdKeyString = host.GetValueString ( ref thirdKey );
910+
resultMapValues = resultMap.Values
911+
.Select ( a => host.GetValueString ( ref a ) )
912+
.ToList ();
913+
914+
host.CloseWindow ( host.MainWindow );
915+
},
916+
host
917+
)
918+
);
893919

894920
//Act
895921
host.Process ();
896922

897923
//Assert
898-
void ProcessCompleted () {
899-
var map = new Dictionary<string, SciterValue> ();
900-
map.Add ( "first", host.CreateValue ( "First Item" ) );
901-
map.Add ( "second", host.CreateValue ( "Second Item" ) );
902-
map.Add ( "third", host.CreateValue ( "Third Item" ) );
903-
var valueMap = host.CreateValue ( map );
904-
905-
var secondMapValue = host.GetMapItem ( ref valueMap, "second" );
906-
var secondMapValueString = host.GetValueString ( ref secondMapValue );
907-
var resultMap = host.GetMapItems ( ref valueMap );
908-
var thirdKey = host.GetValueMapKey ( ref valueMap, 2 );
909-
var thirdKeyString = host.GetValueString ( ref thirdKey );
910-
var resultMapValues = resultMap.Values
911-
.Select ( a => host.GetValueString ( ref a ) )
912-
.ToList ();
913-
914-
host.CloseWindow ( host.MainWindow );
915-
Assert.Equal ( "Second Item", secondMapValueString );
916-
Assert.Equal ( "third", thirdKeyString );
917-
Assert.Equal ( new List<string> { "first", "second", "third" }, resultMap.Keys );
918-
Assert.Equal ( new List<string> { "First Item", "Second Item", "Third Item" }, resultMapValues );
919-
}
924+
Assert.Equal ( "Second Item", secondMapValueString );
925+
Assert.Equal ( "third", thirdKeyString );
926+
Assert.Equal ( new List<string> { "first", "second", "third" }, resultMap.Keys );
927+
Assert.Equal ( new List<string> { "First Item", "Second Item", "Third Item" }, resultMapValues );
920928
}
921929

922930
[Fact, Trait ( "Category", "Integration" )]
@@ -959,20 +967,27 @@ function testFunc() {
959967
);
960968
host.CreateMainWindow ( 300, 300, enableDebug: true );
961969
host.LoadFile ( "embedded://test.html" );
962-
host.AddWindowEventHandler ( new DocumentXCallHandler ( MethodHandled, host ) );
970+
var luherName = "";
971+
int functionResultValue = 0;
972+
host.AddWindowEventHandler (
973+
new DocumentXCallHandler (
974+
( name, arguments ) => {
975+
luherName = name;
976+
var function = arguments.FirstOrDefault ();
977+
var functionResult = host.ValueInvoke ( ref function, null, Enumerable.Empty<SciterValue> () );
978+
functionResultValue = host.GetValueInt32 ( ref functionResult );
979+
host.CloseWindow ( host.MainWindow );
980+
},
981+
host
982+
)
983+
);
963984

964985
//Act
965986
host.Process ();
966987

967988
//Assert
968-
void MethodHandled ( string name, IEnumerable<SciterValue> arguments ) {
969-
var function = arguments.FirstOrDefault ();
970-
var functionResult = host.ValueInvoke ( ref function, null, Enumerable.Empty<SciterValue> () );
971-
var functionResultValue = host.GetValueInt32 ( ref functionResult );
972-
host.CloseWindow ( host.MainWindow );
973-
Assert.Equal ( "luher", name );
974-
Assert.Equal ( 4568, functionResultValue );
975-
}
989+
Assert.Equal ( "luher", luherName );
990+
Assert.Equal ( 4568, functionResultValue );
976991
}
977992

978993
[Fact, Trait ( "Category", "Integration" )]
@@ -1012,20 +1027,28 @@ public void SciterAPIHost_Completed_SetSharedVariable () {
10121027
host.SetSharedVariable ( "globalVariable", ref value );
10131028
host.CreateMainWindow ( 300, 300, enableDebug: true );
10141029
host.LoadFile ( "embedded://test.html" );
1015-
host.AddWindowEventHandler ( new DocumentXCallHandler ( MethodHandled, host ) );
1030+
var nameLuher = "";
1031+
SciterValue globalVariable = new SciterValue ();
1032+
var testValue = "";
1033+
host.AddWindowEventHandler (
1034+
new DocumentXCallHandler (
1035+
( name, arguments ) => {
1036+
nameLuher = name;
1037+
globalVariable = arguments.FirstOrDefault ();
1038+
testValue = host.GetValueString ( ref globalVariable );
1039+
host.CloseWindow ( host.MainWindow );
1040+
},
1041+
host
1042+
)
1043+
);
10161044

10171045
//Act
10181046
host.Process ();
10191047

10201048
//Assert
1021-
void MethodHandled ( string name, IEnumerable<SciterValue> arguments ) {
1022-
var globalVariable = arguments.FirstOrDefault ();
1023-
var testValue = host.GetValueString ( ref globalVariable );
1024-
host.CloseWindow ( host.MainWindow );
1025-
Assert.Equal ( "luher", name );
1026-
Assert.True ( globalVariable.IsString );
1027-
Assert.Equal ( "testvalue", testValue );
1028-
}
1049+
Assert.Equal ( "luher", nameLuher );
1050+
Assert.True ( globalVariable.IsString );
1051+
Assert.Equal ( "testvalue", testValue );
10291052
}
10301053

10311054
[Fact, Trait ( "Category", "Integration" )]
@@ -1036,20 +1059,25 @@ public void SciterAPIHost_Completed_SetMainWindowVariable () {
10361059

10371060
host.CreateMainWindow ( 300, 300, enableDebug: true );
10381061
host.LoadHtml ( "<html><body></body></html>" );
1039-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
1062+
var resultString = "";
1063+
host.AddWindowEventHandler (
1064+
new DocumentReadyHandler (
1065+
() => {
1066+
var result = host.GetMainWindowVariable ( "globalVariable" );
1067+
resultString = host.GetValueString ( ref result );
1068+
host.CloseWindow ( host.MainWindow );
1069+
},
1070+
host
1071+
)
1072+
);
10401073
var value = host.CreateValue ( "testvalue" );
10411074
host.SetMainWindowVariable ( "globalVariable", ref value );
10421075

10431076
//Act
10441077
host.Process ();
10451078

10461079
//Assert
1047-
void ProcessCompleted () {
1048-
var result = host.GetMainWindowVariable ( "globalVariable" );
1049-
var resultString = host.GetValueString ( ref result );
1050-
host.CloseWindow ( host.MainWindow );
1051-
Assert.Equal ( "testvalue", resultString );
1052-
}
1080+
Assert.Equal ( "testvalue", resultString );
10531081
}
10541082

10551083
[Fact, Trait ( "Category", "Integration" )]
@@ -1060,19 +1088,24 @@ public void SciterAPIHost_Completed_SetElementStyleProperty () {
10601088

10611089
host.CreateMainWindow ( 300, 300, enableDebug: true );
10621090
host.LoadHtml ( "<html><body><div></div></body></html>" );
1063-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
1091+
string savedProperty = "";
1092+
host.AddWindowEventHandler (
1093+
new DocumentReadyHandler (
1094+
() => {
1095+
var divElement = host.MakeCssSelector ( "div" ).First ();
1096+
host.SetElementStyleProperty ( divElement, "color", "#ccccff" );
1097+
savedProperty = host.GetElementStyleProperty ( divElement, "color" );
1098+
host.CloseWindow ( host.MainWindow );
1099+
},
1100+
host
1101+
)
1102+
);
10641103

10651104
//Act
10661105
host.Process ();
10671106

10681107
//Assert
1069-
void ProcessCompleted () {
1070-
var divElement = host.MakeCssSelector ( "div" ).First ();
1071-
host.SetElementStyleProperty ( divElement, "color", "#ccccff" );
1072-
var savedProperty = host.GetElementStyleProperty ( divElement, "color" );
1073-
host.CloseWindow ( host.MainWindow );
1074-
Assert.Equal ( "rgb(204,204,255)", savedProperty );
1075-
}
1108+
Assert.Equal ( "#CCCCFF", savedProperty );
10761109
}
10771110

10781111
[Fact, Trait ( "Category", "Integration" )]
@@ -1095,20 +1128,26 @@ public void SciterAPIHost_Completed_MakeCssSelector_InsideElement () {
10951128
</html>
10961129
"""
10971130
);
1098-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
1131+
int allSpans = 0;
1132+
int insideSpans = 0;
1133+
host.AddWindowEventHandler (
1134+
new DocumentReadyHandler (
1135+
() => {
1136+
var divElement = host.MakeCssSelector ( "#insideelement" ).First ();
1137+
allSpans = host.MakeCssSelector ( "span" ).Count ();
1138+
insideSpans = host.MakeCssSelector ( "span", divElement ).Count ();
1139+
host.CloseWindow ( host.MainWindow );
1140+
},
1141+
host
1142+
)
1143+
);
10991144

11001145
//Act
11011146
host.Process ();
11021147

11031148
//Assert
1104-
void ProcessCompleted () {
1105-
var divElement = host.MakeCssSelector ( "#insideelement" ).First ();
1106-
var allSpans = host.MakeCssSelector ( "span" ).Count ();
1107-
var insideSpans = host.MakeCssSelector ( "span", divElement ).Count ();
1108-
host.CloseWindow ( host.MainWindow );
1109-
Assert.Equal ( 3, allSpans );
1110-
Assert.Equal ( 2, insideSpans );
1111-
}
1149+
Assert.Equal ( 3, allSpans );
1150+
Assert.Equal ( 2, insideSpans );
11121151
}
11131152

11141153
[Fact, Trait ( "Category", "Integration" )]
@@ -1126,21 +1165,28 @@ public void SciterAPIHost_Completed_GetWindowSizeAndPosition () {
11261165
</html>
11271166
"""
11281167
);
1129-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
1168+
SciterWindowInfo data = new SciterWindowInfo ( new SciterWindowSize ( 0, 0 ), new SciterWindowPosition ( 0, 0 ) );
1169+
host.AddWindowEventHandler (
1170+
new DocumentReadyHandler (
1171+
() => {
1172+
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
1173+
data = host.GetWindowSizeAndPosition ( host.MainWindow, WindowSizeMode.Client, WindowRelateMode.Monitor, false );
1174+
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
1175+
host.CloseWindow ( host.MainWindow );
1176+
},
1177+
host
1178+
)
1179+
);
11301180

11311181
//Act
11321182
host.Process ();
11331183

11341184
//Assert
1135-
void ProcessCompleted () {
1136-
var data = host.GetWindowSizeAndPosition ( host.MainWindow, WindowSizeMode.Client, WindowRelateMode.Monitor, false );
1137-
host.CloseWindow ( host.MainWindow );
1138-
Assert.NotNull ( data );
1139-
Assert.Equal ( 8, data.Position.X );
1140-
Assert.Equal ( 31, data.Position.Y );
1141-
Assert.Equal ( 284, data.Size.Width );
1142-
Assert.Equal ( 261, data.Size.Height );
1143-
}
1185+
Assert.NotNull ( data );
1186+
Assert.Equal ( 8, data.Position.X );
1187+
Assert.Equal ( 31, data.Position.Y );
1188+
Assert.Equal ( 284, data.Size.Width );
1189+
Assert.Equal ( 261, data.Size.Height );
11441190
}
11451191

11461192
[Fact, Trait ( "Category", "Integration" )]
@@ -1158,17 +1204,22 @@ public void SciterAPIHost_Completed_GetWindowActive () {
11581204
</html>
11591205
"""
11601206
);
1161-
host.AddWindowEventHandler ( new DocumentReadyHandler ( ProcessCompleted, host ) );
1207+
var isActive = false;
1208+
host.AddWindowEventHandler (
1209+
new DocumentReadyHandler (
1210+
() => {
1211+
isActive = host.GetWindowActive ( host.MainWindow );
1212+
host.CloseWindow ( host.MainWindow );
1213+
},
1214+
host
1215+
)
1216+
);
11621217

11631218
//Act
11641219
host.Process ();
11651220

11661221
//Assert
1167-
void ProcessCompleted () {
1168-
var isActive = host.GetWindowActive ( host.MainWindow );
1169-
host.CloseWindow ( host.MainWindow );
1170-
Assert.True ( isActive );
1171-
}
1222+
Assert.True ( isActive );
11721223
}
11731224

11741225
public class AddEventHandlerTestHandler : SciterEventHandler {

src/EmptyFlow.SciterAPI/Client/HostElementAPI.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public int GetElementChildrensCount ( IntPtr element ) {
4141
return (int) count;
4242
}
4343

44+
public nint GetElementChildren ( IntPtr element, int index ) {
45+
var nthChildResult = m_basicApi.SciterGetNthChild ( element, (uint) index, out var nthElement );
46+
if ( nthChildResult != DomResult.SCDOM_OK ) return nint.Zero;
47+
48+
return nthElement;
49+
}
50+
4451
public IEnumerable<nint> GetElementChildrens ( IntPtr element ) {
4552
var domResult = m_basicApi.SciterGetChildrenCount ( element, out var count );
4653
if ( domResult != DomResult.SCDOM_OK ) return [];

src/EmptyFlow.SciterAPI/EmptyFlow.SciterAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
SciterAPIHost.TrueValue global true value
2828
SciterAPIHost.FalseValue global false value
2929
SciterAPIHost.NullValue global null value
30+
SciterAPIHost.GetElementChildren get children by index
3031
</PackageReleaseNotes>
3132
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3233
</PropertyGroup>

0 commit comments

Comments
 (0)