Skip to content

Instantly share code, notes, and snippets.

- (void)testRotateHomeScreen {
XCUIDevice *device = [XCUIDevice sharedDevice];
[self verifyHomePageButtons];
[device setOrientation:UIDeviceOrientationLandscapeRight];
[self verifyHomePageButtons];
[device setOrientation:UIDeviceOrientationPortraitUpsideDown];
[self verifyHomePageButtons];
/**
* 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;
/**
* 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;
@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);
@catehstn
catehstn / AndroidOneColorImage.java
Last active September 25, 2023 09:16
Android create one color image
/**
* A one color image.
* @param width
* @param height
* @param color
* @return A one color image with the given width and height.
*/
public static Bitmap createImage(int width, int height, int color) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
- (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];
// 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));
// 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
@catehstn
catehstn / ImageDrawer.m
Last active December 1, 2016 05:30
Creating images from an array of colors
// Make an image all of one size, in whatever color.
+ (UIImage *)createTestImageWithWidth:(CGFloat)width
height:(CGFloat)height
color:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(rect.size);
[color set];
UIRectFill(rect);
UIImage *testImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
#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_;