foobar2000 SDK  2015-08-03
selftest.cpp
Go to the documentation of this file.
1 #include "pfc.h"
2 
3 
4 namespace {
5  class foo {};
6 }
7 
8 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,foo p_source) {p_fmt.add_string_("FOO"); return p_fmt;}
9 
10 namespace {
11  using namespace pfc;
12  class thread_selftest : public thread {
13  public:
14  void threadProc() {
15  pfc::event ev;
16  ev.wait_for(1);
17  m_event.set_state(true);
18  ev.wait_for(1);
19  }
20  pfc::event m_event;
21 
22  void selftest() {
23  lores_timer timer; timer.start();
24  this->start();
25  if (!m_event.wait_for(-1)) {
26  PFC_ASSERT(!"Should not get here");
27  return;
28  }
29  PFC_ASSERT(fabs(timer.query() - 1.0) < 0.1);
30  this->waitTillDone();
31  PFC_ASSERT(fabs(timer.query() - 2.0) < 0.1);
32  }
33  };
34 }
35 
36 namespace pfc {
37 
38 
39 
40  // Self test routines that need to be executed to do their payload
42  {
43  thread_selftest t; t.selftest();
44  }
45 
46  }
47  // Self test routines that fail at compile time if there's something seriously wrong
48  void selftest_static() {
49  PFC_STATIC_ASSERT(sizeof(t_uint8) == 1);
50  PFC_STATIC_ASSERT(sizeof(t_uint16) == 2);
51  PFC_STATIC_ASSERT(sizeof(t_uint32) == 4);
52  PFC_STATIC_ASSERT(sizeof(t_uint64) == 8);
53 
54  PFC_STATIC_ASSERT(sizeof(t_int8) == 1);
55  PFC_STATIC_ASSERT(sizeof(t_int16) == 2);
56  PFC_STATIC_ASSERT(sizeof(t_int32) == 4);
57  PFC_STATIC_ASSERT(sizeof(t_int64) == 8);
58 
59  PFC_STATIC_ASSERT(sizeof(t_float32) == 4);
60  PFC_STATIC_ASSERT(sizeof(t_float64) == 8);
61 
62  PFC_STATIC_ASSERT(sizeof(t_size) == sizeof(void*));
63  PFC_STATIC_ASSERT(sizeof(t_ssize) == sizeof(void*));
64 
65  PFC_STATIC_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4);
66 
67  PFC_STATIC_ASSERT(sizeof(GUID) == 16);
68 
69  typedef pfc::avltree_t<int> t_asdf;
70  t_asdf asdf; asdf.add_item(1);
71  t_asdf::iterator iter = asdf._first_var();
72  t_asdf::const_iterator iter2 = asdf._first_var();
73 
74  PFC_string_formatter() << "foo" << 1337 << foo();
75 
76  pfc::list_t<int> l; l.add_item(3);
77  }
78 
79  void selftest() {
81 
82  debugLog out; out << "PFC selftest OK";
83  }
84 }
uint8_t t_uint8
Definition: int_types.h:9
void start()
Definition: timers.h:93
Definition: pfc.h:71
uint64_t t_uint64
Definition: int_types.h:3
void selftest_static()
Definition: selftest.cpp:48
int16_t t_int16
Definition: int_types.h:6
double t_float64
Definition: int_types.h:15
int32_t t_int32
Definition: int_types.h:4
IMPORTANT: all classes derived from thread must call waitTillDone() in their destructor, to avoid object destruction during a virtual function call!
Definition: threads.h:11
size_t t_size
Definition: int_types.h:48
uint16_t t_uint16
Definition: int_types.h:7
void selftest()
Definition: selftest.cpp:79
t_storage & add_item(t_param const &p_item)
Definition: avltree.h:380
void selftest_runtime()
Definition: selftest.cpp:41
double query() const
Definition: timers.h:97
pfc::sized_int_t< sizeof(size_t) >::t_signed t_ssize
Definition: int_types.h:49
bool wait_for(double p_timeout_seconds)
Returns true when signaled, false on timeout.
Definition: win-objects.h:139
void add_string_(const char *str)
Definition: string_base.h:39
float t_float32
Definition: int_types.h:14
uint32_t t_uint32
Definition: int_types.h:5
int64_t t_int64
Definition: int_types.h:2
int8_t t_int8
Definition: int_types.h:8
pfc::string_base & operator<<(pfc::string_base &p_fmt, foo p_source)
Definition: selftest.cpp:8