/*
|
/*
|
load-3.m
|
load-3.m
|
|
|
Author: Ovidiu Predescu <ovidiu@cup.hp.com>
|
Author: Ovidiu Predescu <ovidiu@cup.hp.com>
|
Date: June 3, 2001
|
Date: June 3, 2001
|
|
|
Test if the +load methods are invoked, and are invoked in the
|
Test if the +load methods are invoked, and are invoked in the
|
proper order.
|
proper order.
|
*/
|
*/
|
|
|
#include <objc/objc.h>
|
#include <objc/objc.h>
|
#include <objc/Object.h>
|
#include <objc/Object.h>
|
|
|
@interface A : Object
|
@interface A : Object
|
@end
|
@end
|
|
|
@interface B : A
|
@interface B : A
|
@end
|
@end
|
|
|
static a_load = 0;
|
static a_load = 0;
|
static b_load = 0;
|
static b_load = 0;
|
static a_category_load = 0;
|
static a_category_load = 0;
|
static b_category_load = 0;
|
static b_category_load = 0;
|
|
|
@implementation A (Category)
|
@implementation A (Category)
|
+ (void)load
|
+ (void)load
|
{
|
{
|
a_category_load = 1;
|
a_category_load = 1;
|
printf("+[A(Category) load]\n");
|
printf("+[A(Category) load]\n");
|
|
|
if (a_load != 1)
|
if (a_load != 1)
|
{
|
{
|
printf("+load for A(Category) invoked before A's!\n");
|
printf("+load for A(Category) invoked before A's!\n");
|
abort();
|
abort();
|
}
|
}
|
}
|
}
|
@end
|
@end
|
|
|
@implementation B(Category)
|
@implementation B(Category)
|
+ (void)load
|
+ (void)load
|
{
|
{
|
b_category_load = 1;
|
b_category_load = 1;
|
printf("+[B(Category) load]\n");
|
printf("+[B(Category) load]\n");
|
|
|
if (b_load != 1)
|
if (b_load != 1)
|
{
|
{
|
printf ("+load for B(Category) invoked before B!\n");
|
printf ("+load for B(Category) invoked before B!\n");
|
abort();
|
abort();
|
}
|
}
|
}
|
}
|
@end
|
@end
|
|
|
@implementation B
|
@implementation B
|
+ (void)load
|
+ (void)load
|
{
|
{
|
b_load = 1;
|
b_load = 1;
|
printf("+[B load]\n");
|
printf("+[B load]\n");
|
|
|
if (a_load != 1)
|
if (a_load != 1)
|
{
|
{
|
printf("+load for B invoked before A's!\n");
|
printf("+load for B invoked before A's!\n");
|
abort();
|
abort();
|
}
|
}
|
|
|
if (b_category_load != 0)
|
if (b_category_load != 0)
|
{
|
{
|
printf("+load for B invoked after B(Category)!\n");
|
printf("+load for B invoked after B(Category)!\n");
|
abort();
|
abort();
|
}
|
}
|
}
|
}
|
@end
|
@end
|
|
|
@implementation A
|
@implementation A
|
+ (void)load
|
+ (void)load
|
{
|
{
|
a_load = 1;
|
a_load = 1;
|
printf("+[A load]\n");
|
printf("+[A load]\n");
|
|
|
if (a_category_load != 0)
|
if (a_category_load != 0)
|
{
|
{
|
printf("+load for A(Category) invoked before A!\n");
|
printf("+load for A(Category) invoked before A!\n");
|
abort();
|
abort();
|
}
|
}
|
|
|
if (b_load != 0)
|
if (b_load != 0)
|
{
|
{
|
printf("+load for A invoked after B!\n");
|
printf("+load for A invoked after B!\n");
|
abort();
|
abort();
|
}
|
}
|
|
|
if (b_category_load != 0)
|
if (b_category_load != 0)
|
{
|
{
|
printf("+load for B(Category) invoked before A and B!\n");
|
printf("+load for B(Category) invoked before A and B!\n");
|
abort();
|
abort();
|
}
|
}
|
}
|
}
|
@end
|
@end
|
|
|
int main (void)
|
int main (void)
|
{
|
{
|
if (a_load + b_load + a_category_load + b_category_load != 4)
|
if (a_load + b_load + a_category_load + b_category_load != 4)
|
{
|
{
|
printf("Not all +load methods invoked!\n");
|
printf("Not all +load methods invoked!\n");
|
abort();
|
abort();
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|