libs-base/Tests/base/Functions/class_hierarchy.m
Richard Frith-MacDonald e6dc5a58b6 Important change to the START_SET and END_SET macros to stop their use
being confusing.  They now both take a simple C-string argument which
names the set, and the macros check that each end matches a start of
the same name.  Since tis means that a START_SET no longer takes an
argument sayng whether or notthe set is to be skipped, we now have a
SKIP macro to be used inside a set to skip to the end of it.  This
is actually more versatile as we can have multiple SKIP macros in the
same set, each providing a different reason for the set being skipped.
Also removed a few obsolete/unused functions and macros.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32355 72102866-910b-0410-8b05-ffd578937521
2011-02-24 16:26:01 +00:00

88 lines
2.4 KiB
Objective-C

#import "Testing.h"
#import <Foundation/Foundation.h>
// OS X doesn't seem to provide all of the runtime functions by default.
#ifndef GNUSTEP
# include <objc/runtime.h>
#endif
// Simple root class - test that the runtime does the right thing with new
// roots
@interface Bar { id isa; } @end
@implementation Bar @end
// Some simple classes that inherit from root classes in Foundation. Test that
// they go in the right places in the runtime.
@interface Foo : NSObject @end
@implementation Foo @end
@interface Foo2 : Foo @end
@implementation Foo2 @end
@interface Proxy : NSProxy @end
@implementation Proxy @end
@interface Proxy2 : Proxy @end
@implementation Proxy2 @end
/**
* Tests a root class has its superclass and metaclass correctly configured
*/
void testRootClass(const char *clsName)
{
testHopeful = YES;
START_SET("testRootClass")
Class cls = objc_getClass(clsName);
Class super = class_getSuperclass(cls);
Class meta = object_getClass(cls);
Class superMeta = class_getSuperclass(meta);
Class metaMeta = object_getClass(meta);
PASS(Nil == super, "superclass of root class is Nil");
PASS(metaMeta == meta,
"root class's metaclass is also its metaclass's metaclass");
PASS(cls == superMeta, "Root class is its metaclass's superclass");
END_SET("testRootClass")
}
/**
* Tests a non-root class and its metaclass are in the correct place in the
* hierarchy.
*/
void testNonRootClass(const char *clsName)
{
testHopeful = YES;
START_SET("testNonRootClass")
Class cls = objc_getClass(clsName);
Class super = class_getSuperclass(cls);
Class meta = object_getClass(cls);
Class superMeta = class_getSuperclass(meta);
Class metaMeta = object_getClass(meta);
Class metaSuper = object_getClass(super);
Class root = super;
Class rootMeta = Nil;
do
{
rootMeta = object_getClass(root);
root = class_getSuperclass(root);
} while (root != Nil);
PASS(Nil != super, "Non-root class has a superclass");
PASS(superMeta == metaSuper,
"Metaclass's superclass is superclass's metaclass");
PASS(rootMeta == metaMeta,
"Metaclass's metaclass is root class's metaclass");
END_SET("testNonRootClass")
}
int main(void)
{
testRootClass("NSObject");
testRootClass("NSProxy");
testRootClass("Bar");
testNonRootClass("Foo");
testNonRootClass("Foo2");
testNonRootClass("Proxy");
testNonRootClass("Proxy2");
return 0;
}