Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Tests/CFRunLoop/observer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "CoreFoundation/CFRunLoop.h"
#include "../CFTesting.h"
#include <string.h>

static void
observe (CFRunLoopObserverRef o, CFRunLoopActivity a, void *info)
{
}

int main (void)
{
int marker = 42;
CFRunLoopObserverContext ctx = { 0, &marker, NULL, NULL, NULL };
CFRunLoopObserverContext got;
CFOptionFlags acts = kCFRunLoopBeforeWaiting | kCFRunLoopExit;
CFRunLoopObserverRef obs = CFRunLoopObserverCreate (NULL, acts, true, 5,
observe, &ctx);

PASS_CF (obs != NULL, "An observer is created.");
PASS_CF (CFGetTypeID (obs) == CFRunLoopObserverGetTypeID (),
"An observer has the observer type ID.");
PASS_CF (CFRunLoopObserverGetActivities (obs) == acts,
"The observed activities round-trip.");
PASS_CF (CFRunLoopObserverDoesRepeat (obs) == true,
"The repeat flag round-trips.");
PASS_CF (CFRunLoopObserverGetOrder (obs) == 5, "The order round-trips.");

memset (&got, 0, sizeof (got));
CFRunLoopObserverGetContext (obs, &got);
PASS_CF (got.info == &marker, "The context info pointer round-trips.");

CFRelease (obs);
return 0;
}
40 changes: 40 additions & 0 deletions Tests/CFRunLoop/source_accessors.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "CoreFoundation/CFRunLoop.h"
#include "../CFTesting.h"
#include <string.h>

static void
perform (void *info)
{
}

int main (void)
{
int marker = 99;
CFRunLoopSourceContext ctx;
CFRunLoopSourceContext got;
CFRunLoopSourceRef src;

memset (&ctx, 0, sizeof (ctx));
ctx.version = 0;
ctx.info = &marker;
ctx.perform = perform;
src = CFRunLoopSourceCreate (NULL, 4, &ctx);

PASS_CF (src != NULL, "A source is created.");
PASS_CF (CFGetTypeID (src) == CFRunLoopSourceGetTypeID (),
"A source has the source type ID.");
PASS_CF (CFRunLoopSourceGetOrder (src) == 4, "The order round-trips.");
PASS_CF (CFRunLoopSourceIsValid (src) == true, "A new source is valid.");

memset (&got, 0, sizeof (got));
CFRunLoopSourceGetContext (src, &got);
PASS_CF (got.info == &marker, "The context info pointer round-trips.");
PASS_CF (got.version == 0, "The context version round-trips.");

CFRunLoopSourceInvalidate (src);
PASS_CF (CFRunLoopSourceIsValid (src) == false,
"An invalidated source is no longer valid.");

CFRelease (src);
return 0;
}
44 changes: 44 additions & 0 deletions Tests/CFRunLoop/timer_accessors.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "CoreFoundation/CFRunLoop.h"
#include "../CFTesting.h"
#include <string.h>

static void
fire (CFRunLoopTimerRef t, void *info)
{
}

int main (void)
{
int marker = 7;
CFRunLoopTimerContext ctx = { 0, &marker, NULL, NULL, NULL };
CFRunLoopTimerContext got;
CFRunLoopTimerRef t = CFRunLoopTimerCreate (NULL, 100.0, 5.0, 0, 3,
fire, &ctx);
CFRunLoopTimerRef once = CFRunLoopTimerCreate (NULL, 100.0, 0.0, 0, 0,
fire, NULL);

PASS_CF (t != NULL, "A timer is created.");
PASS_CF (CFGetTypeID (t) == CFRunLoopTimerGetTypeID (),
"A timer has the timer type ID.");
PASS_CF (CFRunLoopTimerGetNextFireDate (t) == 100.0,
"The fire date round-trips.");
PASS_CF (CFRunLoopTimerGetInterval (t) == 5.0, "The interval round-trips.");
PASS_CF (CFRunLoopTimerGetOrder (t) == 3, "The order round-trips.");
PASS_CF (CFRunLoopTimerDoesRepeat (t) == true,
"A timer with a positive interval repeats.");
PASS_CF (CFRunLoopTimerDoesRepeat (once) == false,
"A timer with a zero interval does not repeat.");
PASS_CF (CFRunLoopTimerIsValid (t) == true, "A new timer is valid.");

memset (&got, 0, sizeof (got));
CFRunLoopTimerGetContext (t, &got);
PASS_CF (got.info == &marker, "The context info pointer round-trips.");

CFRunLoopTimerInvalidate (t);
PASS_CF (CFRunLoopTimerIsValid (t) == false,
"An invalidated timer is no longer valid.");

CFRelease (t);
CFRelease (once);
return 0;
}
Loading