classname.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // TEST_CONFIG
  2. #include "test.h"
  3. #include "testroot.i"
  4. #include <string.h>
  5. #include <objc/runtime.h>
  6. @interface Fake : TestRoot @end
  7. @implementation Fake @end
  8. int main()
  9. {
  10. TestRoot *obj = [TestRoot new];
  11. Class __unsafe_unretained * buf = (Class *)(__bridge void *)(obj);
  12. *buf = [Fake class];
  13. testassert(object_getClass(obj) == [Fake class]);
  14. testassert(object_setClass(obj, [TestRoot class]) == [Fake class]);
  15. testassert(object_getClass(obj) == [TestRoot class]);
  16. testassert(object_setClass(nil, [TestRoot class]) == nil);
  17. testassert(malloc_size(buf) >= sizeof(id));
  18. bzero(buf, malloc_size(buf));
  19. testassert(object_setClass(obj, [TestRoot class]) == nil);
  20. testassert(object_getClass(obj) == [TestRoot class]);
  21. testassert(object_getClass([TestRoot class]) == object_getClass([TestRoot class]));
  22. testassert(object_getClass(nil) == Nil);
  23. testassert(0 == strcmp(object_getClassName(obj), "TestRoot"));
  24. testassert(0 == strcmp(object_getClassName([TestRoot class]), "TestRoot"));
  25. testassert(0 == strcmp(object_getClassName(nil), "nil"));
  26. testassert(0 == strcmp(class_getName([TestRoot class]), "TestRoot"));
  27. testassert(0 == strcmp(class_getName(object_getClass([TestRoot class])), "TestRoot"));
  28. testassert(0 == strcmp(class_getName(nil), "nil"));
  29. succeed(__FILE__);
  30. }