This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
ProtobuffsTests.m
53 lines (41 loc) · 1.76 KB
/
ProtobuffsTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <AxolotlKit/AxolotlKit-Swift.h>
#import <AxolotlKit/PreKeyWhisperMessage.h>
#import <AxolotlKit/WhisperMessage.h>
#import <XCTest/XCTest.h>
@interface ProtobuffsTests : XCTestCase
@end
@implementation ProtobuffsTests
- (void)setUp {
[super 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.
[super tearDown];
}
- (void)testProtoSerialization {
NSData *ratchetKey = [@"RatchetKey" dataUsingEncoding:NSUTF8StringEncoding];
NSData *cipherText = [@"CipherText" dataUsingEncoding:NSUTF8StringEncoding];
int counter = 2;
int previousCounter = 1;
SPKProtoTSProtoWhisperMessageBuilder *builder =
[SPKProtoTSProtoWhisperMessage builderWithRatchetKey:ratchetKey
counter:counter
ciphertext:cipherText];
[builder setPreviousCounter:previousCounter];
SPKProtoTSProtoWhisperMessage *message = [builder buildIgnoringErrors];
NSData *serializedMessage = [message serializedDataIgnoringErrors];
NSError *error;
SPKProtoTSProtoWhisperMessage *_Nullable deserialized =
[SPKProtoTSProtoWhisperMessage parseData:serializedMessage error:&error];
XCTAssertNotNil(deserialized);
XCTAssertNil(error);
XCTAssert(deserialized.counter == counter);
XCTAssert(deserialized.previousCounter == previousCounter);
XCTAssert([deserialized.ratchetKey isEqualToData:ratchetKey]);
XCTAssert([deserialized.ciphertext isEqualToData:cipherText]);
}
@end