OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [objc/] [execute/] [class-tests-1.h] - Blame information for rev 702

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 702 jeremybenn
/* Contributed by Nicola Pero on Tue Mar  6 23:05:53 CET 2001 */
2
 
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include "../../objc-obj-c++-shared/runtime.h"
6
 
7
/*
8
 * Standard Tests For Classes and Objects - abort upon failing; return
9
 * normally if all is well.
10
 */
11
 
12
/* Test that `class' is a Class */
13
static void test_is_class (Class class)
14
{
15
  if (class_isMetaClass (object_getClass (class)) == NO)
16
    {
17
      printf ("test_is_class failed\n");
18
      abort ();
19
    }
20
}
21
 
22
/* Test that the superclass of `class' is `superclass' */
23
static void test_superclass (Class class, Class superclass)
24
{
25
  if (class_getSuperclass (class) != superclass)
26
    {
27
      printf ("test_superclass failed\n");
28
      abort ();
29
    }
30
}
31
 
32
/* Test that the classname of `class' is `classname' */
33
static void test_class_name (Class class, const char *classname)
34
{
35
  if (strcmp (class_getName (class), classname))
36
    {
37
      printf ("test_class_name failed\n");
38
      abort ();
39
    }
40
}
41
 
42
/* Test that we can allocate instances of `class' */
43
static void test_allocate (Class class)
44
{
45
  /* The object we create is leaked but who cares, this is only a test */
46
  id object = class_createInstance (class, 0);
47
 
48
  if (object == nil)
49
    {
50
      printf ("test_allocate failed\n");
51
      abort ();
52
    }
53
}
54
 
55
/* Test that instances of `class' are instances and not classes */
56
static void test_instances (Class class)
57
{
58
  id object = class_createInstance (class, 0);
59
 
60
  if (class_isMetaClass (object_getClass (object)) == YES)
61
    {
62
      printf ("test_instances failed\n");
63
      abort ();
64
    }
65
}
66
 
67
/* Test that we can deallocate instances of `class' */
68
static void test_deallocate (Class class)
69
{
70
  id object = class_createInstance (class, 0);
71
 
72
  object_dispose (object);
73
}
74
 
75
/* Test that the object and the class agree on what the class is */
76
static void test_object_class (Class class)
77
{
78
  id object = class_createInstance (class, 0);
79
 
80
  if (object_getClass (object) != class)
81
    {
82
      printf ("test_object_class failed\n");
83
      abort ();
84
    }
85
}
86
 
87
/*
88
 *  Runs all the tests in this file for the specified class
89
 */
90
void test_class_with_superclass (const char *class_name,
91
                                 const char *superclass_name)
92
{
93
  Class class;
94
  Class superclass;
95
 
96
  /* class_name must be an existing class */
97
  class = objc_getClass (class_name);
98
  test_is_class (class);
99
 
100
  /* But superclass_name can be "", which means `Nil' */
101
  superclass = objc_getClass (superclass_name);
102
  if (superclass != Nil)
103
    {
104
      test_is_class (superclass);
105
    }
106
 
107
  /* Now the tests */
108
  test_superclass (class, superclass);
109
  test_class_name (class, class_name);
110
  test_allocate (class);
111
  test_instances (class);
112
  test_deallocate (class);
113
  test_object_class (class);
114
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.