diff options
Diffstat (limited to 'unittest/Catch/projects/runners/iTchRunner/internal')
3 files changed, 418 insertions, 0 deletions
diff --git a/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerAppDelegate.h b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerAppDelegate.h new file mode 100644 index 0000000..522291a --- /dev/null +++ b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerAppDelegate.h @@ -0,0 +1,114 @@ +/* + * iTchRunnerAppDelegate.h + * iTchRunner + * + * Created by Phil on 07/02/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + */ +#ifndef TWOBLUECUBES_ITCHRUNNERAPPDELEGATE_H_INCLUDED +#define TWOBLUECUBES_ITCHRUNNERAPPDELEGATE_H_INCLUDED + +#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]; + arcSafeRelease( view ); + + return YES; +} + +/////////////////////////////////////////////////////////////////////////////// +- (void)dealloc +{ +#if !CATCH_ARC_ENABLED + [window release]; + [super dealloc]; +#endif +} + + +/////////////////////////////////////////////////////////////////////////////// +- (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 + +#endif // TWOBLUECUBES_ITCHRUNNERAPPDELEGATE_H_INCLUDED diff --git a/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerMainView.h b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerMainView.h new file mode 100644 index 0000000..c6a6394 --- /dev/null +++ b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerMainView.h @@ -0,0 +1,189 @@ +/* + * iTchRunnerMainView.h + * iTchRunner + * + * Created by Phil on 07/02/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + */ +#ifndef TWOBLUECUBES_ITCHRUNNERMAINVIEW_H_INCLUDED +#define TWOBLUECUBES_ITCHRUNNERMAINVIEW_H_INCLUDED + +#include "internal/catch_config.hpp" +#include "internal/catch_runner_impl.hpp" +#include "internal/catch_context_impl.hpp" +#include "catch.hpp" + +#include "iTchRunnerReporter.h" + +#import <UIKit/UIKit.h> + +@interface iTchRunnerMainView : UIView<iTchRunnerDelegate, UIActionSheetDelegate> +{ + UITextField* appName; +} + +-(void) showAlert; + +@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]; + arcSafeRelease( appName ); + appName.textColor = [[UIColor alloc] initWithRed:0.35 green:0.35 blue:1 alpha:1]; + arcSafeRelease( appName.textColor ); + appName.textAlignment = NSTextAlignmentCenter; + + appName.text = [NSString stringWithFormat:@"CATCH tests"]; +// [self performSelector: @selector(showAlert) withObject:nil afterDelay:0.1]; + [self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO]; + + } + return self; +} + +/////////////////////////////////////////////////////////////////////////////// +-(void) dealloc +{ + [appName removeFromSuperview]; +#if !CATCH_ARC_ENABLED + [super dealloc]; +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +-(void) showAlert +{ + UIActionSheet* menu = [[UIActionSheet alloc] initWithTitle:@"Options" + delegate:self + cancelButtonTitle:nil + destructiveButtonTitle:nil + otherButtonTitles:@"Run all tests", nil]; + [menu showInView: self]; + arcSafeRelease( menu ); + +} + +// This is a copy & paste from Catch::Runner2 to get us bootstrapped (this is due to all be +// replaced anyway) +inline Catch::Totals runTestsForGroup( Catch::RunContext& context, const Catch::TestCaseFilters& filterGroup ) { + using namespace Catch; + Totals totals; + std::vector<TestCase>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin(); + std::vector<TestCase>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end(); + int testsRunForGroup = 0; + for(; it != itEnd; ++it ) { + if( filterGroup.shouldInclude( *it ) ) { + testsRunForGroup++; + + if( context.aborting() ) + break; + + totals += context.runTest( *it ); + } + } + if( testsRunForGroup == 0 ) + std::cerr << "\n[No test cases matched with: " << filterGroup.getName() << "]" << std::endl; + return totals; + +} + +/////////////////////////////////////////////////////////////////////////////// +-(void) actionSheet: (UIActionSheet*) sheet clickedButtonAtIndex: (NSInteger) index +{ + Catch::Ptr<Catch::Config> config = new Catch::Config(); + Catch::IReporter* reporter = new Catch::iTchRunnerReporter( self ); + Catch::LegacyReporterAdapter* reporterAdapter = new Catch::LegacyReporterAdapter( reporter ); + Catch::RunContext runner( config.get(), reporterAdapter ); + + + std::vector<Catch::TestCaseFilters> filterGroups; + Catch::TestCaseFilters filterGroup( "" ); + filterGroups.push_back( filterGroup ); + + Catch::Totals totals; + + std::vector<Catch::TestCaseFilters>::const_iterator it = filterGroups.begin(); + std::vector<Catch::TestCaseFilters>::const_iterator itEnd = filterGroups.end(); + + std::size_t groupCount = filterGroups.size(); + std::size_t groupIndex = 0; + for(; it != itEnd && !runner.aborting(); ++it, ++index ) { + runner.testGroupStarting( it->getName(), groupIndex, groupCount ); + totals += runTestsForGroup( runner, *it ); + runner.testGroupEnded( it->getName(), totals, groupIndex, groupCount ); + } + + + if( totals.assertions.failed == 0 ) + { + NSLog( @"no failures" ); + if( totals.assertions.passed > 0 ) + appName.textColor = [[UIColor alloc] initWithRed:0.35 green:1 blue:0.35 alpha:1]; + } + else + { + NSLog( @"%lu failures", totals.assertions.failed ); + appName.textColor = [[UIColor alloc] initWithRed:1 green:0.35 blue:0.35 alpha:1]; + } +} + +/////////////////////////////////////////////////////////////////////////////// +-(void) testWasRun: (const Catch::AssertionResult*) pResultInfo +{ + const Catch::AssertionResult& resultInfo = *pResultInfo; + std::ostringstream oss; + + if( resultInfo.hasExpression() ) + { + oss << resultInfo.getExpression(); + if( resultInfo.isOk() ) + 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 + +#endif // TWOBLUECUBES_ITCHRUNNERMAINVIEW_H_INCLUDED diff --git a/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerReporter.h b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerReporter.h new file mode 100644 index 0000000..d262886 --- /dev/null +++ b/unittest/Catch/projects/runners/iTchRunner/internal/iTchRunnerReporter.h @@ -0,0 +1,115 @@ +/* + * iTchRunnerReporter.h + * iTchRunner + * + * Created by Phil on 07/02/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + */ +#ifndef TWOBLUECUBES_ITCHRUNNERREPORTER_H_INCLUDED +#define TWOBLUECUBES_ITCHRUNNERREPORTER_H_INCLUDED + +#include "catch.hpp" + +@protocol iTchRunnerDelegate + +-(void) testWasRun: (const Catch::AssertionResult*) result; + +@end + +namespace Catch +{ + class iTchRunnerReporter : public SharedImpl<IReporter> + { + public: + /////////////////////////////////////////////////////////////////////////// + iTchRunnerReporter + ( + id<iTchRunnerDelegate> delegate + ) + : m_delegate( delegate ) + { + } + + /////////////////////////////////////////////////////////////////////////// + virtual bool shouldRedirectStdout + () + const + { + return true; + } + + /////////////////////////////////////////////////////////////////////////// + static std::string getDescription + () + { + return "Captures results for iOS runner"; + } + + /////////////////////////////////////////////////////////////////////////// + size_t getSucceeded + () + const + { + return m_totals.assertions.passed; + } + + /////////////////////////////////////////////////////////////////////////// + size_t getFailed + () + const + { + return m_totals.assertions.failed; + } + + /////////////////////////////////////////////////////////////////////////// + void reset() + { + m_totals = Totals(); + } + + private: // IReporter + + /////////////////////////////////////////////////////////////////////////// + virtual void StartTesting + () + {} + + /////////////////////////////////////////////////////////////////////////// + virtual void EndTesting + ( + const Totals& totals + ) + { + m_totals = totals; + } + + /////////////////////////////////////////////////////////////////////////// + virtual void Result + ( + const AssertionResult& result + ) + { + [m_delegate testWasRun: &result]; + } + + /////////////////////////////////////////////////////////////////////////// + // Deliberately unimplemented: + virtual void StartGroup( const std::string& ){} + virtual void EndGroup( const std::string&, const Totals& ){} + virtual void StartTestCase( const TestCaseInfo& ){} + virtual void StartSection( const std::string& sectionName, const std::string& description ) {} + virtual void EndSection( const std::string&, const Counts& ){} + virtual void EndTestCase( const TestCaseInfo&, const Totals&, const std::string&, const std::string& ){} + virtual void Aborted() {} + virtual void NoAssertionsInSection( std::string const& sectionName ) {} + virtual void NoAssertionsInTestCase( std::string const& testName ) {} + + private: + Totals m_totals; + + id<iTchRunnerDelegate> m_delegate; + }; +} + +#endif // TWOBLUECUBES_ITCHRUNNERREPORTER_H_INCLUDED |