You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
1.0 KiB

  1. #define BOOST_TEST_DYN_LINK
  2. #define BOOST_TEST_NO_MAIN
  3. #ifdef HAVE_CONFIG_H
  4. #include "config.h"
  5. #endif
  6. #include <boost/test/unit_test.hpp>
  7. #include "mtasker.hh"
  8. BOOST_AUTO_TEST_SUITE(mtasker_cc)
  9. static int g_result;
  10. static void doSomething(void* p)
  11. {
  12. MTasker<>* mt = reinterpret_cast<MTasker<>*>(p);
  13. int i = 12, o;
  14. if (mt->waitEvent(i, &o) == 1)
  15. g_result = o;
  16. }
  17. BOOST_AUTO_TEST_CASE(test_Simple)
  18. {
  19. MTasker<> mt;
  20. mt.makeThread(doSomething, &mt);
  21. struct timeval now;
  22. gettimeofday(&now, 0);
  23. bool first = true;
  24. int o = 24;
  25. for (;;) {
  26. while (mt.schedule(&now))
  27. ;
  28. if (first) {
  29. mt.sendEvent(12, &o);
  30. first = false;
  31. }
  32. if (mt.noProcesses())
  33. break;
  34. }
  35. BOOST_CHECK_EQUAL(g_result, o);
  36. }
  37. static void willThrow(void* p)
  38. {
  39. throw std::runtime_error("Help!");
  40. }
  41. BOOST_AUTO_TEST_CASE(test_MtaskerException)
  42. {
  43. BOOST_CHECK_THROW({
  44. MTasker<> mt;
  45. mt.makeThread(willThrow, 0);
  46. struct timeval now;
  47. for (;;) {
  48. mt.schedule(&now);
  49. }
  50. },
  51. std::exception);
  52. }
  53. BOOST_AUTO_TEST_SUITE_END()