]> git.saurik.com Git - apple/security.git/blob - sec/SOSCircle/Regressions/SOSTestTransport.c
Security-55471.14.8.tar.gz
[apple/security.git] / sec / SOSCircle / Regressions / SOSTestTransport.c
1 //
2 // SOSTestTransport.c
3 // sec
4 //
5 // Created by Michael Brouwer on 10/16/12.
6 //
7
8 #include "SOSTestTransport.h"
9
10 #include <utilities/SecCFWrappers.h>
11 #include <test/testmore.h>
12
13 struct SOSTestTransport {
14 struct SOSTransport t;
15 CFDataRef lastMessage;
16 };
17
18
19 /* Transport protocol. */
20 static bool SOSTestTransportQueue(SOSTransportRef transport, CFDataRef message) {
21 struct SOSTestTransport *t = (struct SOSTestTransport *)transport;
22 if (t->lastMessage) {
23 fail("We already had an unproccessed message");
24 CFReleaseNull(t->lastMessage);
25 }
26 CFRetain(message);
27 t->lastMessage = message;
28 return true;
29 }
30
31 CFDataRef SOSTestTransportDequeue(SOSTransportRef transport) {
32 struct SOSTestTransport *t = (struct SOSTestTransport *)transport;
33 CFDataRef message = t->lastMessage;
34 t->lastMessage = NULL;
35 return message;
36 }
37
38 void SOSTestTransportDispose(SOSTransportRef transport) {
39 struct SOSTestTransport *t = (struct SOSTestTransport *)transport;
40 free(t);
41 }
42
43 SOSTransportRef SOSTestTransportCreate(void) {
44 struct SOSTestTransport *transport = calloc(1, sizeof(struct SOSTestTransport));
45 transport->t.send = SOSTestTransportQueue;
46
47 return (SOSTransportRef)transport;
48 }