mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
First draft of iOS test runner
This commit is contained in:
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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user