mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
5.6 KiB
Matlab
147 lines
5.6 KiB
Matlab
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
9 years ago
|
|
||
9 years ago
|
#import "NSDate+millisecondTimeStamp.h"
|
||
9 years ago
|
#import "TSAttachmentStream.h"
|
||
9 years ago
|
#import "TSMessage.h"
|
||
9 years ago
|
#import "TSThread.h"
|
||
9 years ago
|
|
||
|
#import <XCTest/XCTest.h>
|
||
|
|
||
9 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
9 years ago
|
@interface TSMessageTest : XCTestCase
|
||
|
|
||
9 years ago
|
@property TSThread *thread;
|
||
|
|
||
9 years ago
|
@end
|
||
|
|
||
|
@implementation TSMessageTest
|
||
|
|
||
|
- (void)setUp {
|
||
|
[super setUp];
|
||
9 years ago
|
self.thread = [[TSThread alloc] init];
|
||
9 years ago
|
}
|
||
|
|
||
|
- (void)tearDown {
|
||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||
|
[super tearDown];
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testExpiresAtWithoutStartedTimer
|
||
|
{
|
||
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
|
inThread:self.thread
|
||
|
messageBody:@"foo"
|
||
|
attachmentIds:@[]
|
||
|
expiresInSeconds:100];
|
||
|
XCTAssertEqual(0, message.expiresAt);
|
||
|
}
|
||
|
|
||
|
- (void)testExpiresAtWithStartedTimer
|
||
|
{
|
||
|
uint64_t now = [NSDate ows_millisecondTimeStamp];
|
||
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
|
inThread:self.thread
|
||
|
messageBody:@"foo"
|
||
|
attachmentIds:@[]
|
||
|
expiresInSeconds:10
|
||
|
expireStartedAt:now];
|
||
|
XCTAssertEqual(now + 10000, message.expiresAt);
|
||
|
}
|
||
|
|
||
|
- (void)testDescription
|
||
|
{
|
||
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:self.thread messageBody:@"My message body"];
|
||
9 years ago
|
XCTAssertEqualObjects(@"My message body", [message description]);
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithBogusAttachmentId
|
||
|
{
|
||
9 years ago
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
9 years ago
|
inThread:self.thread
|
||
9 years ago
|
messageBody:@"My message body"
|
||
|
attachmentIds:@[ @"fake-attachment-id" ]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"UNKNOWN_ATTACHMENT_LABEL", actualDescription);
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithEmptyAttachments
|
||
|
{
|
||
9 years ago
|
TSMessage *message =
|
||
9 years ago
|
[[TSMessage alloc] initWithTimestamp:1 inThread:self.thread messageBody:@"My message body" attachmentIds:@[]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"My message body", actualDescription);
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithPhotoAttachmentId
|
||
|
{
|
||
8 years ago
|
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
|
||
9 years ago
|
[attachment save];
|
||
|
|
||
9 years ago
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
9 years ago
|
inThread:self.thread
|
||
9 years ago
|
messageBody:@"My message body"
|
||
9 years ago
|
attachmentIds:@[ attachment.uniqueId ]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"📷 ATTACHMENT", actualDescription);
|
||
|
}
|
||
|
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithVideoAttachmentId
|
||
|
{
|
||
8 years ago
|
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"video/mp4" sourceFilename:nil];
|
||
9 years ago
|
[attachment save];
|
||
|
|
||
9 years ago
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
9 years ago
|
inThread:self.thread
|
||
9 years ago
|
messageBody:@"My message body"
|
||
9 years ago
|
attachmentIds:@[ attachment.uniqueId ]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"📽 ATTACHMENT", actualDescription);
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithAudioAttachmentId
|
||
|
{
|
||
8 years ago
|
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:@"some-file.mp3"];
|
||
9 years ago
|
[attachment save];
|
||
|
|
||
9 years ago
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
9 years ago
|
inThread:self.thread
|
||
9 years ago
|
messageBody:@"My message body"
|
||
9 years ago
|
attachmentIds:@[ attachment.uniqueId ]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"📻 ATTACHMENT", actualDescription);
|
||
|
}
|
||
|
|
||
8 years ago
|
- (void)testDescriptionWithVoiceMessageAttachmentId
|
||
|
{
|
||
|
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
|
||
|
[attachment save];
|
||
|
|
||
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
|
inThread:self.thread
|
||
|
messageBody:@"My message body"
|
||
|
attachmentIds:@[ attachment.uniqueId ]];
|
||
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"🎤 ATTACHMENT_TYPE_VOICE_MESSAGE", actualDescription);
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)testDescriptionWithUnkownAudioContentType
|
||
|
{
|
||
8 years ago
|
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"non/sense" sourceFilename:nil];
|
||
9 years ago
|
[attachment save];
|
||
|
|
||
9 years ago
|
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||
9 years ago
|
inThread:self.thread
|
||
9 years ago
|
messageBody:@"My message body"
|
||
9 years ago
|
attachmentIds:@[ attachment.uniqueId ]];
|
||
9 years ago
|
NSString *actualDescription = [message description];
|
||
|
XCTAssertEqualObjects(@"ATTACHMENT", actualDescription);
|
||
|
}
|
||
|
|
||
|
@end
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|