Skip to content

Commit

Permalink
Setup integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Nikolskyi committed Jun 2, 2015
2 parents 849c8e9 + 45f1dff commit 3016756
Show file tree
Hide file tree
Showing 93 changed files with 890 additions and 1 deletion.
32 changes: 32 additions & 0 deletions ConnectSDKIntegrationTests/ConnectSDKIntegrationTests-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ConnectSDKIntegrationTests-Prefix.pch
// ConnectSDK
//
// Created by Eugene Nikolskyi on 5/26/15.
// Copyright (c) 2015 LG Electronics. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef ConnectSDK_ConnectSDKIntegrationTests_Prefix_pch
#define ConnectSDK_ConnectSDKIntegrationTests_Prefix_pch

// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#import "ConnectSDKTests-Prefix.pch"

#import <Expecta/Expecta.h>
#import <Specta/Specta.h>

#endif
79 changes: 79 additions & 0 deletions ConnectSDKIntegrationTests/DLNAServiceIntegrationTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// DLNAServiceIntegrationTests.m
// ConnectSDK
//
// Created by Eugene Nikolskyi on 5/26/15.
// Copyright (c) 2015 LG Electronics. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DiscoveryManager.h"
#import "DLNAService.h"
#import "SSDPDiscoveryProvider.h"

#import "EXPMatchers+matchRegex.h"

#pragma mark - Environment-specific constants

static NSString *const kExpectedDeviceName = @"Living Room - Sonos PLAY:1 Media Renderer";
static NSString *const kExpectedIPAddressRegex = @"192\\.168\\.1\\.\\d{1,3}";

#pragma mark -

SpecBegin(DLNAService)

describe(@"ConnectSDK", ^{
it(@"should discover Sonos device in the network", ^{
// the official way to access DiscoveryManager is through the singleton,
// but that's no good for tests
DiscoveryManager *manager = [DiscoveryManager new];
// don't need to save any state information
manager.deviceStore = nil;

// use a custom delegate to avoid showing any UI and get the discovery
// callbacks
id delegateStub = OCMProtocolMock(@protocol(DiscoveryManagerDelegate));
manager.delegate = delegateStub;

// use DLNA service only
[manager registerDeviceService:[DLNAService class]
withDiscovery:[SSDPDiscoveryProvider class]];

// wait for a matching device
waitUntil(^(DoneCallback done) {
void (^deviceVerifier)(ConnectableDevice *) = ^void(ConnectableDevice *device) {
expect(device.address).matchRegex(kExpectedIPAddressRegex);
expect(device.id).notTo.beNil();
expect([device serviceWithName:kConnectSDKDLNAServiceId]).notTo.beNil();
};

OCMStub([delegateStub discoveryManager:manager
didFindDevice:
[OCMArg checkWithBlock:^BOOL(ConnectableDevice *device) {
if ([kExpectedDeviceName isEqualToString:device.friendlyName]) {
deviceVerifier(device);
done();
}

return YES;
}]]);

[manager startDiscovery];
});

[manager stopDiscovery];
});
});

SpecEnd
24 changes: 24 additions & 0 deletions ConnectSDKIntegrationTests/EXPMatchers+matchRegex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// EXPMatchers+matchRegex.h
// ConnectSDK
//
// Created by Eugene Nikolskyi on 5/26/15.
// Copyright (c) 2015 LG Electronics. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Expecta/Expecta.h>

/// Expects a string to fully match the given @c regex.
EXPMatcherInterface(matchRegex, (NSString *regex));
42 changes: 42 additions & 0 deletions ConnectSDKIntegrationTests/EXPMatchers+matchRegex.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// EXPMatchers+matchRegex.m
// ConnectSDK
//
// Created by Eugene Nikolskyi on 5/26/15.
// Copyright (c) 2015 LG Electronics. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "EXPMatchers+matchRegex.h"

EXPMatcherImplementationBegin(matchRegex, (NSString *expected)) {
match(^BOOL {
NSString *string = actual;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:expected
options:0
error:nil];
NSRange wholeRange = NSMakeRange(0, string.length);
NSRange matchedRange = [regex rangeOfFirstMatchInString:string
options:NSMatchingAnchored
range:wholeRange];
return NSEqualRanges(matchedRange, wholeRange);
});

failureMessageForTo(^NSString * {
return [NSString stringWithFormat:
@"expected: a string matching regex %@, got: %@",
expected, actual];
});
}
EXPMatcherImplementationEnd
File renamed without changes.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// EXPRuntimeMatcher.h
// Expecta
//
// Created by Luke Redpath on 26/03/2012.
// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "EXPMatcher.h"
#import "EXPDefines.h"

@interface EXPBlockDefinedMatcher : NSObject <EXPMatcher> {
EXPBoolBlock prerequisiteBlock;
EXPBoolBlock matchBlock;
EXPStringBlock failureMessageForToBlock;
EXPStringBlock failureMessageForNotToBlock;
}

@property(nonatomic, copy) EXPBoolBlock prerequisiteBlock;
@property(nonatomic, copy) EXPBoolBlock matchBlock;
@property(nonatomic, copy) EXPStringBlock failureMessageForToBlock;
@property(nonatomic, copy) EXPStringBlock failureMessageForNotToBlock;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// EXPDefines.h
// Expecta
//
// Created by Luke Redpath on 26/03/2012.
// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
//

#ifndef Expecta_EXPDefines_h
#define Expecta_EXPDefines_h

typedef void (^EXPBasicBlock)();
typedef id (^EXPIdBlock)();
typedef BOOL (^EXPBoolBlock)();
typedef NSString *(^EXPStringBlock)();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#import <Foundation/Foundation.h>
#import "EXPMatcher.h"
#import "EXPDefines.h"

@interface EXPExpect : NSObject {
EXPIdBlock _actualBlock;
id _testCase;
int _lineNumber;
char *_fileName;
BOOL _negative;
BOOL _asynchronous;
NSTimeInterval _timeout;
}

@property(nonatomic, copy) EXPIdBlock actualBlock;
@property(nonatomic, readonly) id actual;
@property(nonatomic, assign) id testCase;
@property(nonatomic) int lineNumber;
@property(nonatomic) const char *fileName;
@property(nonatomic) BOOL negative;
@property(nonatomic) BOOL asynchronous;
@property(nonatomic) NSTimeInterval timeout;

@property(nonatomic, readonly) EXPExpect *to;
@property(nonatomic, readonly) EXPExpect *toNot;
@property(nonatomic, readonly) EXPExpect *notTo;
@property(nonatomic, readonly) EXPExpect *will;
@property(nonatomic, readonly) EXPExpect *willNot;
@property(nonatomic, readonly) EXPExpect *(^after)(NSTimeInterval timeInterval);

- (instancetype)initWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(const char *)fileName NS_DESIGNATED_INITIALIZER;
+ (EXPExpect *)expectWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(const char *)fileName;

- (void)applyMatcher:(id<EXPMatcher>)matcher;
- (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual;

@end

@interface EXPDynamicPredicateMatcher : NSObject <EXPMatcher> {
EXPExpect *_expectation;
SEL _selector;
}
- (instancetype)initWithExpectation:(EXPExpect *)expectation selector:(SEL)selector NS_DESIGNATED_INITIALIZER;
@property (nonatomic, readonly, copy) void (^dispatch)(void);
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// EXPMatcher.h
// Expecta
//
// Created by Luke Redpath on 26/03/2012.
// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol EXPMatcher <NSObject>

- (BOOL)matches:(id)actual;

@optional
- (BOOL)meetsPrerequesiteFor:(id)actual;
- (NSString *)failureMessageForTo:(id)actual;
- (NSString *)failureMessageForNotTo:(id)actual;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "Expecta.h"

EXPMatcherInterface(_beCloseToWithin, (id expected, id within));
EXPMatcherInterface(beCloseToWithin, (id expected, id within));

#define beCloseTo(expected) _beCloseToWithin(EXPObjectify((expected)), nil)
#define beCloseToWithin(expected, range) _beCloseToWithin(EXPObjectify((expected)), EXPObjectify((range)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "Expecta.h"

EXPMatcherInterface(beFalsy, (void));
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beGreaterThan, (id expected));
EXPMatcherInterface(beGreaterThan, (id expected));

#define beGreaterThan(expected) _beGreaterThan(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beGreaterThanOrEqualTo, (id expected));
EXPMatcherInterface(beGreaterThanOrEqualTo, (id expected));

#define beGreaterThanOrEqualTo(expected) _beGreaterThanOrEqualTo(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import "Expecta.h"

EXPMatcherInterface(_beIdenticalTo, (void *expected));
EXPMatcherInterface(beIdenticalTo, (void *expected)); // to aid code completion

#if __has_feature(objc_arc)
#define beIdenticalTo(expected) _beIdenticalTo((__bridge void*)expected)
#else
#define beIdenticalTo(expected) _beIdenticalTo(expected)
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beInTheRangeOf, (id expectedLowerBound, id expectedUpperBound));
EXPMatcherInterface(beInTheRangeOf, (id expectedLowerBound, id expectedUpperBound));

#define beInTheRangeOf(expectedLowerBound, expectedUpperBound) _beInTheRangeOf(EXPObjectify((expectedLowerBound)), EXPObjectify((expectedUpperBound)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(beInstanceOf, (Class expected));
EXPMatcherInterface(beAnInstanceOf, (Class expected));
EXPMatcherInterface(beMemberOf, (Class expected));
EXPMatcherInterface(beAMemberOf, (Class expected));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "Expecta.h"

EXPMatcherInterface(beKindOf, (Class expected));
EXPMatcherInterface(beAKindOf, (Class expected));
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beLessThan, (id expected));
EXPMatcherInterface(beLessThan, (id expected));

#define beLessThan(expected) _beLessThan(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beLessThanOrEqualTo, (id expected));
EXPMatcherInterface(beLessThanOrEqualTo, (id expected));

#define beLessThanOrEqualTo(expected) _beLessThanOrEqualTo(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "Expecta.h"

EXPMatcherInterface(beNil, (void));
EXPMatcherInterface(beNull, (void));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "Expecta.h"

EXPMatcherInterface(beSubclassOf, (Class expected));
EXPMatcherInterface(beASubclassOf, (Class expected));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "Expecta.h"

EXPMatcherInterface(beSupersetOf, (id subset));

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "Expecta.h"

EXPMatcherInterface(beTruthy, (void));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "Expecta.h"

EXPMatcherInterface(beginWith, (id expected));
EXPMatcherInterface(startWith, (id expected));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "Expecta.h"

EXPMatcherInterface(conformTo, (Protocol *expected));
Loading

0 comments on commit 3016756

Please sign in to comment.