"Fossies" - the Fresh Open Source Software Archive

Member "pdns-auth-4.2.0/pdns/recursordist/test-mtasker.cc" (27 Aug 2019, 1111 Bytes) of package /linux/misc/dns/pdns-auth-4.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "test-mtasker.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.13_vs_4.2.0.

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