Skip to content

Commit fefe9af

Browse files
DRAFT: Implement MLHandler and SDP parser tests
1 parent 8185b6b commit fefe9af

File tree

5 files changed

+633
-25
lines changed

5 files changed

+633
-25
lines changed

Monal/Classes/MonalAppDelegate.m

+5-23
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ -(void) runParserTests
166166

167167
-(void) runSDPTests
168168
{
169-
DDLogVerbose(@"SDP2XML: %@", [HelperTools sdp2xml:@"v=0\n\
169+
NSArray<MLXMLNode*>* xmlNodes = [HelperTools sdp2xml:@"v=0\n\
170170
o=- 2005859539484728435 2 IN IP4 127.0.0.1\n\
171171
s=-\n\
172172
t=0 0\n\
@@ -288,29 +288,10 @@ -(void) runSDPTests
288288
a=setup:actpass\n\
289289
a=mid:2\n\
290290
a=sctp-port:5000\n\
291-
a=max-message-size:262144\n" withInitiator:YES]);
292-
}
293-
294-
$$class_handler(handlerTest01, $$ID(NSObject*, dummyObj))
295-
DDLogError(@"HandlerTest01 completed");
296-
$$
291+
a=max-message-size:262144\n" withInitiator:YES];
297292

298-
$$class_handler(handlerTest02, $$ID(monal_void_block_t, dummyCallback))
299-
DDLogError(@"HandlerTest02 completed");
300-
$$
301-
302-
-(void) runHandlerTests
303-
{
304-
DDLogError(@"NSClassFromString: '%@'", NSClassFromString(@"monal_void_block_t"));
305-
306-
if([^{} isKindOfClass:[NSObject class]])
307-
DDLogError(@"isKindOfClass");
308-
309-
MLHandler* handler01 = $newHandler([self class], handlerTest01);
310-
$call(handler01, $ID(dummyObj, [NSString new]));
311-
312-
MLHandler* handler02 = $newHandler([self class], handlerTest02);
313-
$call(handler02, $ID(dummyCallback, ^{}));
293+
DDLogVerbose(@"SDP2XML: %@", xmlNodes);
294+
DDLogDebug(@"XML2SDP: %@", [HelperTools xml2sdp:xmlNodes[2] withInitiator:YES]);
314295
}
315296

316297
-(id) init
@@ -334,6 +315,7 @@ -(id) init
334315
//[self runSDPTests];
335316
//[HelperTools flushLogsWithTimeout:0.250];
336317
//[self runHandlerTests];
318+
//exit(0);
337319
return self;
338320
}
339321

Monal/Monal.xcodeproj/project.pbxproj

+14-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@
7777
26E8462824EABAED00ECE419 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 26E8462A24EABAED00ECE419 /* Main.storyboard */; };
7878
26F9794D1ACAC73A0008E005 /* MLContactCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 26F9794C1ACAC73A0008E005 /* MLContactCell.xib */; };
7979
26FE3BCB1C61A6C3003CC230 /* MLResizingTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 26FE3BCA1C61A6C3003CC230 /* MLResizingTextView.m */; };
80-
341F44662CAF427500AA6C7D /* MLPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 341F44642CAF427500AA6C7D /* MLPromise.h */; settings = {ATTRIBUTES = (Public, ); }; };
81-
341F44672CAF427500AA6C7D /* MLPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F44652CAF427500AA6C7D /* MLPromise.m */; };
8280
340F0CA02D2425A4006224D0 /* MLMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 26611024238F17B20030A4EE /* MLMessage.h */; settings = {ATTRIBUTES = (Public, ); }; };
8381
340F0CA12D2425AA006224D0 /* MLXMPPConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 26611015238F08AC0030A4EE /* MLXMPPConnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
8482
340F0CA22D2425C4006224D0 /* XMPPPresence.h in Headers */ = {isa = PBXBuildFile; fileRef = 264E34591787BAB100BC7BD0 /* XMPPPresence.h */; settings = {ATTRIBUTES = (Public, ); }; };
8583
340F0CA32D2425D2006224D0 /* MLXMPPServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 2661100B238F08820030A4EE /* MLXMPPServer.h */; settings = {ATTRIBUTES = (Public, ); }; };
8684
340F0CA42D2425D9006224D0 /* MLXMPPIdentity.h in Headers */ = {isa = PBXBuildFile; fileRef = 26611010238F08980030A4EE /* MLXMPPIdentity.h */; settings = {ATTRIBUTES = (Public, ); }; };
8785
340F0CA52D2425E1006224D0 /* MLLogFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C15D504824C727CC002F75BB /* MLLogFileManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
8886
340F0CA62D24267B006224D0 /* MLXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 260C51D2177F44AD0039634B /* MLXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
87+
341F44662CAF427500AA6C7D /* MLPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 341F44642CAF427500AA6C7D /* MLPromise.h */; settings = {ATTRIBUTES = (Public, ); }; };
88+
341F44672CAF427500AA6C7D /* MLPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F44652CAF427500AA6C7D /* MLPromise.m */; };
8989
3424B4E72D232BE2009F6503 /* MLContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 26611029238F17CA0030A4EE /* MLContact.h */; settings = {ATTRIBUTES = (Public, ); }; };
9090
3424B4E82D232BE7009F6503 /* DataLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 2601D9A80FBF255D004DB939 /* DataLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
9191
3424B4E92D232BEB009F6503 /* xmpp.h in Headers */ = {isa = PBXBuildFile; fileRef = 260C51CF177F08F50039634B /* xmpp.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -188,6 +188,9 @@
188188
84C1CD502A8C764D007076ED /* SwiftHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C1CD4F2A8C764D007076ED /* SwiftHelpers.swift */; };
189189
84C1CD522A8F617F007076ED /* MLStreamRedirect.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C1CD512A8F617F007076ED /* MLStreamRedirect.m */; };
190190
84C1CD542A8F6196007076ED /* MLStreamRedirect.h in Headers */ = {isa = PBXBuildFile; fileRef = 84C1CD532A8F6196007076ED /* MLStreamRedirect.h */; };
191+
84C6F6032D597FB20015575E /* ParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C6F6022D597FB20015575E /* ParserTest.m */; };
192+
84C6F6052D597FD10015575E /* SDPTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C6F6042D597FD10015575E /* SDPTest.m */; };
193+
84C6F6072D597FF40015575E /* HandlerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C6F6062D597FF40015575E /* HandlerTest.m */; };
191194
84D31CE628653B83006D7926 /* WebRTCClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D31CE528653B83006D7926 /* WebRTCClient.swift */; };
192195
84E231F32C16A9CE00735FB7 /* SVGView in Frameworks */ = {isa = PBXBuildFile; productRef = 84E231F22C16A9CE00735FB7 /* SVGView */; };
193196
84E55E7D2964424E003E191A /* ActiveChatsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 261A6284176C156500059090 /* ActiveChatsViewController.m */; };
@@ -626,6 +629,9 @@
626629
84C1CD4F2A8C764D007076ED /* SwiftHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftHelpers.swift; sourceTree = "<group>"; };
627630
84C1CD512A8F617F007076ED /* MLStreamRedirect.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MLStreamRedirect.m; sourceTree = "<group>"; };
628631
84C1CD532A8F6196007076ED /* MLStreamRedirect.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MLStreamRedirect.h; sourceTree = "<group>"; };
632+
84C6F6022D597FB20015575E /* ParserTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ParserTest.m; sourceTree = "<group>"; };
633+
84C6F6042D597FD10015575E /* SDPTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDPTest.m; sourceTree = "<group>"; };
634+
84C6F6062D597FF40015575E /* HandlerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HandlerTest.m; sourceTree = "<group>"; };
629635
84D31CE528653B83006D7926 /* WebRTCClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebRTCClient.swift; path = Classes/WebRTCClient.swift; sourceTree = SOURCE_ROOT; };
630636
84F194C32C0FE70900F0A994 /* es-AR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-AR"; path = "external/es-AR.lproj/Main.strings"; sourceTree = "<group>"; };
631637
84F194C42C0FE74500F0A994 /* es-AR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-AR"; path = "external/es-AR.lproj/Settings.strings"; sourceTree = "<group>"; };
@@ -1461,6 +1467,9 @@
14611467
C1049188261301530054AC9E /* MonalXMPPUnitTests.swift */,
14621468
C104918A261301530054AC9E /* Info.plist */,
14631469
C1B940E826144AF400E9D290 /* MonalXMPPUnitTests-Bridging-Header.h */,
1470+
84C6F6022D597FB20015575E /* ParserTest.m */,
1471+
84C6F6042D597FD10015575E /* SDPTest.m */,
1472+
84C6F6062D597FF40015575E /* HandlerTest.m */,
14641473
);
14651474
path = MonalXMPPUnitTests;
14661475
sourceTree = "<group>";
@@ -2272,8 +2281,11 @@
22722281
isa = PBXSourcesBuildPhase;
22732282
buildActionMask = 2147483647;
22742283
files = (
2284+
84C6F6072D597FF40015575E /* HandlerTest.m in Sources */,
2285+
84C6F6032D597FB20015575E /* ParserTest.m in Sources */,
22752286
C1049189261301530054AC9E /* MonalXMPPUnitTests.swift in Sources */,
22762287
C1B940EA26144AF500E9D290 /* AESGCMTest.m in Sources */,
2288+
84C6F6052D597FD10015575E /* SDPTest.m in Sources */,
22772289
C1049199261301710054AC9E /* MLCryptoTest.swift in Sources */,
22782290
);
22792291
runOnlyForDeploymentPostprocessing = 0;
+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//
2+
// HandlerTest.m
3+
// MonalXMPPUnitTests
4+
//
5+
// Created by admin on 10.02.25.
6+
// Copyright © 2025 monal-im.org. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <XCTest/XCTest.h>
11+
#import <monalxmpp/MLConstants.h>
12+
#import <monalxmpp/MLHandler.h>
13+
14+
@interface HandlerTest : XCTestCase
15+
//TODO: why is that needed for instance handlers at all? other parts of our code also don't need these declarations.
16+
//TODO: and weird thing: class handlers don't seem to throw a compiler error in here, too.
17+
-(void) MLInstanceHandler_handlerTestInstanceHandler_withArguments:(NSDictionary*) _callerArgs andBoundArguments:(NSDictionary*) _boundArgs;
18+
@end
19+
20+
@implementation HandlerTest
21+
22+
-(void) setUp
23+
{
24+
// Put setup code here. This method is called before the invocation of each test method in the class.
25+
}
26+
27+
-(void) tearDown
28+
{
29+
// Put teardown code here. This method is called after the invocation of each test method in the class.
30+
}
31+
32+
-(void) testMonalVoidBlock
33+
{
34+
id voidblock = NSClassFromString(@"monal_void_block_t");
35+
XCTAssert([^{} isKindOfClass:voidblock], "void block should be kind of monal_void_block_t");
36+
}
37+
38+
-(void) testVoidBlockIsNSObject
39+
{
40+
XCTAssert([^{} isKindOfClass:[NSObject class]], "void block should be kind of NSObject");
41+
}
42+
43+
$$class_handler(handlerTestStringObject, $$ID(NSObject*, dummyObj))
44+
XCTAssertEqualObjects(dummyObj, @"dummy string", "handler01 should have gotten 'dummy string'");
45+
$$
46+
47+
-(void) testHandlerStringObject
48+
{
49+
MLHandler* handler = $newHandler([self class], handlerTestStringObject);
50+
$call(handler, $ID(dummyObj, @"dummy string"));
51+
}
52+
53+
$$class_handler(handlerTestBlockArgument, $$ID(monal_void_block_t, dummyCallback))
54+
dummyCallback();
55+
$$
56+
57+
-(void) testHandlerBlockArgument
58+
{
59+
XCTestExpectation* expectation = [self expectationWithDescription:@"handlerTestBlockArgument should call callback block"];
60+
expectation.expectedFulfillmentCount = 1;
61+
expectation.assertForOverFulfill = YES;
62+
63+
MLHandler* handler = $newHandler([self class], handlerTestBlockArgument);
64+
$call(handler, $ID(dummyCallback, (^{
65+
[expectation fulfill];
66+
})));
67+
68+
[self waitForExpectations:@[expectation] timeout:1.0];
69+
}
70+
71+
$$instance_handler(handlerTestInstanceHandler, testcase, $$ID(XCTestCase*, testcase), $$ID(XCTestExpectation*, expectation), $$ID(monal_void_block_t, someCallback), $$ID(NSString*, dummyObj))
72+
XCTAssertEqualObjects(dummyObj, @"dummy string", "handler03 should have gotten 'dummy string'");
73+
[self handlerTestInstanceHandlerSubcall:expectation];
74+
someCallback();
75+
$$
76+
77+
-(void) handlerTestInstanceHandlerSubcall:(XCTestExpectation*) expectation
78+
{
79+
[expectation fulfill];
80+
}
81+
82+
-(void) testHandlerInstanceHandler
83+
{
84+
XCTestExpectation* expectation = [self expectationWithDescription:@"handlerTestInstanceHandler should fulfill this twice"];
85+
expectation.expectedFulfillmentCount = 2;
86+
expectation.assertForOverFulfill = YES;
87+
88+
MLHandler* handler = $newHandler(self, handlerTestInstanceHandler);
89+
$call(handler, $ID(dummyObj, @"dummy string"), $ID(dummyCallback, (^{
90+
[expectation fulfill];
91+
})));
92+
93+
[self waitForExpectations:@[expectation] timeout:1.0];
94+
}
95+
96+
$$class_handler(handlerTestMandatoryArgument, $$ID(monal_void_block_t, dummyCallback))
97+
dummyCallback();
98+
$$
99+
100+
-(void) testHandlerMandatoryArgument
101+
{
102+
MLHandler* handler = $newHandler([self class], handlerTestMandatoryArgument);
103+
XCTAssertThrows(($call(handler, $ID(something, @"something"))), "missing mandatory dummyCallback should trigger an exception");
104+
}
105+
106+
$$class_handler(handlerTestMissingOptionalArgument, $_ID(NSString*, dummy))
107+
XCTAssertNil(dummy, "missing optional argument should be nil");
108+
$$
109+
110+
-(void) testHandlerMissingOptionalArgument
111+
{
112+
MLHandler* handler = $newHandler([self class], handlerTestMissingOptionalArgument, $ID(dummy2, @"dummy2"));
113+
XCTAssertNoThrow(($call(handler, $ID(something, @"something"))), "missing optional dummy argument should not trigger an error");
114+
}
115+
116+
$$class_handler(handlerTestGivenOptionalArgument, $_ID(NSString*, dummy))
117+
XCTAssertNotNil(dummy, "given optional argument should not be nil");
118+
$$
119+
120+
-(void) testHandlerGivenOptionalArgument
121+
{
122+
MLHandler* handler = $newHandler([self class], handlerTestGivenOptionalArgument, $ID(dummy, @"dummy"));
123+
XCTAssertNoThrow(($call(handler, $ID(something, @"something"))), "giving optional dummy argument should not trigger an error");
124+
}
125+
126+
$$class_handler(handlerTestWithInvalidation01, $_ID(NSString*, dummy))
127+
XCTAssertTrue(NO, "this handler should never be called");
128+
$$
129+
$$class_handler(handlerTestWithInvalidationInvalidation01, $_ID(NSString*, something))
130+
XCTAssertEqualObjects(something, @"something01", "handlerTestWithInvalidationInvalidation01 should have gotten 'something01'");
131+
$$
132+
133+
-(void) testHandlerWithInvalidation01
134+
{
135+
MLHandler* handler = $newHandlerWithInvalidation([self class], handlerTestWithInvalidation01, handlerTestWithInvalidationInvalidation01, $ID(dummy2, @"dummy2"));
136+
XCTAssertNoThrow(($invalidate(handler, $ID(something, @"something01"))), "calling an invalidation should not trigger an error");
137+
XCTAssertThrow(($call(handler, $ID(something, @"something02"))), "calling a handler after its invaidation should trigger an error");
138+
XCTAssertThrow(($invalidate(handler, $ID(something, @"something03"))), "calling an invalidation twice should trigger an error");
139+
}
140+
141+
$$class_handler(handlerTestWithInvalidation02, $$ID(NSString*, dummy2))
142+
XCTAssertEqualObjects(dummy2, @"dummy2", "handlerTestWithInvalidation02 should have gotten 'dummy2'");
143+
$$
144+
$$class_handler(handlerTestWithInvalidationInvalidation02, $_ID(NSString*, something))
145+
XCTAssertTrue(NO, "this invalidation should never be called");
146+
$$
147+
148+
-(void) testHandlerWithInvalidation02
149+
{
150+
MLHandler* handler = $newHandlerWithInvalidation([self class], handlerTestWithInvalidation02, handlerTestWithInvalidationInvalidation02, $ID(dummy2, @"dummy2"));
151+
XCTAssertNoThrow(($call(handler, $ID(something, @"something01"))), "calling a handler should not trigger an error");
152+
XCTAssertThrow(($invalidate(handler, $ID(something, @"something02"))), "calling an invalidation after its handler should trigger an error");
153+
}
154+
155+
@end

Monal/MonalXMPPUnitTests/ParserTest.m

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// ParserTest.m
3+
// MonalXMPPUnitTests
4+
//
5+
// Created by admin on 10.02.25.
6+
// Copyright © 2025 monal-im.org. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>

0 commit comments

Comments
 (0)