Skip to content

Instantly share code, notes, and snippets.

#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import "HomeViewController.h"
#import "HomeViewPresenter.h"
@interface HomeViewControllerTest : XCTestCase {
id mockPresenter_;
HomeViewController *viewController_;
}
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import "HomeView.h"
#import "HomeViewController.h"
#import "HomeViewPresenter.h"
#import "UIImageHelper.h"
@interface HomeViewPresenterTest : XCTestCase {
id mockCameraButton_;
// Turn an image into an array of UIColors.
+ (NSArray *)pixelsForImage:(UIImage *)image {
NSUInteger width = [image size].width;
NSUInteger height = [image size].height;
NSUInteger count = width * height;
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// Add 1 for the alpha channel
// Create an image from an array of colors.
+ (UIImage *)createImageWithPixelData:(NSArray *)pixelData width:(int)width height:(int)height {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// Add 1 for the alpha channel
size_t numberOfComponents = CGColorSpaceGetNumberOfComponents(colorSpace) + 1;
size_t bitsPerComponent = 8;
size_t bytesPerPixel = (bitsPerComponent * numberOfComponents) / 8;
size_t bytesPerRow = bytesPerPixel * width;
uint8_t *rawData = (uint8_t*)calloc([pixelData count] * numberOfComponents, sizeof(uint8_t));
- (void)compareColorArrayRGBs:(NSArray *)array toExpected:(NSArray *)expected {
XCTAssertEqual([expected count], [array count]);
for (int i = 0; i < [expected count]; i++) {
UIColor *color = [array objectAtIndex:i];
UIColor *expectedColor = [expected objectAtIndex:i];
CGFloat r, g, b, a;
CGFloat eR, eG, eB, eA;
[color getRed:&r green:&g blue:&b alpha:&a];
[expectedColor getRed:&eR green:&eG blue:&eB alpha:&eA];
@catehstn
catehstn / AndroidTwoColorImage.java
Last active August 29, 2015 14:17
Android create 3x3 2-color alternating image
/**
* A 3x3 2-color image.
* @param color1
* @param color2
* @return A 3x3 image alternating the two colors.
*/
public static Bitmap createTwoColorImage(int color1, int color2) {
Bitmap bitmap = Bitmap.createBitmap(3, 3, Bitmap.Config.ARGB_8888);
bitmap.setPixel(0, 0, color1);
bitmap.setPixel(2, 0, color1);
/**
* A image from an array of colors.
* @param width
* @param height
* @param colors
* @return image of given width and height filled with the given color array.
*/
public static Bitmap createImage(int width, int height, int[] colors) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int x = 0;
/**
* Compare two images.
* @param bitmap1
* @param bitmap2
* @return true iff both images have the same dimensions and pixel values.
*/
public static boolean compareImages(Bitmap bitmap1, Bitmap bitmap2) {
if (bitmap1.getWidth() != bitmap2.getWidth() ||
bitmap1.getHeight() != bitmap2.getHeight()) {
return false;
- (void)testRotateHomeScreen {
XCUIDevice *device = [XCUIDevice sharedDevice];
[self verifyHomePageButtons];
[device setOrientation:UIDeviceOrientationLandscapeRight];
[self verifyHomePageButtons];
[device setOrientation:UIDeviceOrientationPortraitUpsideDown];
[self verifyHomePageButtons];
- (void)testOpenInspireView {
[[app_ buttons][[SHAStrings inspireButtonTitleString]] tap];
// Verify page load by checking the title.
XCUIElement *title = [app_ otherElements][@"Show and Hide"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"exists == 1"];
[self expectationForPredicate:predicate evaluatedWithObject:title handler:nil];
[self waitForExpectationsWithTimeout:2.0 handler:nil];
// Go back.