mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/jsqRewriteVsTests'
commit
3065b22bb6
Binary file not shown.
After Width: | Height: | Size: 675 KiB |
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,326 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "ConversationViewItem.h"
|
||||||
|
#import <MobileCoreServices/MobileCoreServices.h>
|
||||||
|
#import <SignalServiceKit/SecurityUtils.h>
|
||||||
|
#import <SignalServiceKit/TSAttachmentStream.h>
|
||||||
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
|
@interface ConversationViewItem (Testing)
|
||||||
|
|
||||||
|
- (SEL)copyActionSelector;
|
||||||
|
- (SEL)saveActionSelector;
|
||||||
|
- (SEL)shareActionSelector;
|
||||||
|
- (SEL)deleteActionSelector;
|
||||||
|
- (SEL)metadataActionSelector;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface ConversationViewItemTest : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ConversationViewItemTest
|
||||||
|
|
||||||
|
- (void)setUp
|
||||||
|
{
|
||||||
|
[super setUp];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown
|
||||||
|
{
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test canPerformAction
|
||||||
|
|
||||||
|
- (NSString *)fakeTextMessageText
|
||||||
|
{
|
||||||
|
return @"abc";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)textViewItem
|
||||||
|
{
|
||||||
|
TSOutgoingMessage *message =
|
||||||
|
[[TSOutgoingMessage alloc] initWithTimestamp:1 inThread:nil messageBody:self.fakeTextMessageText];
|
||||||
|
[message save];
|
||||||
|
ConversationViewItem *viewItem = [[ConversationViewItem alloc] initWithTSInteraction:message isGroupThread:NO];
|
||||||
|
return viewItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)viewItemWithAttachmentMimetype:(NSString *)mimeType filename:(NSString *)filename
|
||||||
|
{
|
||||||
|
OWSAssert(filename.length > 0);
|
||||||
|
|
||||||
|
NSString *resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath];
|
||||||
|
NSString *filePath = [resourcePath stringByAppendingPathComponent:filename];
|
||||||
|
|
||||||
|
OWSAssert([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
|
||||||
|
TSAttachmentStream *attachment = [[TSAttachmentStream alloc] initWithContentType:mimeType sourceFilename:nil];
|
||||||
|
DataSource *dataSource = [DataSourcePath dataSourceWithFilePath:filePath];
|
||||||
|
BOOL success = [attachment writeDataSource:dataSource];
|
||||||
|
OWSAssert(success);
|
||||||
|
[attachment save];
|
||||||
|
NSMutableArray<NSString *> *attachmentIds = [@[
|
||||||
|
attachment.uniqueId,
|
||||||
|
] mutableCopy];
|
||||||
|
TSOutgoingMessage *message =
|
||||||
|
[[TSOutgoingMessage alloc] initWithTimestamp:1 inThread:nil messageBody:nil attachmentIds:attachmentIds];
|
||||||
|
[message save];
|
||||||
|
ConversationViewItem *viewItem = [[ConversationViewItem alloc] initWithTSInteraction:message isGroupThread:NO];
|
||||||
|
return viewItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)stillImageViewItem
|
||||||
|
{
|
||||||
|
return [self viewItemWithAttachmentMimetype:@"image/jpeg" filename:@"test-jpg.jpg"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)animatedImageViewItem
|
||||||
|
{
|
||||||
|
return [self viewItemWithAttachmentMimetype:@"image/gif" filename:@"test-gif.gif"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)videoViewItem
|
||||||
|
{
|
||||||
|
return [self viewItemWithAttachmentMimetype:@"video/mp4" filename:@"test-mp4.mp4"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ConversationViewItem *)audioViewItem
|
||||||
|
{
|
||||||
|
return [self viewItemWithAttachmentMimetype:@"audio/mp3" filename:@"test-mp3.mp3"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCanPerformEditingActionWithNonMediaMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.textViewItem;
|
||||||
|
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.copyActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:viewItem.saveActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.shareActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.deleteActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.metadataActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:@selector(unknownAction:)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCanPerformEditingActionWithPhotoMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.stillImageViewItem;
|
||||||
|
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.copyActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.saveActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.shareActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.deleteActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.metadataActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:@selector(unknownAction:)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCanPerformEditingActionWithAnimatedMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.animatedImageViewItem;
|
||||||
|
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.copyActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.saveActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.shareActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.deleteActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.metadataActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:@selector(unknownAction:)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCanPerformEditingActionWithVideoMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.videoViewItem;
|
||||||
|
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.copyActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.saveActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.shareActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.deleteActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.metadataActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:@selector(unknownAction:)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCanPerformEditingActionWithAudioMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.audioViewItem;
|
||||||
|
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.copyActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:viewItem.saveActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.shareActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.deleteActionSelector]);
|
||||||
|
XCTAssertTrue([viewItem canPerformAction:viewItem.metadataActionSelector]);
|
||||||
|
XCTAssertFalse([viewItem canPerformAction:@selector(unknownAction:)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Delete
|
||||||
|
|
||||||
|
- (void)testPerformDeleteEditingActionWithNonMediaMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.textViewItem;
|
||||||
|
|
||||||
|
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
[viewItem deleteAction];
|
||||||
|
XCTAssertNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformDeleteActionWithPhotoMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.stillImageViewItem;
|
||||||
|
|
||||||
|
XCTAssertEqual((NSUInteger)1, ((TSMessage *)viewItem.interaction).attachmentIds.count);
|
||||||
|
NSString *_Nullable attachmentId = ((TSMessage *)viewItem.interaction).attachmentIds.firstObject;
|
||||||
|
XCTAssertNotNil(attachmentId);
|
||||||
|
TSAttachment *_Nullable attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId];
|
||||||
|
XCTAssertTrue([attachment isKindOfClass:[TSAttachmentStream class]]);
|
||||||
|
TSAttachmentStream *_Nullable attachmentStream = (TSAttachmentStream *)attachment;
|
||||||
|
NSString *_Nullable filePath = attachmentStream.filePath;
|
||||||
|
XCTAssertNotNil(filePath);
|
||||||
|
|
||||||
|
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNotNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
[viewItem deleteAction];
|
||||||
|
XCTAssertNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformDeleteEditingActionWithAnimatedMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.animatedImageViewItem;
|
||||||
|
|
||||||
|
XCTAssertEqual((NSUInteger)1, ((TSMessage *)viewItem.interaction).attachmentIds.count);
|
||||||
|
NSString *_Nullable attachmentId = ((TSMessage *)viewItem.interaction).attachmentIds.firstObject;
|
||||||
|
XCTAssertNotNil(attachmentId);
|
||||||
|
TSAttachment *_Nullable attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId];
|
||||||
|
XCTAssertTrue([attachment isKindOfClass:[TSAttachmentStream class]]);
|
||||||
|
TSAttachmentStream *_Nullable attachmentStream = (TSAttachmentStream *)attachment;
|
||||||
|
NSString *_Nullable filePath = attachmentStream.filePath;
|
||||||
|
XCTAssertNotNil(filePath);
|
||||||
|
|
||||||
|
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNotNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
[viewItem deleteAction];
|
||||||
|
XCTAssertNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformDeleteEditingActionWithVideoMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.videoViewItem;
|
||||||
|
|
||||||
|
XCTAssertEqual((NSUInteger)1, ((TSMessage *)viewItem.interaction).attachmentIds.count);
|
||||||
|
NSString *_Nullable attachmentId = ((TSMessage *)viewItem.interaction).attachmentIds.firstObject;
|
||||||
|
XCTAssertNotNil(attachmentId);
|
||||||
|
TSAttachment *_Nullable attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId];
|
||||||
|
XCTAssertTrue([attachment isKindOfClass:[TSAttachmentStream class]]);
|
||||||
|
TSAttachmentStream *_Nullable attachmentStream = (TSAttachmentStream *)attachment;
|
||||||
|
NSString *_Nullable filePath = attachmentStream.filePath;
|
||||||
|
XCTAssertNotNil(filePath);
|
||||||
|
|
||||||
|
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNotNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
[viewItem deleteAction];
|
||||||
|
XCTAssertNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformDeleteEditingActionWithAudioMessage
|
||||||
|
{
|
||||||
|
ConversationViewItem *viewItem = self.audioViewItem;
|
||||||
|
|
||||||
|
XCTAssertEqual((NSUInteger)1, ((TSMessage *)viewItem.interaction).attachmentIds.count);
|
||||||
|
NSString *_Nullable attachmentId = ((TSMessage *)viewItem.interaction).attachmentIds.firstObject;
|
||||||
|
XCTAssertNotNil(attachmentId);
|
||||||
|
TSAttachment *_Nullable attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId];
|
||||||
|
XCTAssertTrue([attachment isKindOfClass:[TSAttachmentStream class]]);
|
||||||
|
TSAttachmentStream *_Nullable attachmentStream = (TSAttachmentStream *)attachment;
|
||||||
|
NSString *_Nullable filePath = attachmentStream.filePath;
|
||||||
|
XCTAssertNotNil(filePath);
|
||||||
|
|
||||||
|
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNotNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
[viewItem deleteAction];
|
||||||
|
XCTAssertNil([TSMessage fetchObjectWithUniqueID:viewItem.interaction.uniqueId]);
|
||||||
|
XCTAssertNil([TSAttachment fetchObjectWithUniqueID:attachmentId]);
|
||||||
|
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Copy
|
||||||
|
|
||||||
|
- (void)testPerformCopyEditingActionWithNonMediaMessage
|
||||||
|
{
|
||||||
|
// Reset the pasteboard.
|
||||||
|
UIPasteboard.generalPasteboard.items = @[];
|
||||||
|
XCTAssertNil(UIPasteboard.generalPasteboard.string);
|
||||||
|
|
||||||
|
ConversationViewItem *viewItem = self.textViewItem;
|
||||||
|
[viewItem copyAction];
|
||||||
|
XCTAssertEqualObjects(self.fakeTextMessageText, UIPasteboard.generalPasteboard.string);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformCopyEditingActionWithStillImageMessage
|
||||||
|
{
|
||||||
|
// Reset the pasteboard.
|
||||||
|
UIPasteboard.generalPasteboard.items = @[];
|
||||||
|
XCTAssertNil(UIPasteboard.generalPasteboard.image);
|
||||||
|
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeJPEG]);
|
||||||
|
|
||||||
|
ConversationViewItem *viewItem = self.stillImageViewItem;
|
||||||
|
[viewItem copyAction];
|
||||||
|
NSData *_Nullable copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeJPEG];
|
||||||
|
XCTAssertTrue(copiedData.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformCopyEditingActionWithAnimatedImageMessage
|
||||||
|
{
|
||||||
|
// Reset the pasteboard.
|
||||||
|
UIPasteboard.generalPasteboard.items = @[];
|
||||||
|
XCTAssertNil(UIPasteboard.generalPasteboard.image);
|
||||||
|
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeGIF]);
|
||||||
|
|
||||||
|
ConversationViewItem *viewItem = self.animatedImageViewItem;
|
||||||
|
[viewItem copyAction];
|
||||||
|
NSData *_Nullable copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeGIF];
|
||||||
|
XCTAssertTrue(copiedData.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformCopyEditingActionWithVideoMessage
|
||||||
|
{
|
||||||
|
// Reset the pasteboard.
|
||||||
|
UIPasteboard.generalPasteboard.items = @[];
|
||||||
|
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMPEG4]);
|
||||||
|
|
||||||
|
ConversationViewItem *viewItem = self.videoViewItem;
|
||||||
|
[viewItem copyAction];
|
||||||
|
NSData *_Nullable copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMPEG4];
|
||||||
|
XCTAssertTrue(copiedData.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformCopyEditingActionWithMp3AudioMessage
|
||||||
|
{
|
||||||
|
// Reset the pasteboard.
|
||||||
|
UIPasteboard.generalPasteboard.items = @[];
|
||||||
|
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMP3]);
|
||||||
|
|
||||||
|
ConversationViewItem *viewItem = self.audioViewItem;
|
||||||
|
[viewItem copyAction];
|
||||||
|
NSData *_Nullable copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMP3];
|
||||||
|
XCTAssertTrue(copiedData.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)unknownAction:(id)sender
|
||||||
|
{
|
||||||
|
// It's easier to create this stub method than to suppress the "unknown selector" build warnings.
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -1,335 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSAttachmentStream.h"
|
|
||||||
#import "TSOutgoingMessage.h"
|
|
||||||
#import <MobileCoreServices/MobileCoreServices.h>
|
|
||||||
#import <XCTest/XCTest.h>
|
|
||||||
|
|
||||||
@interface TSMessageAdapter (Testing)
|
|
||||||
|
|
||||||
// expose some private setters for ease of testing setup
|
|
||||||
@property (nonatomic, retain) NSString *messageBody;
|
|
||||||
@property JSQMediaItem *mediaItem;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface TSMessageAdapterTest : XCTestCase
|
|
||||||
|
|
||||||
@property TSMessageAdapter *messageAdapter;
|
|
||||||
@property TSOutgoingMessage *message;
|
|
||||||
@property (readonly) NSData *fakeAudioData;
|
|
||||||
@property (readonly) NSData *fakeImageData;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation TSMessageAdapterTest
|
|
||||||
|
|
||||||
- (NSData *)fakeAudioData
|
|
||||||
{
|
|
||||||
NSString *fakeAudioString = @"QmxhY2tiaXJkIFJhdW0gRG90IE1QMw==";
|
|
||||||
return [[NSData alloc] initWithBase64EncodedString:fakeAudioString options:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSData *)fakeVideoData
|
|
||||||
{
|
|
||||||
NSString *fakeVideoString = @"RmFrZSBWaWRlbyBEYXRh";
|
|
||||||
return [[NSData alloc] initWithBase64EncodedString:fakeVideoString options:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSData *)fakeImageData
|
|
||||||
{
|
|
||||||
NSString *fakeString = @"RmFrZUltYWdlRGF0YQ==";
|
|
||||||
return [[NSData alloc] initWithBase64EncodedString:fakeString options:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setUp
|
|
||||||
{
|
|
||||||
[super setUp];
|
|
||||||
|
|
||||||
self.message = [[TSOutgoingMessage alloc] initWithTimestamp:1 inThread:nil messageBody:nil];
|
|
||||||
[self.message save];
|
|
||||||
|
|
||||||
self.messageAdapter = [TSMessageAdapter new];
|
|
||||||
self.messageAdapter.interaction = self.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)tearDown
|
|
||||||
{
|
|
||||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
||||||
[super tearDown];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test canPerformAction
|
|
||||||
|
|
||||||
- (void)testCanPerformEditingActionWithNonMediaMessage
|
|
||||||
{
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(delete:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(copy:)]);
|
|
||||||
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:NSSelectorFromString(@"save:")]);
|
|
||||||
|
|
||||||
//e.g. any other unsupported action
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:@selector(paste:)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCanPerformEditingActionWithPhotoMessage
|
|
||||||
{
|
|
||||||
self.messageAdapter.mediaItem = [[TSPhotoAdapter alloc] init];
|
|
||||||
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(delete:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(copy:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:NSSelectorFromString(@"save:")]);
|
|
||||||
|
|
||||||
// e.g. any other unsupported action
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:@selector(paste:)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCanPerformEditingActionWithAnimatedMessage
|
|
||||||
{
|
|
||||||
self.messageAdapter.mediaItem = [[TSAnimatedAdapter alloc] init];
|
|
||||||
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(delete:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(copy:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:NSSelectorFromString(@"save:")]);
|
|
||||||
|
|
||||||
// e.g. any other unsupported action
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:@selector(paste:)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCanPerformEditingActionWithVideoMessage
|
|
||||||
{
|
|
||||||
TSAttachmentStream *videoAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"video/mp4" sourceFilename:nil];
|
|
||||||
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:videoAttachment incoming:NO];
|
|
||||||
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(delete:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(copy:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:NSSelectorFromString(@"save:")]);
|
|
||||||
|
|
||||||
// e.g. any other unsupported action
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:@selector(paste:)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCanPerformEditingActionWithAudioMessage
|
|
||||||
{
|
|
||||||
TSAttachmentStream *audioAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:audioAttachment incoming:NO];
|
|
||||||
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(delete:)]);
|
|
||||||
XCTAssertTrue([self.messageAdapter canPerformEditingAction:@selector(copy:)]);
|
|
||||||
|
|
||||||
//e.g. Can't save an audio attachment at this time.
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:NSSelectorFromString(@"save:")]);
|
|
||||||
|
|
||||||
//e.g. any other unsupported action
|
|
||||||
XCTAssertFalse([self.messageAdapter canPerformEditingAction:@selector(paste:)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Delete
|
|
||||||
|
|
||||||
- (void)testPerformDeleteEditingActionWithNonMediaMessage
|
|
||||||
{
|
|
||||||
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
[self.messageAdapter performEditingAction:@selector(delete:)];
|
|
||||||
XCTAssertNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformDeleteActionWithPhotoMessage
|
|
||||||
{
|
|
||||||
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
|
|
||||||
self.messageAdapter.mediaItem = [[TSPhotoAdapter alloc] init];
|
|
||||||
[self.messageAdapter performEditingAction:@selector(delete:)];
|
|
||||||
XCTAssertNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
// TODO assert files are deleted
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformDeleteEditingActionWithAnimatedMessage
|
|
||||||
{
|
|
||||||
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
|
|
||||||
self.messageAdapter.mediaItem = [[TSAnimatedAdapter alloc] init];
|
|
||||||
[self.messageAdapter performEditingAction:@selector(delete:)];
|
|
||||||
XCTAssertNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
// TODO assert files are deleted
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformDeleteEditingActionWithVideoMessage
|
|
||||||
{
|
|
||||||
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *videoAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"video/mp4" sourceFilename:nil];
|
|
||||||
[videoAttachment writeData:[NSData new] error:&error];
|
|
||||||
[videoAttachment save];
|
|
||||||
|
|
||||||
[self.message.attachmentIds addObject:videoAttachment.uniqueId];
|
|
||||||
[self.message save];
|
|
||||||
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:videoAttachment incoming:NO];
|
|
||||||
|
|
||||||
// Sanity Check
|
|
||||||
XCTAssert([[NSFileManager defaultManager] fileExistsAtPath:videoAttachment.filePath]);
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(delete:)];
|
|
||||||
XCTAssertNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:videoAttachment.filePath]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformDeleteEditingActionWithAudioMessage
|
|
||||||
{
|
|
||||||
XCTAssertNotNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *audioAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
|
|
||||||
[audioAttachment writeData:[NSData new] error:&error];
|
|
||||||
[audioAttachment save];
|
|
||||||
|
|
||||||
[self.message.attachmentIds addObject:audioAttachment.uniqueId];
|
|
||||||
[self.message save];
|
|
||||||
|
|
||||||
// Sanity Check
|
|
||||||
XCTAssertNil(error);
|
|
||||||
XCTAssert([[NSFileManager defaultManager] fileExistsAtPath:audioAttachment.filePath]);
|
|
||||||
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:audioAttachment incoming:NO];
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(delete:)];
|
|
||||||
XCTAssertNil([TSMessage fetchObjectWithUniqueID:self.message.uniqueId]);
|
|
||||||
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:audioAttachment.filePath]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Copy
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithNonMediaMessage
|
|
||||||
{
|
|
||||||
self.messageAdapter.messageBody = @"My message text";
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
XCTAssertEqualObjects(@"My message text", UIPasteboard.generalPasteboard.string);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithPhotoMessage
|
|
||||||
{
|
|
||||||
// reset the paste board for clean slate test
|
|
||||||
UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
XCTAssertNil(UIPasteboard.generalPasteboard.image);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *attachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
|
|
||||||
[attachment writeData:self.fakeAudioData error:&error];
|
|
||||||
[attachment save];
|
|
||||||
|
|
||||||
// Sanity Check
|
|
||||||
XCTAssertNil(error);
|
|
||||||
XCTAssert([[NSFileManager defaultManager] fileExistsAtPath:attachment.filePath]);
|
|
||||||
|
|
||||||
[self.message.attachmentIds addObject:attachment.uniqueId];
|
|
||||||
[self.message save];
|
|
||||||
|
|
||||||
TSPhotoAdapter *photoAdapter = [[TSPhotoAdapter alloc] initWithAttachment:attachment incoming:NO];
|
|
||||||
// assign random image, since photoAdapter expects an image.
|
|
||||||
photoAdapter.image = [UIImage imageNamed:@"savephoto"];
|
|
||||||
self.messageAdapter.mediaItem = photoAdapter;
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
|
|
||||||
NSData *copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeJPEG];
|
|
||||||
XCTAssertEqualObjects(self.fakeAudioData, copiedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithVideoMessage
|
|
||||||
{
|
|
||||||
// reset the paste board for clean slate test
|
|
||||||
UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *videoAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"video/mp4" sourceFilename:nil];
|
|
||||||
[videoAttachment writeData:self.fakeVideoData error:&error];
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:videoAttachment incoming:YES];
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
|
|
||||||
NSData *copiedData = [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMPEG4];
|
|
||||||
XCTAssertEqualObjects(self.fakeVideoData, copiedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithMp3AudioMessage
|
|
||||||
{
|
|
||||||
UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMP3]);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *audioAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
|
|
||||||
[audioAttachment writeData:self.fakeAudioData error:&error];
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:audioAttachment incoming:NO];
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
XCTAssertEqualObjects(self.fakeAudioData, [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMP3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithM4aAudioMessage
|
|
||||||
{
|
|
||||||
UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMPEG4Audio]);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *audioAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"audio/x-m4a" sourceFilename:nil];
|
|
||||||
[audioAttachment writeData:self.fakeAudioData error:&error];
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:audioAttachment incoming:NO];
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
XCTAssertEqualObjects(self.fakeAudioData, [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeMPEG4Audio]);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testPerformCopyEditingActionWithGenericAudioMessage
|
|
||||||
{
|
|
||||||
UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
XCTAssertNil([UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeAudio]);
|
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
TSAttachmentStream *audioAttachment =
|
|
||||||
[[TSAttachmentStream alloc] initWithContentType:@"audio/wav" sourceFilename:nil];
|
|
||||||
[audioAttachment writeData:self.fakeAudioData error:&error];
|
|
||||||
self.messageAdapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:audioAttachment incoming:NO];
|
|
||||||
|
|
||||||
[self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
XCTAssertEqualObjects(self.fakeAudioData, [UIPasteboard.generalPasteboard dataForPasteboardType:(NSString *)kUTTypeAudio]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - We don't currenlty have a good way of testing "copy of an animated message attachment"
|
|
||||||
// We need an attachment with some NSData, which requires getting into the crypto layer,
|
|
||||||
// which is outside of my realm.
|
|
||||||
//
|
|
||||||
// Since you can't currently PASTE images into our version of JSQMessageViewController, I tested this by pasting
|
|
||||||
// into native Messages client, and verifying the result was animated.
|
|
||||||
//
|
|
||||||
//- (void)testPerformCopyActionWithAnimatedMessage
|
|
||||||
//{
|
|
||||||
// // reset the paste board for clean slate test
|
|
||||||
// UIPasteboard.generalPasteboard.items = @[];
|
|
||||||
// XCTAssertNil(UIPasteboard.generalPasteboard.image);
|
|
||||||
//
|
|
||||||
// // "some-animated-gif" doesn't exist yet
|
|
||||||
// NSData *imageData = [[NSData alloc] initWithContentsOfFile:@"some-animated-gif"];
|
|
||||||
// //TODO build attachment with imageData
|
|
||||||
// TSAttachmentStream animatedAttachement = [[TSAttachmentStream alloc] initWithIdentifier:@"test-animated-attachment-id" data:imageDatq key:@"TODO" contentType:@"image/gif"];
|
|
||||||
// TSAnimatedAdapter *animatedAdapter = [[TSAnimatedAdapter alloc] initWithAttachment:animatedAttachment];
|
|
||||||
// animatedAdapter.image = image;
|
|
||||||
// self.messageAdapter.mediaItem = animatedAdapter;
|
|
||||||
// [self.messageAdapter performEditingAction:@selector(copy:)];
|
|
||||||
//
|
|
||||||
// // TODO XCTAssert that image is copied as a GIF (e.g. not convereted to a PNG, etc.)
|
|
||||||
// // We want to be sure that we can copy/paste an animated GIF from
|
|
||||||
// // one thread to the other, and ensure it's still animated.
|
|
||||||
//}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,5 +0,0 @@
|
|||||||
#import <XCTest/XCTest.h>
|
|
||||||
|
|
||||||
@interface QueueTest : XCTestCase
|
|
||||||
|
|
||||||
@end
|
|
@ -1,31 +0,0 @@
|
|||||||
#import "Queue.h"
|
|
||||||
#import "QueueTest.h"
|
|
||||||
#import "TestUtil.h"
|
|
||||||
|
|
||||||
@implementation QueueTest
|
|
||||||
|
|
||||||
- (void)testQueue {
|
|
||||||
Queue *q = [Queue new];
|
|
||||||
test(q.count == 0);
|
|
||||||
testThrows(q.peek);
|
|
||||||
testThrows([q dequeue]);
|
|
||||||
|
|
||||||
[q enqueue:@5];
|
|
||||||
test(q.count == 1);
|
|
||||||
test([q.peek isEqualToNumber:@5]);
|
|
||||||
|
|
||||||
[q enqueue:@23];
|
|
||||||
test(q.count == 2);
|
|
||||||
test([q.peek isEqualToNumber:@5]);
|
|
||||||
|
|
||||||
test([[q dequeue] isEqualToNumber:@5]);
|
|
||||||
test(q.count == 1);
|
|
||||||
test([q.peek isEqualToNumber:@23]);
|
|
||||||
|
|
||||||
test([[q dequeue] isEqualToNumber:@23]);
|
|
||||||
test(q.count == 0);
|
|
||||||
testThrows(q.peek);
|
|
||||||
testThrows([q dequeue]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
Loading…
Reference in New Issue