mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Added some tests that check that the runtime is doing the right thing with root
classes and metaclasses (or, at least, the same thing that the NeXT runtime does). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32325 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
59d4be1265
commit
29c6646667
1 changed files with 77 additions and 0 deletions
77
Tests/base/Functions/class_hierarchy.m
Normal file
77
Tests/base/Functions/class_hierarchy.m
Normal file
|
@ -0,0 +1,77 @@
|
|||
#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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a non-root class and its metaclass are in the correct place in the
|
||||
* hierarchy.
|
||||
*/
|
||||
void testNonRootClass(const char *clsName)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
testRootClass("NSObject");
|
||||
testRootClass("NSProxy");
|
||||
testRootClass("Bar");
|
||||
testNonRootClass("Foo");
|
||||
testNonRootClass("Foo2");
|
||||
testNonRootClass("Proxy");
|
||||
testNonRootClass("Proxy2");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue