-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #999 from esl/muc-light-empty-message-handling
MUC Light empty message handling
- Loading branch information
Showing
3 changed files
with
96 additions
and
10 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 |
---|---|---|
|
@@ -31,7 +31,7 @@ - (void)testReceiveMessageWithoutStorage{ | |
[roomLight addDelegate:self delegateQueue:dispatch_get_main_queue()]; | ||
[roomLight activate:streamTest]; | ||
|
||
[streamTest fakeMessageResponse:[self fakeIncomingMessage]]; | ||
[streamTest fakeMessageResponse:[self fakeIncomingMessageWithBody:YES]]; | ||
[self waitForExpectationsWithTimeout:2 handler:^(NSError * _Nullable error) { | ||
if(error){ | ||
XCTFail(@"Expectation Failed with error: %@", error); | ||
|
@@ -53,7 +53,7 @@ - (void)testReceiveMessageWithStorage{ | |
[roomLight addDelegate:self delegateQueue:dispatch_get_main_queue()]; | ||
[roomLight activate:streamTest]; | ||
|
||
[streamTest fakeMessageResponse:[self fakeIncomingMessage]]; | ||
[streamTest fakeMessageResponse:[self fakeIncomingMessageWithBody:YES]]; | ||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
NSManagedObjectContext *context = [storage mainThreadManagedObjectContext]; | ||
|
@@ -135,6 +135,52 @@ - (void)testReceiveAffiliationMessageWithStorage { | |
}]; | ||
} | ||
|
||
- (void)testReceiveMessageWithoutBody { | ||
self.checkDelegate = false; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"receive message without body and correctly stored"]; | ||
|
||
XMPPRoomLightCoreDataStorage *storage = [[XMPPRoomLightCoreDataStorage alloc] initWithDatabaseFilename:@"testReceiveMessageWithoutBody.sqlite" | ||
storeOptions:nil]; | ||
storage.autoRemovePreviousDatabaseFile = YES; | ||
|
||
XMPPMockStream *streamTest = [[XMPPMockStream alloc] init]; | ||
streamTest.myJID = [XMPPJID jidWithString:@"[email protected]"]; | ||
XMPPJID *jid = [XMPPJID jidWithString:@"[email protected]"]; | ||
XMPPRoomLight *roomLight = [[XMPPRoomLight alloc] initWithRoomLightStorage:storage jid:jid roomname:@"test" dispatchQueue:nil]; | ||
roomLight.shouldHandleMemberMessagesWithoutBody = YES; | ||
[roomLight activate:streamTest]; | ||
|
||
[streamTest fakeMessageResponse:[self fakeIncomingMessageWithBody:NO]]; | ||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
NSManagedObjectContext *context = [storage mainThreadManagedObjectContext]; | ||
NSEntityDescription *entity = [NSEntityDescription entityForName:@"XMPPRoomLightMessageCoreDataStorageObject" | ||
inManagedObjectContext:context]; | ||
|
||
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"roomJIDStr = %@", jid.full]; | ||
|
||
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | ||
request.entity = entity; | ||
request.predicate = predicate; | ||
|
||
NSError *error; | ||
XMPPRoomLightMessageCoreDataStorageObject *roomMessage = [[context executeFetchRequest:request error:&error] firstObject]; | ||
XCTAssertNil(error); | ||
XCTAssertEqualObjects(roomMessage.jid.full, @"[email protected]/[email protected]"); | ||
XCTAssertNil(roomMessage.body); | ||
XCTAssertEqualObjects(roomMessage.nickname, @"[email protected]"); | ||
|
||
[expectation fulfill]; | ||
}); | ||
|
||
[self waitForExpectationsWithTimeout:3 handler:^(NSError * _Nullable error) { | ||
if(error){ | ||
XCTFail(@"Expectation Failed with error: %@", error); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)testImportMessage { | ||
self.checkDelegate = false; | ||
|
||
|
@@ -148,7 +194,10 @@ - (void)testImportMessage { | |
XMPPJID *jid = [XMPPJID jidWithString:@"[email protected]"]; | ||
XMPPRoomLight *roomLight = [[XMPPRoomLight alloc] initWithRoomLightStorage:storage jid:jid roomname:@"test" dispatchQueue:nil]; | ||
|
||
[storage importRemoteArchiveMessage:[self fakeIncomingMessage] withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] inRoom:roomLight fromStream:streamTest]; | ||
[storage importRemoteArchiveMessage:[self fakeIncomingMessageWithBody:YES] | ||
withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] | ||
inRoom:roomLight | ||
fromStream:streamTest]; | ||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
NSManagedObjectContext *context = [storage mainThreadManagedObjectContext]; | ||
|
@@ -194,8 +243,14 @@ - (void)testImportMessageUniquing { | |
XMPPJID *jid = [XMPPJID jidWithString:@"[email protected]"]; | ||
XMPPRoomLight *roomLight = [[XMPPRoomLight alloc] initWithRoomLightStorage:storage jid:jid roomname:@"test" dispatchQueue:nil]; | ||
|
||
[storage importRemoteArchiveMessage:[self fakeIncomingMessage] withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] inRoom:roomLight fromStream:streamTest]; | ||
[storage importRemoteArchiveMessage:[self fakeIncomingMessage] withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] inRoom:roomLight fromStream:streamTest]; | ||
[storage importRemoteArchiveMessage:[self fakeIncomingMessageWithBody:YES] | ||
withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] | ||
inRoom:roomLight | ||
fromStream:streamTest]; | ||
[storage importRemoteArchiveMessage:[self fakeIncomingMessageWithBody:YES] | ||
withTimestamp:[NSDate dateWithTimeIntervalSinceReferenceDate:0] | ||
inRoom:roomLight | ||
fromStream:streamTest]; | ||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
NSManagedObjectContext *context = [storage mainThreadManagedObjectContext]; | ||
|
@@ -231,14 +286,16 @@ - (void)xmppRoomLight:(XMPPRoomLight *)sender didReceiveMessage:(XMPPMessage *)m | |
} | ||
} | ||
|
||
- (XMPPMessage *)fakeIncomingMessage{ | ||
- (XMPPMessage *)fakeIncomingMessageWithBody:(BOOL)shouldIncludeBody { | ||
NSMutableString *s = [NSMutableString string]; | ||
[s appendString: @"<message xmlns='jabber:client' \ | ||
from='[email protected]/[email protected]' \ | ||
to='[email protected]' \ | ||
id='C7A969D8-C711-4516-9313-10EA9927B39B' \ | ||
type='groupchat'>"]; | ||
[s appendString: @" <body>Yo! 13</body>'"]; | ||
if (shouldIncludeBody) { | ||
[s appendString: @"<body>Yo! 13</body>'"]; | ||
} | ||
[s appendString: @"</message>"]; | ||
|
||
NSError *error; | ||
|