mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
First draft of iOS test runner
This commit is contained in:
parent
58e9a8bafd
commit
9e33fdd465
108
runners/iTchRunner/internal/iTchRunnerAppDelegate.h
Normal file
108
runners/iTchRunner/internal/iTchRunnerAppDelegate.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* iTchRunnerAppDelegate.h
|
||||||
|
* iTchRunner
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/02/2011.
|
||||||
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "iTchRunnerMainView.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@interface iTchRunnerAppDelegate : NSObject <UIApplicationDelegate>
|
||||||
|
{
|
||||||
|
UIWindow *window;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation iTchRunnerAppDelegate
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
|
{
|
||||||
|
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||||
|
[window setUserInteractionEnabled:YES];
|
||||||
|
[window setMultipleTouchEnabled:YES];
|
||||||
|
|
||||||
|
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
|
||||||
|
iTchRunnerMainView* view = [[iTchRunnerMainView alloc] initWithFrame:screenRect];
|
||||||
|
|
||||||
|
[window addSubview:view];
|
||||||
|
[window makeKeyAndVisible];
|
||||||
|
[view release];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[window release];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationWillResignActive:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||||
|
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||||
|
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationDidBecomeActive:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationWillTerminate:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Called when the application is about to terminate.
|
||||||
|
See also applicationDidEnterBackground:.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
127
runners/iTchRunner/internal/iTchRunnerMainView.h
Normal file
127
runners/iTchRunner/internal/iTchRunnerMainView.h
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* iTchRunnerMainView.h
|
||||||
|
* iTchRunner
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/02/2011.
|
||||||
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "internal/catch_config.hpp"
|
||||||
|
#include "internal/catch_runner_impl.hpp"
|
||||||
|
#include "internal/catch_hub_impl.hpp"
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include "iTchRunnerReporter.h"
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface iTchRunnerMainView : UIView<iTchRunnerDelegate, UIActionSheetDelegate>
|
||||||
|
{
|
||||||
|
UITextField* appName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation iTchRunnerMainView
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
-(id) initWithFrame:(CGRect)frame
|
||||||
|
{
|
||||||
|
if ((self = [super initWithFrame:frame]))
|
||||||
|
{
|
||||||
|
// Initialization code
|
||||||
|
self.backgroundColor = [UIColor blackColor];
|
||||||
|
|
||||||
|
appName = [[UITextField alloc] initWithFrame: CGRectMake( 0, 50, 320, 50 )];
|
||||||
|
[self addSubview: appName];
|
||||||
|
[appName release];
|
||||||
|
appName.textColor = [[UIColor alloc] initWithRed:0.35 green:0.35 blue:1 alpha:1];
|
||||||
|
[appName.textColor release];
|
||||||
|
appName.textAlignment = UITextAlignmentCenter;
|
||||||
|
|
||||||
|
NSString* appNameStr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
|
||||||
|
if( [appNameStr isEqualToString:@"iTchRunner"] )
|
||||||
|
appName.text = @"iTchRunner self-tests";
|
||||||
|
else
|
||||||
|
appName.text = [NSString stringWithFormat:@"CATCH tests for %@", appNameStr];
|
||||||
|
|
||||||
|
|
||||||
|
UIActionSheet* menu = [[UIActionSheet alloc] initWithTitle:@"Options"
|
||||||
|
delegate:self
|
||||||
|
cancelButtonTitle:nil
|
||||||
|
destructiveButtonTitle:nil
|
||||||
|
otherButtonTitles:@"Run all tests", nil];
|
||||||
|
[menu showInView: self];
|
||||||
|
[menu release];
|
||||||
|
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
-(void) dealloc
|
||||||
|
{
|
||||||
|
[appName removeFromSuperview];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
-(void) actionSheet: (UIActionSheet*) sheet clickedButtonAtIndex: (NSInteger) index
|
||||||
|
{
|
||||||
|
Catch::Config config;
|
||||||
|
config.setReporter( new Catch::iTchRunnerReporter( self ) );
|
||||||
|
Catch::Runner runner( config );
|
||||||
|
|
||||||
|
config.getReporter()->StartGroup( "" );
|
||||||
|
runner.runAll( true );
|
||||||
|
config.getReporter()->EndGroup( "", runner.getSuccessCount(), runner.getFailureCount() );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
-(void) testWasRun: (const Catch::ResultInfo*) pResultInfo
|
||||||
|
{
|
||||||
|
const Catch::ResultInfo& resultInfo = *pResultInfo;
|
||||||
|
std::ostringstream oss;
|
||||||
|
|
||||||
|
if( resultInfo.hasExpression() )
|
||||||
|
{
|
||||||
|
oss << resultInfo.getExpression();
|
||||||
|
if( resultInfo.ok() )
|
||||||
|
oss << " succeeded";
|
||||||
|
else
|
||||||
|
oss << " failed";
|
||||||
|
}
|
||||||
|
switch( resultInfo.getResultType() )
|
||||||
|
{
|
||||||
|
case Catch::ResultWas::ThrewException:
|
||||||
|
if( resultInfo.hasExpression() )
|
||||||
|
oss << " with unexpected";
|
||||||
|
else
|
||||||
|
oss << "Unexpected";
|
||||||
|
oss << " exception with message: '" << resultInfo.getMessage() << "'";
|
||||||
|
break;
|
||||||
|
case Catch::ResultWas::Info:
|
||||||
|
oss << "info: '" << resultInfo.getMessage() << "'";
|
||||||
|
break;
|
||||||
|
case Catch::ResultWas::Warning:
|
||||||
|
oss << "warning: '" << resultInfo.getMessage() << "'";
|
||||||
|
break;
|
||||||
|
case Catch::ResultWas::ExplicitFailure:
|
||||||
|
oss << "failed with message: '" << resultInfo.getMessage() << "'";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( resultInfo.hasExpression() )
|
||||||
|
{
|
||||||
|
oss << " for: " << resultInfo.getExpandedExpression();
|
||||||
|
}
|
||||||
|
oss << std::endl;
|
||||||
|
NSLog( @"%s", oss.str().c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
105
runners/iTchRunner/internal/iTchRunnerReporter.h
Normal file
105
runners/iTchRunner/internal/iTchRunnerReporter.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* iTchRunnerReporter.h
|
||||||
|
* iTchRunner
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/02/2011.
|
||||||
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
@protocol iTchRunnerDelegate
|
||||||
|
|
||||||
|
-(void) testWasRun: (const Catch::ResultInfo*) result;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
class iTchRunnerReporter : public IReporter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
iTchRunnerReporter
|
||||||
|
(
|
||||||
|
id<iTchRunnerDelegate> delegate
|
||||||
|
)
|
||||||
|
: m_succeeded( 0 ),
|
||||||
|
m_failed( 0 ),
|
||||||
|
m_delegate( delegate )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
static std::string getDescription
|
||||||
|
()
|
||||||
|
{
|
||||||
|
return "Captures results for iOS runner";
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
size_t getSucceeded
|
||||||
|
()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return m_succeeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
size_t getFailed
|
||||||
|
()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return m_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
m_succeeded = 0;
|
||||||
|
m_failed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private: // IReporter
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
virtual void StartTesting
|
||||||
|
()
|
||||||
|
{}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
virtual void EndTesting
|
||||||
|
(
|
||||||
|
std::size_t succeeded,
|
||||||
|
std::size_t failed
|
||||||
|
)
|
||||||
|
{
|
||||||
|
m_succeeded = succeeded;
|
||||||
|
m_failed = failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
virtual void Result
|
||||||
|
(
|
||||||
|
const ResultInfo& result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
[m_delegate testWasRun: &result];
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Deliberately unimplemented:
|
||||||
|
virtual void StartGroup( const std::string& ){}
|
||||||
|
virtual void EndGroup( const std::string&, std::size_t, std::size_t ){}
|
||||||
|
virtual void StartTestCase( const TestCaseInfo& ){}
|
||||||
|
virtual void StartSection( const std::string&, const std::string ){}
|
||||||
|
virtual void EndSection( const std::string&, std::size_t, std::size_t ){}
|
||||||
|
virtual void EndTestCase( const TestCaseInfo&, std::size_t, std::size_t, const std::string&, const std::string& ){}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t m_succeeded;
|
||||||
|
size_t m_failed;
|
||||||
|
|
||||||
|
id<iTchRunnerDelegate> m_delegate;
|
||||||
|
};
|
||||||
|
}
|
18
runners/iTchRunner/itChRunnerMain.mm
Normal file
18
runners/iTchRunner/itChRunnerMain.mm
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// iTchRunnerMain.mm
|
||||||
|
// iTchRunner
|
||||||
|
//
|
||||||
|
// Created by Phil on 04/02/2011.
|
||||||
|
// Copyright Two Blue Cubes Ltd 2011. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "internal/iTchRunnerAppDelegate.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
|
||||||
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
int retVal = UIApplicationMain(argc, argv, nil, @"iTchRunnerAppDelegate");
|
||||||
|
[pool release];
|
||||||
|
return retVal;
|
||||||
|
}
|
6
runners/iTchRunner/readme
Normal file
6
runners/iTchRunner/readme
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
* Select Project -> New Target. Select Cocoa Touch -> Application. Click next and name it something like "Unit Tests"
|
||||||
|
* While the target info is displayed, find: 'User Header Search Paths' and add a path to the Catch folder
|
||||||
|
* Open the plist file for the target (Unit Test-Info.plist, if you used that name). Delete the entry for "Main nib file base name: MainWindow"
|
||||||
|
* From the overview drop-down select the new target.
|
||||||
|
* Add the file Catch/Runner/iTchRunnerMain.mm into your project - but only in the new target
|
||||||
|
* Write tests (adding files under test into the target as necessary)
|
Loading…
Reference in New Issue
Block a user