Hi Guys,

I wrote a simple test for NSThread to be run through a googletest
framework, this passes on OSX but just hangs on GNUStep:

#import "Foundation/NSThread.h"

class NSThreadTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
  // Tried with and without this
  GSRegisterCurrentThread();
  mainTid = pthread_self();
  }
public:
pthread_t mainTid;
};

pthread_t backgroundTid;
@interface BackgroundThread : NSObject
- (void) run:(NSObject*) thread;
@end

@implementation BackgroundThread
- (void) run:(NSObject*) thread
{
backgroundTid = pthread_self();
}
@end

TEST_F(NSThreadTest, TestsAreOnSameThread)
{
    EXPECT_EQ(mainTid, pthread_self());
}

TEST_F(NSThreadTest, BackgroundThreadNotMainThread)
{
    BackgroundThread* backThread = [[BackgroundThread alloc]init];
    backgroundTid = 0;
    [backThread performSelectorInBackground:@selector(run:)
withObject:backThread];
    while(backgroundTid == 0)
        sleep(1);

    EXPECT_NE(mainTid, backgroundTid);
}

Any thoughts on what I'm doing wrong?
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to