Added thread test.

This commit is contained in:
Branimir Karadžić
2014-08-03 09:33:11 -07:00
parent ec2d1f8e93
commit d8ef558932
4 changed files with 52 additions and 1 deletions

View File

@@ -74,7 +74,7 @@
// #define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__)
#define BX_STATIC_ASSERT(_condition, ...) typedef char BX_CONCATENATE(BX_STATIC_ASSERT_, __LINE__)[1][(_condition)]
#define BX_CACHE_LINE_ALIGN_MARKER() BX_ALIGN_STRUCT(BX_CACHE_LINE_SIZE, struct) {}
#define BX_CACHE_LINE_ALIGN_MARKER() BX_ALIGN_STRUCT(BX_CACHE_LINE_SIZE, struct) BX_CONCATENATE(bx_cache_line_marker_compiler_stfu, __COUNTER__) {}
#define BX_CACHE_LINE_ALIGN(_def) BX_CACHE_LINE_ALIGN_MARKER(); _def; BX_CACHE_LINE_ALIGN_MARKER()
#define BX_ALIGN_STRUCT_16(_struct) BX_ALIGN_STRUCT(16, _struct)

View File

@@ -117,11 +117,19 @@ namespace bx
return result;
}
/// Skip _offset bytes forward.
inline int64_t skip(SeekerI* _seeker, int64_t _offset)
{
return _seeker->seek(_offset, Whence::Current);
}
/// Seek to any position in file.
inline int64_t seek(SeekerI* _seeker, int64_t _offset = 0, Whence::Enum _whence = Whence::Current)
{
return _seeker->seek(_offset, _whence);
}
/// Returns size of file.
inline int64_t getSize(SeekerI* _seeker)
{
int64_t offset = _seeker->seek();

View File

@@ -117,6 +117,11 @@ namespace bx
return m_running;
}
int32_t getExitCode() const
{
return m_exitCode;
}
private:
int32_t entry()
{

38
tests/thread.cpp Normal file
View File

@@ -0,0 +1,38 @@
/*
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "test.h"
#include <bx/thread.h>
int32_t threadExit0(void*)
{
return 0;
}
int32_t threadExit1(void*)
{
return 1;
}
TEST(thread)
{
bx::Thread th;
CHECK_EQUAL(th.isRunning(), false);
th.init(threadExit0);
CHECK_EQUAL(th.isRunning(), true);
th.shutdown();
CHECK_EQUAL(th.isRunning(), false);
CHECK_EQUAL(th.getExitCode(), 0);
th.init(threadExit1);
CHECK_EQUAL(th.isRunning(), true);
th.shutdown();
CHECK_EQUAL(th.isRunning(), false);
CHECK_EQUAL(th.getExitCode(), 1);
}