~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Testing/nstimer.m

Tags: upstream-1.20.0
ImportĀ upstreamĀ versionĀ 1.20.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test/example program for the base library
2
 
 
3
 
   Copyright (C) 2005 Free Software Foundation, Inc.
4
 
   
5
 
  Copying and distribution of this file, with or without modification,
6
 
  are permitted in any medium without royalty provided the copyright
7
 
  notice and this notice are preserved.
8
 
 
9
 
   This file is part of the GNUstep Base Library.
10
 
*/
11
 
#include <Foundation/NSRunLoop.h>
12
 
#include <Foundation/NSTimer.h>
13
 
#include <Foundation/NSInvocation.h>
14
 
#include <Foundation/NSAutoreleasePool.h>
15
 
 
16
 
@interface TestDouble : NSObject
17
 
+ (double) testDouble;
18
 
- (double) testDoubleInstance;
19
 
@end
20
 
@implementation TestDouble
21
 
+ (void) sayCount
22
 
{
23
 
  static int count = 0;
24
 
  printf ("Timer fired %d times\n", ++count);
25
 
  if (count == 20)
26
 
    exit(0);
27
 
}
28
 
+ (double) testDouble
29
 
{
30
 
  return 12345678912345.0;
31
 
}
32
 
- (double) testDoubleInstance
33
 
{
34
 
  return 92345678912345.0;
35
 
}
36
 
@end
37
 
 
38
 
double test_double ()
39
 
{
40
 
  return 92345678912345.0;
41
 
}
42
 
 
43
 
 
44
 
int main()
45
 
{
46
 
  NSAutoreleasePool     *arp = [NSAutoreleasePool new];
47
 
  volatile double foo, bar;
48
 
  id inv;
49
 
  id o;
50
 
  id d;
51
 
 
52
 
  inv = [NSInvocation invocationWithMethodSignature:
53
 
    [TestDouble methodSignatureForSelector: @selector(sayCount)]];
54
 
  [inv setSelector: @selector(sayCount)];
55
 
  [inv setTarget: [TestDouble class]];
56
 
 
57
 
  foo = [TestDouble testDouble];
58
 
  printf ("TestDouble is %f\n", foo);
59
 
  foo = [TestDouble testDouble];
60
 
  printf ("TestDouble 2 is %f\n", foo);
61
 
  o = [[TestDouble alloc] init];
62
 
  bar = [o testDoubleInstance];
63
 
  printf ("testDouble is %f\n", bar);
64
 
 
65
 
  foo = test_double ();
66
 
  printf ("test_double is %f\n", foo);
67
 
 
68
 
  d = [NSDate date];
69
 
  printf ("time interval since now %f\n", [d timeIntervalSinceNow]);
70
 
 
71
 
  [NSTimer scheduledTimerWithTimeInterval: 3.0
72
 
           invocation: inv
73
 
           repeats: YES];
74
 
  [[NSRunLoop currentRunLoop] run];
75
 
  [arp release];
76
 
  exit (0);
77
 
}