-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRAFT: Implement MLHandler and SDP parser tests
- Loading branch information
1 parent
8185b6b
commit fefe9af
Showing
5 changed files
with
633 additions
and
25 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
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,155 @@ | ||
// | ||
// HandlerTest.m | ||
// MonalXMPPUnitTests | ||
// | ||
// Created by admin on 10.02.25. | ||
// Copyright © 2025 monal-im.org. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <XCTest/XCTest.h> | ||
#import <monalxmpp/MLConstants.h> | ||
#import <monalxmpp/MLHandler.h> | ||
|
||
@interface HandlerTest : XCTestCase | ||
//TODO: why is that needed for instance handlers at all? other parts of our code also don't need these declarations. | ||
//TODO: and weird thing: class handlers don't seem to throw a compiler error in here, too. | ||
-(void) MLInstanceHandler_handlerTestInstanceHandler_withArguments:(NSDictionary*) _callerArgs andBoundArguments:(NSDictionary*) _boundArgs; | ||
@end | ||
|
||
@implementation HandlerTest | ||
|
||
-(void) setUp | ||
{ | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
-(void) tearDown | ||
{ | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
-(void) testMonalVoidBlock | ||
{ | ||
id voidblock = NSClassFromString(@"monal_void_block_t"); | ||
XCTAssert([^{} isKindOfClass:voidblock], "void block should be kind of monal_void_block_t"); | ||
} | ||
|
||
-(void) testVoidBlockIsNSObject | ||
{ | ||
XCTAssert([^{} isKindOfClass:[NSObject class]], "void block should be kind of NSObject"); | ||
} | ||
|
||
$$class_handler(handlerTestStringObject, $$ID(NSObject*, dummyObj)) | ||
XCTAssertEqualObjects(dummyObj, @"dummy string", "handler01 should have gotten 'dummy string'"); | ||
$$ | ||
|
||
-(void) testHandlerStringObject | ||
{ | ||
MLHandler* handler = $newHandler([self class], handlerTestStringObject); | ||
$call(handler, $ID(dummyObj, @"dummy string")); | ||
} | ||
|
||
$$class_handler(handlerTestBlockArgument, $$ID(monal_void_block_t, dummyCallback)) | ||
dummyCallback(); | ||
$$ | ||
|
||
-(void) testHandlerBlockArgument | ||
{ | ||
XCTestExpectation* expectation = [self expectationWithDescription:@"handlerTestBlockArgument should call callback block"]; | ||
expectation.expectedFulfillmentCount = 1; | ||
expectation.assertForOverFulfill = YES; | ||
|
||
MLHandler* handler = $newHandler([self class], handlerTestBlockArgument); | ||
$call(handler, $ID(dummyCallback, (^{ | ||
[expectation fulfill]; | ||
}))); | ||
|
||
[self waitForExpectations:@[expectation] timeout:1.0]; | ||
} | ||
|
||
$$instance_handler(handlerTestInstanceHandler, testcase, $$ID(XCTestCase*, testcase), $$ID(XCTestExpectation*, expectation), $$ID(monal_void_block_t, someCallback), $$ID(NSString*, dummyObj)) | ||
Check failure on line 71 in Monal/MonalXMPPUnitTests/HandlerTest.m
|
||
XCTAssertEqualObjects(dummyObj, @"dummy string", "handler03 should have gotten 'dummy string'"); | ||
[self handlerTestInstanceHandlerSubcall:expectation]; | ||
someCallback(); | ||
$$ | ||
|
||
-(void) handlerTestInstanceHandlerSubcall:(XCTestExpectation*) expectation | ||
{ | ||
[expectation fulfill]; | ||
} | ||
|
||
-(void) testHandlerInstanceHandler | ||
{ | ||
XCTestExpectation* expectation = [self expectationWithDescription:@"handlerTestInstanceHandler should fulfill this twice"]; | ||
expectation.expectedFulfillmentCount = 2; | ||
expectation.assertForOverFulfill = YES; | ||
|
||
MLHandler* handler = $newHandler(self, handlerTestInstanceHandler); | ||
$call(handler, $ID(dummyObj, @"dummy string"), $ID(dummyCallback, (^{ | ||
[expectation fulfill]; | ||
}))); | ||
|
||
[self waitForExpectations:@[expectation] timeout:1.0]; | ||
} | ||
|
||
$$class_handler(handlerTestMandatoryArgument, $$ID(monal_void_block_t, dummyCallback)) | ||
dummyCallback(); | ||
$$ | ||
|
||
-(void) testHandlerMandatoryArgument | ||
{ | ||
MLHandler* handler = $newHandler([self class], handlerTestMandatoryArgument); | ||
XCTAssertThrows(($call(handler, $ID(something, @"something"))), "missing mandatory dummyCallback should trigger an exception"); | ||
} | ||
|
||
$$class_handler(handlerTestMissingOptionalArgument, $_ID(NSString*, dummy)) | ||
XCTAssertNil(dummy, "missing optional argument should be nil"); | ||
$$ | ||
|
||
-(void) testHandlerMissingOptionalArgument | ||
{ | ||
MLHandler* handler = $newHandler([self class], handlerTestMissingOptionalArgument, $ID(dummy2, @"dummy2")); | ||
XCTAssertNoThrow(($call(handler, $ID(something, @"something"))), "missing optional dummy argument should not trigger an error"); | ||
} | ||
|
||
$$class_handler(handlerTestGivenOptionalArgument, $_ID(NSString*, dummy)) | ||
XCTAssertNotNil(dummy, "given optional argument should not be nil"); | ||
$$ | ||
|
||
-(void) testHandlerGivenOptionalArgument | ||
{ | ||
MLHandler* handler = $newHandler([self class], handlerTestGivenOptionalArgument, $ID(dummy, @"dummy")); | ||
XCTAssertNoThrow(($call(handler, $ID(something, @"something"))), "giving optional dummy argument should not trigger an error"); | ||
} | ||
|
||
$$class_handler(handlerTestWithInvalidation01, $_ID(NSString*, dummy)) | ||
XCTAssertTrue(NO, "this handler should never be called"); | ||
$$ | ||
$$class_handler(handlerTestWithInvalidationInvalidation01, $_ID(NSString*, something)) | ||
XCTAssertEqualObjects(something, @"something01", "handlerTestWithInvalidationInvalidation01 should have gotten 'something01'"); | ||
$$ | ||
|
||
-(void) testHandlerWithInvalidation01 | ||
{ | ||
MLHandler* handler = $newHandlerWithInvalidation([self class], handlerTestWithInvalidation01, handlerTestWithInvalidationInvalidation01, $ID(dummy2, @"dummy2")); | ||
XCTAssertNoThrow(($invalidate(handler, $ID(something, @"something01"))), "calling an invalidation should not trigger an error"); | ||
XCTAssertThrow(($call(handler, $ID(something, @"something02"))), "calling a handler after its invaidation should trigger an error"); | ||
Check failure on line 137 in Monal/MonalXMPPUnitTests/HandlerTest.m
|
||
XCTAssertThrow(($invalidate(handler, $ID(something, @"something03"))), "calling an invalidation twice should trigger an error"); | ||
} | ||
|
||
$$class_handler(handlerTestWithInvalidation02, $$ID(NSString*, dummy2)) | ||
XCTAssertEqualObjects(dummy2, @"dummy2", "handlerTestWithInvalidation02 should have gotten 'dummy2'"); | ||
$$ | ||
$$class_handler(handlerTestWithInvalidationInvalidation02, $_ID(NSString*, something)) | ||
XCTAssertTrue(NO, "this invalidation should never be called"); | ||
$$ | ||
|
||
-(void) testHandlerWithInvalidation02 | ||
{ | ||
MLHandler* handler = $newHandlerWithInvalidation([self class], handlerTestWithInvalidation02, handlerTestWithInvalidationInvalidation02, $ID(dummy2, @"dummy2")); | ||
XCTAssertNoThrow(($call(handler, $ID(something, @"something01"))), "calling a handler should not trigger an error"); | ||
XCTAssertThrow(($invalidate(handler, $ID(something, @"something02"))), "calling an invalidation after its handler should trigger an error"); | ||
} | ||
|
||
@end |
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,9 @@ | ||
// | ||
// ParserTest.m | ||
// MonalXMPPUnitTests | ||
// | ||
// Created by admin on 10.02.25. | ||
// Copyright © 2025 monal-im.org. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> |
Oops, something went wrong.