summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m
blob: 16ffa8b2a24c9d4c96460a2f1cbc67f61927cd2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>

#import "SDLArtwork.h"
#import "SDLFileType.h"

QuickSpecBegin(SDLArtworkSpec)

describe(@"SDLArtwork", ^{
    __block SDLArtwork *testArtwork = nil;
    
    describe(@"when created", ^{
        context(@"As a PNG", ^{
            __block NSString *testArtworkName = nil;
            __block UIImage *testImage = nil;
            __block SDLArtworkImageFormat testFormat = NSNotFound;
            
            beforeEach(^{
                testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
                testArtworkName = @"Test Artwork";
                testFormat = SDLArtworkImageFormatPNG;
                
                testArtwork = [[SDLArtwork alloc] initWithImage:testImage name:testArtworkName persistent:NO asImageFormat:testFormat];
            });
            
            it(@"should correctly store image data", ^{
                expect(testArtwork.data).to(equal(UIImagePNGRepresentation(testImage)));
            });
            
            it(@"should correctly store name", ^{
                expect(testArtwork.name).to(equal(testArtworkName));
            });
            
            it(@"should correctly store format", ^{
                expect(testArtwork.fileType).to(equal(SDLFileTypeGraphicPNG));
            });
            
            it(@"should correctly store persistence", ^{
                expect(@(testArtwork.persistent)).to(equal(@NO));
            });
        });
        
        context(@"As a JPG", ^{
            __block NSString *testArtworkName = nil;
            __block UIImage *testImage = nil;
            __block SDLArtworkImageFormat testFormat = NSNotFound;
            
            beforeEach(^{
                testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
                testArtworkName = @"Test Artwork";
                testFormat = SDLArtworkImageFormatJPG;
                
                testArtwork = [[SDLArtwork alloc] initWithImage:testImage name:testArtworkName persistent:NO asImageFormat:testFormat];
            });
            
            it(@"should correctly store image data", ^{
                expect(testArtwork.data).to(equal(UIImageJPEGRepresentation(testImage, 0.85)));
            });
            
            it(@"should correctly store name", ^{
                expect(testArtwork.name).to(equal(testArtworkName));
            });
            
            it(@"should correctly store format", ^{
                expect(testArtwork.fileType).to(equal(SDLFileTypeGraphicJPEG));
            });
            
            it(@"should correctly store persistence", ^{
                expect(@(testArtwork.persistent)).to(equal(@NO));
            });
        });
        
        describe(@"to be persistent", ^{
            __block NSString *testArtworkName = nil;
            __block UIImage *testImage = nil;
            __block SDLArtworkImageFormat testFormat = NSNotFound;
            
            beforeEach(^{
                testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
                testArtworkName = @"Test Artwork";
                testFormat = SDLArtworkImageFormatPNG;
                
                testArtwork = [[SDLArtwork alloc] initWithImage:testImage name:testArtworkName persistent:YES asImageFormat:testFormat];
            });
            
            it(@"is persistent", ^{
                expect(@(testArtwork.persistent)).to(equal(@YES));
            });
        });
    });
});

QuickSpecEnd