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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
//
// SDLRPCMessage.m
// SmartDeviceLink-iOS
#import <Foundation/Foundation.h>
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>
#import "SDLRPCMessage.h"
#import "SDLNames.h"
QuickSpecBegin(SDLRPCMessageSpec)
describe(@"Readonly Property Tests", ^ {
it(@"Should get name correctly when initialized with name", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@"Poorly Named"];
expect(testMessage.name).to(equal(@"Poorly Named"));
});
it(@"Should get correctly when initialized with dictionary", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithDictionary:[@{NAMES_notification:
@{NAMES_parameters:
@{@"name":@"George"},
NAMES_operation_name:@"Poorly Named"}} mutableCopy]];
expect(testMessage.name).to(equal(@"Poorly Named"));
expect(testMessage.messageType).to(equal(NAMES_notification));
});
});
describe(@"Parameter Tests", ^ {
it(@"Should set and get correctly", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@""];
[testMessage setParameters:@"ADogAPanicInAPagoda" value:@"adogaPAnIcinaPAgoDA"];
expect([testMessage getParameters:@"ADogAPanicInAPagoda"]).to(equal(@"adogaPAnIcinaPAgoDA"));
});
it(@"Should get correctly when initialized", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithDictionary:[@{NAMES_response:
@{NAMES_parameters:
@{@"age":@25},
NAMES_operation_name:@"Nameless"}} mutableCopy]];
expect([testMessage getParameters:@"age"]).to(equal(@25));
});
it(@"Should be nil if not set", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@""];
expect([testMessage getParameters:@"ADogAPanicInAPagoda"]).to(beNil());
});
});
describe(@"FunctionName Tests", ^ {
it(@"Should set and get correctly", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@""];
[testMessage setFunctionName:@"Functioning"];
expect([testMessage getFunctionName]).to(equal(@"Functioning"));
});
it(@"Should get correctly when initialized", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithDictionary:[@{NAMES_request:
@{NAMES_parameters:
@{@"age":@25},
NAMES_operation_name:@"DoNothing"}} mutableCopy]];
expect([testMessage getFunctionName]).to(equal(@"DoNothing"));
testMessage = [[SDLRPCMessage alloc] initWithName:@"DoSomething"];
expect([testMessage getFunctionName]).to(equal(@"DoSomething"));
});
it(@"Should be nil if not set", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithDictionary:[@{NAMES_notification:
@{NAMES_parameters:
@{}}} mutableCopy]];
expect([testMessage getFunctionName]).to(beNil());
});
});
describe(@"BulkDataTests", ^ {
it(@"Should set and get correctly", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@""];
const char* testString = "ImportantData";
testMessage.bulkData = [NSData dataWithBytes:testString length:strlen(testString)];
expect([NSString stringWithUTF8String:testMessage.bulkData.bytes]).to(equal(@"ImportantData"));
});
it(@"Should get correctly when initialized", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithDictionary:[@{NAMES_notification:
@{NAMES_parameters:
@{}},
NAMES_bulkData:[NSData dataWithBytes:"ImageData" length:strlen("ImageData")]} mutableCopy]];
expect(testMessage.bulkData).to(equal([NSData dataWithBytes:"ImageData" length:strlen("ImageData")]));
});
it(@"Should be nil if not set", ^ {
SDLRPCMessage* testMessage = [[SDLRPCMessage alloc] initWithName:@""];
expect(testMessage.bulkData).to(beNil());
});
});
QuickSpecEnd
|