mirror of https://github.com/oxen-io/session-ios
Update assertions.
* Streamline precompiled headers. * Remove obsolete assertions in Constraints.h.pull/1/head
parent
5e6a93cffb
commit
9b94580dae
@ -1,44 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ExceptionsTest.h"
|
||||
#import "TestUtil.h"
|
||||
|
||||
@implementation ExceptionsTest
|
||||
|
||||
- (void)testContracts {
|
||||
ows_require(1 + 1 == 2);
|
||||
@try {
|
||||
ows_require(1 + 1 == 3);
|
||||
XCTFail(@"");
|
||||
} @catch (BadArgument *ex) {
|
||||
test([[ex reason] hasPrefix:@"require 1 + 1 == 3"]);
|
||||
}
|
||||
|
||||
requireState(1 + 1 == 2);
|
||||
@try {
|
||||
requireState(1 + 1 == 3);
|
||||
XCTFail(@"");
|
||||
} @catch (BadState *ex) {
|
||||
test([[ex reason] hasPrefix:@"required state: 1 + 1 == 3"]);
|
||||
}
|
||||
|
||||
checkOperationDescribe(1 + 1 == 2, @"addition.");
|
||||
@try {
|
||||
checkOperationDescribe(1 + 1 == 3, @"addition.");
|
||||
XCTFail(@"");
|
||||
} @catch (OperationFailed *ex) {
|
||||
test([[ex reason] hasPrefix:@"Operation failed: addition. Expected: 1 + 1 == 3"]);
|
||||
}
|
||||
|
||||
checkOperation(1 + 1 == 2);
|
||||
@try {
|
||||
checkOperation(1 + 1 == 3);
|
||||
XCTFail(@"");
|
||||
} @catch (OperationFailed *ex) {
|
||||
test([[ex reason] hasPrefix:@"Operation failed. Expected: 1 + 1 == 3"]);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -1,8 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
@interface BadArgument : NSException
|
||||
+(BadArgument*) new:(NSString*)reason;
|
||||
+(void)raise:(NSString *)message;
|
||||
@end
|
@ -1,10 +0,0 @@
|
||||
#import "BadArgument.h"
|
||||
|
||||
@implementation BadArgument
|
||||
+(BadArgument*) new:(NSString*)reason {
|
||||
return [[BadArgument alloc] initWithName:@"Invalid Argument" reason:reason userInfo:nil];
|
||||
}
|
||||
+(void)raise:(NSString *)message {
|
||||
[BadArgument raise:@"Invalid Argument" format:@"%@", message];
|
||||
}
|
||||
@end
|
@ -1,7 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
@interface BadState : NSException
|
||||
+(void)raise:(NSString *)message;
|
||||
@end
|
@ -1,11 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BadState.h"
|
||||
|
||||
@implementation BadState
|
||||
+(void)raise:(NSString *)message {
|
||||
[BadState raise:@"Invalid State" format:@"%@", message];
|
||||
}
|
||||
@end
|
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BadArgument.h"
|
||||
#import "BadState.h"
|
||||
#import "OperationFailed.h"
|
||||
#import <CocoaLumberjack/CocoaLumberjack.h>
|
||||
|
||||
/// 'require(X)' is used to indicate parameter-related preconditions that callers must satisfy.
|
||||
/// Failure to satisfy indicates a bug in the caller.
|
||||
#define ows_require(expr) \
|
||||
if (!(expr)) { \
|
||||
NSString *reason = \
|
||||
[NSString stringWithFormat:@"require %@ (in %s at line %d)", (@ #expr), __FILE__, __LINE__]; \
|
||||
OWSLogError(@"%@", reason); \
|
||||
[BadArgument raise:reason]; \
|
||||
};
|
||||
|
||||
/// 'requireState(X)' is used to indicate callee-state-related preconditions that callers must satisfy.
|
||||
/// Failure to satisfy indicates a stateful bug in either the caller or the callee.
|
||||
#define requireState(expr) \
|
||||
if (!(expr)) \
|
||||
[BadState raise:[NSString stringWithFormat:@"required state: %@ (in %s at line %d)", (@ #expr), __FILE__, __LINE__]]
|
||||
|
||||
/// 'checkOperation(X)' is used to throw exceptions if operations fail.
|
||||
/// Failure does not indicate a bug.
|
||||
/// Methods may throw these exceptions for callers to catch as a 'returned error' result.
|
||||
#define checkOperation(expr) \
|
||||
if (!(expr)) { \
|
||||
NSString *reason = [NSString \
|
||||
stringWithFormat:@"Operation failed. Expected: %@(in %s at line %d)", (@ #expr), __FILE__, __LINE__]; \
|
||||
[OperationFailed raise:reason]; \
|
||||
}
|
||||
|
||||
/// 'checkOperationDescribe(X, Desc)' is used to throw exceptions if operations fail, and describe the problem.
|
||||
/// Failure does not indicate a bug.
|
||||
/// Methods may throw these exceptions for callers to catch as a 'returned error' result.
|
||||
#define checkOperationDescribe(expr, desc) \
|
||||
if (!(expr)) \
|
||||
[OperationFailed raise:[NSString stringWithFormat:@"Operation failed: %@ Expected: %@(in %s at line %d)", \
|
||||
(desc), \
|
||||
(@ #expr), \
|
||||
__FILE__, \
|
||||
__LINE__]]
|
@ -1,8 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
@interface OperationFailed : NSException
|
||||
+(OperationFailed*) new:(NSString*)reason;
|
||||
+(void)raise:(NSString *)message;
|
||||
@end
|
@ -1,14 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OperationFailed.h"
|
||||
|
||||
@implementation OperationFailed
|
||||
+(OperationFailed*) new:(NSString*)reason {
|
||||
return [[OperationFailed alloc] initWithName:@"Operation failed" reason:reason userInfo:nil];
|
||||
}
|
||||
+(void)raise:(NSString *)message {
|
||||
[OperationFailed raise:@"Operation failed" format:@"%@", message];
|
||||
}
|
||||
@end
|
Loading…
Reference in New Issue