Exemplo n.º 1
0
int main()
{
  async_foo(false, handler1);
  async_foo(true, handler1);

  async_foo(false, &handler1);
  async_foo(true, &handler1);

  async_foo(false, handler2());
  async_foo(true, handler2());

  handler2 h1;
  async_foo(false, h1);
  async_foo(true, h1);

  const handler2 h2;
  async_foo(false, h2);
  async_foo(true, h2);

  async_foo(false, handler3());
  async_foo(true, handler3());

  handler3 h3, h4;
  async_foo(false, std::move(h3));
  async_foo(true, std::move(h4));

  async_foo(false, [](std::error_code e, int, int){ e ? ++fail_count : ++success_count; });
  async_foo(true, [](std::error_code e, int, int){ e ? ++fail_count : ++success_count; });

  std::future<std::tuple<int, int>> f1 = async_foo(false, std::use_future);
  try
  {
    f1.get();
    ++success_count;
  }
  catch (...)
  {
    ++fail_count;
  }

  std::future<std::tuple<int, int>> f2 = async_foo(true, std::use_future);
  try
  {
    f2.get();
    ++success_count;
  }
  catch (...)
  {
    ++fail_count;
  }

  assert(success_count == 9);
  assert(fail_count == 9);
}
Exemplo n.º 2
0
int main()
{
  async_foo(handler1);

  async_foo(&handler1);

  async_foo(handler2());

  handler2 h1;
  async_foo(h1);

  const handler2 h2;
  async_foo(h2);

  async_foo(handler3());

  handler3 h3;
  async_foo(std::move(h3));

  async_foo([](int){ ++success_count; });

  std::future<int> f = async_foo(std::use_future);
  int v = f.get();
  assert(v == 1);
  ++success_count;

  assert(success_count == 9);
}
Exemplo n.º 3
0
int main()
{
    flinter::Logger::SetFilter(flinter::Logger::kLevelVerbose);
    signals_ignore(SIGPIPE);

    Handler handler1("1");
    Handler handler2("2");
    flinter::EasyServer s;
    g_server = &s;

    if (!s.Listen(5566, &handler1)) {
        return EXIT_FAILURE;
    }

    if (!s.Listen(5567, &handler2)) {
        return EXIT_FAILURE;
    }

    if (!s.Initialize(3, 7)) {
        return EXIT_FAILURE;
    }

    msleep(10000);
    s.Shutdown();
    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
MojErr MojSignalTest::test2()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add2Slot(handler1->m_slot2);
	MojTestAssert(handler1->refCount() == 2);
	source->fire2(200, "hello");
	MojTestAssert(handler1->m_handle2Count == 1);
	MojTestAssert(handler1->m_lastInt == 200);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello"));
	MojTestAssert(handler1->refCount() == 1);
	source->fire2(200, "hello");
	MojTestAssert(handler1->m_handle2Count == 1);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add2Slot(handler1->m_slot2);
	source->add2Slot(handler2->m_slot2);
	source->fire2(201, "hello2");
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 201);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello2"));
	// cancel
	source->add2Slot(handler1->m_slot2);
	source->add2Slot(handler2->m_slot2);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot2.cancel();
	source->fire2(202, "hello3");
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 202);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello3"));
	// cancel from callback
	source->add2Slot(handler2->m_slot2);
	source->add2Slot(handler1->m_slot2Cancel);
	source->fire2(203, "hello4");
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 203);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello4"));
	source->add2Slot(handler2->m_slot2);
	source->fire2(204, "hello5");
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 204);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello5"));

	return MojErrNone;
}
Exemplo n.º 5
0
MojErr MojSignalTest::test3()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add3Slot(handler1->m_slot3);
	MojTestAssert(handler1->refCount() == 2);
	source->fire3(200, "hello", 1.0);
	MojTestAssert(handler1->m_handle3Count == 1);
	MojTestAssert(handler1->m_lastInt == 200 && handler1->m_lastDouble == 1.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello"));
	MojTestAssert(handler1->refCount() == 1);
	source->fire3(200, "hello", 1.0);
	MojTestAssert(handler1->m_handle3Count == 1);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add3Slot(handler1->m_slot3);
	source->add3Slot(handler2->m_slot3);
	source->fire3(201, "hello2", 2.0);
	MojTestAssert(handler1->m_lastInt == 201 && handler1->m_lastDouble == 2.0);
	MojTestAssert(handler2->m_lastInt == 201 && handler2->m_lastDouble == 2.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello2"));
	// cancel
	source->add3Slot(handler1->m_slot3);
	source->add3Slot(handler2->m_slot3);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot3.cancel();
	source->fire3(202, "hello3", 3.0);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 201 && handler1->m_lastDouble == 2.0);
	MojTestAssert(handler2->m_lastInt == 202 && handler2->m_lastDouble == 3.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello3"));
	// cancel from callback
	source->add3Slot(handler1->m_slot3Cancel);
	source->add3Slot(handler2->m_slot3);
	source->fire3(203, "hello4", 4.0);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 203 && handler1->m_lastDouble == 4.0);
	MojTestAssert(handler2->m_lastInt == 203 && handler2->m_lastDouble == 4.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello4"));
	source->add3Slot(handler2->m_slot3);
	source->fire3(204, "hello5", 5.0);
	MojTestAssert(handler1->m_lastInt == 203 && handler1->m_lastDouble == 4.0);
	MojTestAssert(handler2->m_lastInt == 204 && handler2->m_lastDouble == 5.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello5"));

	return MojErrNone;
}
Exemplo n.º 6
0
MojErr MojSignalTest::test1()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add1Slot(handler1->m_slot1);
	MojTestAssert(handler1->refCount() == 2);
	source->fire1(200);
	MojTestAssert(handler1->m_handle1Count == 1);
	MojTestAssert(handler1->m_lastInt == 200);
	MojTestAssert(handler1->refCount() == 1);
	source->fire1(200);
	MojTestAssert(handler1->m_handle1Count == 1);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add1Slot(handler1->m_slot1);
	source->add1Slot(handler2->m_slot1);
	source->fire1(201);
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 201);
	// cancel
	source->add1Slot(handler1->m_slot1);
	source->add1Slot(handler2->m_slot1);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot1.cancel();
	source->fire1(202);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 202);
	// cancel from callback
	source->add1Slot(handler1->m_slot1Cancel);
	source->add1Slot(handler2->m_slot1);
	source->fire1(203);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 203);
	source->add1Slot(handler2->m_slot1);
	source->fire1(204);
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 204);

	return MojErrNone;
}
Exemplo n.º 7
0
// Listing 3 code/ch12
int ACE_TMAIN (int, ACE_TCHAR *[])
{
  HA_Device_Repository rep;
  ACE_Thread_Mutex rep_mutex;

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Condition<ACE_Thread_Mutex> wait (rep_mutex);
  //FUZZ: enable check_for_lack_ACE_OS

  HA_CommandHandler handler1 (rep, wait, rep_mutex);
  HA_CommandHandler handler2 (rep, wait, rep_mutex);

  handler1.activate ();
  handler2.activate ();

  handler1.wait ();
  handler2.wait ();

  return 0;
}
Exemplo n.º 8
0
TEST(Log, StdoutLogMsgHandler)
{
    LogControl logControl;
    EXPECT_TRUE(logControl.highestLogLevel() == Log::NONE);

    StdoutLogMsgHandler handler;
    logControl.registerMsgHandler(&handler);
    TestUtilLogControlSwap swap(&logControl);

    EXPECT_TRUE(logControl.highestLogLevel() == Log::DEBUG);

    // --
    TRACE("trace message" << "OK");
    DEBUG("debug message");
    INFO("info message");

    StdoutLogMsgHandler handler2(Log::TRACE);
    logControl.registerMsgHandler(&handler2);
    EXPECT_TRUE(logControl.highestLogLevel() == Log::TRACE);

    swap.restore();
}
void UT_LifeTimerKeySequenceHandler::t_keySequenceValidator()
{
    // life timer feature enabled scenario
    EXPECT(CRepository, Get)
        .willOnce(invoke(this, setLifeTimerData))
        .returns(KErrNone);
    expect("KeySequenceHandler::setKeySequenceValidator")
        .with(QRegExp::escape(KCodeLifeTimer));
    
    QScopedPointer<LifeTimerKeySequenceHandler> handler1(
        new LifeTimerKeySequenceHandler());
    
    QVERIFY(verify());
    
    // life timer feature not enabled scenario
    EXPECT(CRepository, Get).returns(KErrNotFound);
    expect("KeySequenceHandler::setKeySequenceValidator").times(0);
    
    QScopedPointer<LifeTimerKeySequenceHandler> handler2(
        new LifeTimerKeySequenceHandler());
    
    QVERIFY(verify());
}
Exemplo n.º 10
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::post(function1);
  std::experimental::post(function1, handler1);
  std::experimental::post(function1, &handler1);
  std::experimental::post(function1, handler2());
  std::experimental::post(function1, h2);
  std::experimental::post(function1, ch2);
  std::experimental::post(function1, handler3());
  std::experimental::post(function1, std::move(h3));
  std::future<int> fut1 = std::experimental::post(function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(&function1);
  std::experimental::post(&function1, handler1);
  std::experimental::post(&function1, &handler1);
  std::experimental::post(&function1, handler2());
  std::experimental::post(&function1, h2);
  std::experimental::post(&function1, ch2);
  std::experimental::post(&function1, handler3());
  std::experimental::post(&function1, std::move(h3));
  std::future<int> fut2 = std::experimental::post(&function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(function2());
  std::experimental::post(function2(), handler1);
  std::experimental::post(function2(), &handler1);
  std::experimental::post(function2(), handler2());
  std::experimental::post(function2(), h2);
  std::experimental::post(function2(), ch2);
  std::experimental::post(function2(), handler3());
  std::experimental::post(function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::post(function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(f2);
  std::experimental::post(f2, handler1);
  std::experimental::post(f2, &handler1);
  std::experimental::post(f2, handler2());
  std::experimental::post(f2, h2);
  std::experimental::post(f2, ch2);
  std::experimental::post(f2, handler3());
  std::experimental::post(f2, std::move(h3));
  std::future<int> fut4 = std::experimental::post(f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(cf2);
  std::experimental::post(cf2, handler1);
  std::experimental::post(cf2, &handler1);
  std::experimental::post(cf2, handler2());
  std::experimental::post(cf2, h2);
  std::experimental::post(cf2, ch2);
  std::experimental::post(cf2, handler3());
  std::experimental::post(cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::post(cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(function3());
  std::experimental::post(function3(), handler1);
  std::experimental::post(function3(), &handler1);
  std::experimental::post(function3(), handler2());
  std::experimental::post(function3(), h2);
  std::experimental::post(function3(), ch2);
  std::experimental::post(function3(), handler3());
  std::experimental::post(function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::post(function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(std::move(f3));
  std::experimental::post(std::move(f3), handler1);
  std::experimental::post(std::move(f3), &handler1);
  std::experimental::post(std::move(f3), handler2());
  std::experimental::post(std::move(f3), h2);
  std::experimental::post(std::move(f3), ch2);
  std::experimental::post(std::move(f3), handler3());
  std::experimental::post(std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::post(std::move(f3), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 63);
  assert(handler_count == 49);

  std::future<int> fut8 = std::experimental::post(function_throw, std::experimental::use_future);
  try
  {
    fut8.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }

  std::future<int> fut9 = std::experimental::post(std::experimental::package(function_throw));
  try
  {
    fut9.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }
}
Exemplo n.º 11
0
    void TestHandler() throw(Exception)
    {
        // Test that CHASTE_TEST_OUTPUT always has a trailing slash even before
        // a class object is instantiated
        const std::string chaste_test_output(OutputFileHandler::GetChasteTestOutputDirectory());
        TS_ASSERT_EQUALS( *(chaste_test_output.end()-1), '/');

        // Make a handler that points straight to the CHASTE_TEST_OUTPUT directory.
        OutputFileHandler handler("");
        const std::string handler_path(handler.GetOutputDirectoryFullPath());
        TS_ASSERT(handler_path.length() > 0);
        TS_ASSERT_EQUALS(handler_path, handler.GetChasteTestOutputDirectory());
        TS_ASSERT_EQUALS(handler.GetRelativePath(), "");

        // Test that CHASTE_TEST_OUTPUT always has a trailing slash
        TS_ASSERT_EQUALS( *(handler_path.end()-1), '/');

        // Make a handler that points to a sub-directory.
        std::string dir = "testhandler";
        OutputFileHandler handler2(dir);
        std::string full_dir = handler2.GetOutputDirectoryFullPath();
        TS_ASSERT_EQUALS(full_dir.substr(full_dir.length()-dir.length()-1), dir+"/");
        TS_ASSERT_EQUALS(full_dir.substr(0, full_dir.length()-dir.length()-1), handler_path);
        TS_ASSERT_EQUALS(handler2.GetRelativePath(), dir);

        // We can also create handlers from a FileFinder (provided it points to a location in CHASTE_TEST_OUTPUT)
        OutputFileHandler handler3(handler.FindFile("testhandler2"));
        full_dir = handler3.GetOutputDirectoryFullPath();
        TS_ASSERT_EQUALS(full_dir.substr(full_dir.length()-dir.length()-2), dir+"2/");
        TS_ASSERT_EQUALS(full_dir.substr(0, full_dir.length()-dir.length()-2), handler_path);
        TS_ASSERT_EQUALS(handler3.GetRelativePath(), "testhandler2");

        // Check that all three handlers can create files
        out_stream p_file_stream;
        p_file_stream = handler.OpenOutputFile("test_file", std::ios::out);
        TS_ASSERT(FileFinder(handler_path + "test_file").Exists());

        p_file_stream = handler.OpenOutputFile("test_file2");
        TS_ASSERT(FileFinder(handler_path + "test_file2").Exists());

        p_file_stream = handler2.OpenOutputFile("test_file");
        TS_ASSERT(FileFinder(handler2.GetOutputDirectoryFullPath() + "test_file").Exists());

        p_file_stream = handler2.OpenOutputFile("test_", 34, ".txt");
        TS_ASSERT(FileFinder(handler2.GetOutputDirectoryFullPath() + "test_34.txt").Exists());

        p_file_stream = handler3.OpenOutputFile("test_file");
        TS_ASSERT(FileFinder(handler3.GetOutputDirectoryFullPath() + "test_file").Exists());

        // This should try to write files to /, which isn't allowed (we hope!)
        TS_ASSERT_THROWS_CONTAINS(OutputFileHandler bad_handler("../../../../../../../../../../../../../../../", false),
                                  "due to it potentially being above, and cleaning, CHASTE_TEST_OUTPUT.");
        TS_ASSERT_THROWS_CONTAINS(OutputFileHandler bad_handler("/", false),
                                  "The constructor argument to OutputFileHandler must be a relative path");
        TS_ASSERT_THROWS_CONTAINS(OutputFileHandler bad_handler(FileFinder("/"), false),
                                  "The location provided to OutputFileHandler must be inside CHASTE_TEST_OUTPUT");

        // Check the CopyFileTo method
        FileFinder source_file("global/test/TestOutputFileHandler.hpp", RelativeTo::ChasteSourceRoot);
        TS_ASSERT(!handler2.FindFile("TestOutputFileHandler.hpp").Exists());
        PetscTools::Barrier("TestOutputFileHandler-0");
        FileFinder dest_file = handler2.CopyFileTo(source_file);
        TS_ASSERT(dest_file.Exists());
        FileFinder missing_file("global/no_file", RelativeTo::ChasteSourceRoot);
        TS_ASSERT_THROWS_CONTAINS(handler2.CopyFileTo(missing_file), "Can only copy single files");
        FileFinder global_dir("global", RelativeTo::ChasteSourceRoot);
        TS_ASSERT_THROWS_CONTAINS(handler2.CopyFileTo(global_dir), "Can only copy single files");

        // We don't want other people using CHASTE_TEST_OUTPUT whilst we are messing with it!
        PetscTools::Barrier("TestOutputFileHandler-1");

        // Test that the environment variable actually influences the location of files
        {
            setenv("CHASTE_TEST_OUTPUT", "", 1/*Overwrite*/);
            // Check this folder is not present
            FileFinder test_folder("testoutput/whatever", RelativeTo::ChasteSourceRoot);
            TS_ASSERT(!test_folder.Exists());

            PetscTools::Barrier("TestOutputFileHandler-2");

            // Make a folder and erase it - NB only master can erase files and check it is successful!
            OutputFileHandler handler4("whatever");
            TS_ASSERT(test_folder.Exists());
            PetscTools::Barrier("TestOutputFileHandler-2b");
            if (PetscTools::AmMaster())
            {
                test_folder.Remove();
                // If we've not written anything else to the testoutput folder, remove that too
                // rather than leaving an empty folder lieing around in the source tree!
                FileFinder output_root("", RelativeTo::ChasteTestOutput);
                if (output_root.IsEmpty())
                {
                    output_root.DangerousRemove();
                }
            }
            PetscTools::Barrier("TestOutputFileHandler-2c");
        }

        {
            setenv("CHASTE_TEST_OUTPUT", "config__cyborg__T800__cooper", 1/*Overwrite*/);
            // Test that CHASTE_TEST_OUTPUT always has a trailing slash even before
            // a class object is instantiated and when the directory does not exist
            const std::string nonexistent_test_path(OutputFileHandler::GetChasteTestOutputDirectory());
            TS_ASSERT_EQUALS( *(nonexistent_test_path.end()-1), '/');
        }

        {
            // Check this folder is not present
            std::string test_folder("somewhere_without_trailing_forward_slash");
            TS_ASSERT(!FileFinder(test_folder, RelativeTo::CWD).Exists());
            PetscTools::Barrier("TestOutputFileHandler-3");

            setenv("CHASTE_TEST_OUTPUT", test_folder.c_str(), 1/*Overwrite*/);

            // Make a folder using a FileFinder, for coverage of the case where the root output folder doesn't exist
            FileFinder sub_folder("test_folder", RelativeTo::ChasteTestOutput);
            TS_ASSERT(!sub_folder.Exists());
            PetscTools::Barrier("TestOutputFileHandler-3a");
            OutputFileHandler creating_handler(sub_folder);
            TS_ASSERT(sub_folder.Exists());

            // Make a folder
            OutputFileHandler handler5("whatever");
            TS_ASSERT(FileFinder(test_folder, RelativeTo::CWD).Exists());
            PetscTools::Barrier("TestOutputFileHandler-3b");

            // Erase it
            if (PetscTools::AmMaster())
            {
                FileFinder(test_folder).DangerousRemove();
            }
        }

        // Reset the location of CHASTE_TEST_OUTPUT
        setenv("CHASTE_TEST_OUTPUT", chaste_test_output.c_str(), 1/*Overwrite*/);

        // We don't want other people using CHASTE_TEST_OUTPUT while we are messing with it!
        PetscTools::Barrier("TestOutputFileHandler-4");

        // Coverage of the case where we can't open a file for writing
        OutputFileHandler handler6("no_write_access");
        if (PetscTools::AmMaster())
        {
            std::string dir_path =  handler6.GetOutputDirectoryFullPath();
#ifndef _MSC_VER
            // This test can never pass on modern Windows OS! See: http://support.microsoft.com/kb/326549
            // You can't change DIRECTORY attributes
            chmod(dir_path.c_str(), CHASTE_READONLY);
            TS_ASSERT_THROWS_CONTAINS(p_file_stream = handler6.OpenOutputFile("test_file"),
                                      "Could not open file");
#endif
            chmod(dir_path.c_str(), CHASTE_READ_WRITE_EXECUTE);
            fs::remove(dir_path + ".chaste_deletable_folder");
            fs::remove(dir_path);
        }

        // Check behaviour of FindFile("")
        FileFinder handler_self = handler.FindFile("");
        TS_ASSERT_EQUALS(handler_self.GetAbsolutePath(), handler.GetOutputDirectoryFullPath());
    }
Exemplo n.º 12
0
    void TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves() throw(Exception, std::exception)
    {
        std::string test_folder = "cannot_delete_me";
        if (PetscTools::AmMaster())
        {
            ABORT_IF_THROWS(fs::create_directories(OutputFileHandler::GetChasteTestOutputDirectory() + test_folder));
        }
        // Wait until directory has been created, and check it exists
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-1");
        FileFinder cannot_delete(test_folder, RelativeTo::ChasteTestOutput);
        TS_ASSERT(cannot_delete.IsDir());

        // Try to use it as an output folder
        TS_ASSERT_THROWS_CONTAINS(OutputFileHandler bad_handler(test_folder),
                                  "because signature file \".chaste_deletable_folder\" is not present");

        // Tidy up
        if (PetscTools::AmMaster())
        {
            TS_ASSERT(cannot_delete.Exists());
            cannot_delete.DangerousRemove();
            TS_ASSERT(!cannot_delete.Exists());
        }

        // Now create a folder the proper way
        test_folder = "can_delete_me";
        OutputFileHandler handler(test_folder);
        out_stream p_file_stream = handler.OpenOutputFile("test_file");
        p_file_stream->close(); // Windows does not like deleting open files

        // Test file is present
        FileFinder test_file = handler.FindFile("test_file");
        TS_ASSERT(test_file.Exists());
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-2");

        OutputFileHandler handler2(test_folder, false /* don't clean */);

        // Test file is still present
        TS_ASSERT(test_file.Exists());
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-3");

        OutputFileHandler handler3(test_folder, true /* do clean */);

        // Test file is deleted
        TS_ASSERT(!test_file.Exists());
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-4");

        // Check we can delete the test_folder too
        if (PetscTools::AmMaster())
        {
            FileFinder folder = handler.FindFile("");
            TS_ASSERT(folder.Exists());
            folder.Remove();
            TS_ASSERT(!folder.Exists());
        }

        // Test we can make a directory of folders and delete them all
        OutputFileHandler handler4("what_about_me/and_me/and_me/and_da_da_da", true);

        // Check we have made a subdirectory
        FileFinder sub_folder("what_about_me/and_me", RelativeTo::ChasteTestOutput);
        TS_ASSERT(sub_folder.IsDir());
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-5");

        OutputFileHandler handler5("what_about_me", true);

        // Check we have wiped the sub-directories
        TS_ASSERT(!sub_folder.Exists());
        PetscTools::Barrier("TestWeCanOnlyDeleteFoldersWeHaveMadeOurselves-6");

        // Check we can delete the main directory too
        if (PetscTools::AmMaster())
        {
            FileFinder folder = handler5.FindFile("");
            TS_ASSERT(folder.Exists());
            folder.Remove();
            TS_ASSERT(!folder.Exists());
        }
    }
Exemplo n.º 13
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::system_executor ex;

  std::experimental::dispatch(ex.wrap(function1), handler1);
  std::experimental::dispatch(ex.wrap(function1), &handler1);
  std::experimental::dispatch(ex.wrap(function1), handler2());
  std::experimental::dispatch(ex.wrap(function1), h2);
  std::experimental::dispatch(ex.wrap(function1), ch2);
  std::experimental::dispatch(ex.wrap(function1), handler3());
  std::experimental::dispatch(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex.wrap(&function1), handler1);
  std::experimental::dispatch(ex.wrap(&function1), &handler1);
  std::experimental::dispatch(ex.wrap(&function1), handler2());
  std::experimental::dispatch(ex.wrap(&function1), h2);
  std::experimental::dispatch(ex.wrap(&function1), ch2);
  std::experimental::dispatch(ex.wrap(&function1), handler3());
  std::experimental::dispatch(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex.wrap(function2()), handler1);
  std::experimental::dispatch(ex.wrap(function2()), &handler1);
  std::experimental::dispatch(ex.wrap(function2()), handler2());
  std::experimental::dispatch(ex.wrap(function2()), h2);
  std::experimental::dispatch(ex.wrap(function2()), ch2);
  std::experimental::dispatch(ex.wrap(function2()), handler3());
  std::experimental::dispatch(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex.wrap(f2), handler1);
  std::experimental::dispatch(ex.wrap(f2), &handler1);
  std::experimental::dispatch(ex.wrap(f2), handler2());
  std::experimental::dispatch(ex.wrap(f2), h2);
  std::experimental::dispatch(ex.wrap(f2), ch2);
  std::experimental::dispatch(ex.wrap(f2), handler3());
  std::experimental::dispatch(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex.wrap(cf2), handler1);
  std::experimental::dispatch(ex.wrap(cf2), &handler1);
  std::experimental::dispatch(ex.wrap(cf2), handler2());
  std::experimental::dispatch(ex.wrap(cf2), h2);
  std::experimental::dispatch(ex.wrap(cf2), ch2);
  std::experimental::dispatch(ex.wrap(cf2), handler3());
  std::experimental::dispatch(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex.wrap(function3()), handler1);
  std::experimental::dispatch(ex.wrap(function3()), &handler1);
  std::experimental::dispatch(ex.wrap(function3()), handler2());
  std::experimental::dispatch(ex.wrap(function3()), h2);
  std::experimental::dispatch(ex.wrap(function3()), ch2);
  std::experimental::dispatch(ex.wrap(function3()), handler3());
  std::experimental::dispatch(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex.wrap(std::move(f3)), handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), &handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler2());
  std::experimental::dispatch(ex.wrap(std::move(f3)), h2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), ch2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler3());
  std::experimental::dispatch(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 14
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  invoke(std::experimental::chain(function1));
  invoke(std::experimental::chain(function1, handler1));
  invoke(std::experimental::chain(function1, &handler1));
  invoke(std::experimental::chain(function1, handler2()));
  invoke(std::experimental::chain(function1, h2));
  invoke(std::experimental::chain(function1, ch2));
  invoke(std::experimental::chain(function1, handler3()));
  invoke(std::experimental::chain(function1, std::move(h3)));

  invoke(std::experimental::chain(&function1));
  invoke(std::experimental::chain(&function1, handler1));
  invoke(std::experimental::chain(&function1, &handler1));
  invoke(std::experimental::chain(&function1, handler2()));
  invoke(std::experimental::chain(&function1, h2));
  invoke(std::experimental::chain(&function1, ch2));
  invoke(std::experimental::chain(&function1, handler3()));
  invoke(std::experimental::chain(&function1, std::move(h3)));

  invoke(std::experimental::chain(function2()));
  invoke(std::experimental::chain(function2(), handler1));
  invoke(std::experimental::chain(function2(), &handler1));
  invoke(std::experimental::chain(function2(), handler2()));
  invoke(std::experimental::chain(function2(), h2));
  invoke(std::experimental::chain(function2(), ch2));
  invoke(std::experimental::chain(function2(), handler3()));
  invoke(std::experimental::chain(function2(), std::move(h3)));

  invoke(std::experimental::chain(f2));
  invoke(std::experimental::chain(f2, handler1));
  invoke(std::experimental::chain(f2, &handler1));
  invoke(std::experimental::chain(f2, handler2()));
  invoke(std::experimental::chain(f2, h2));
  invoke(std::experimental::chain(f2, ch2));
  invoke(std::experimental::chain(f2, handler3()));
  invoke(std::experimental::chain(f2, std::move(h3)));

  invoke(std::experimental::chain(cf2));
  invoke(std::experimental::chain(cf2, handler1));
  invoke(std::experimental::chain(cf2, &handler1));
  invoke(std::experimental::chain(cf2, handler2()));
  invoke(std::experimental::chain(cf2, h2));
  invoke(std::experimental::chain(cf2, ch2));
  invoke(std::experimental::chain(cf2, handler3()));
  invoke(std::experimental::chain(cf2, std::move(h3)));

  invoke(std::experimental::chain(function3()));
  invoke(std::experimental::chain(function3(), handler1));
  invoke(std::experimental::chain(function3(), &handler1));
  invoke(std::experimental::chain(function3(), handler2()));
  invoke(std::experimental::chain(function3(), h2));
  invoke(std::experimental::chain(function3(), ch2));
  invoke(std::experimental::chain(function3(), handler3()));
  invoke(std::experimental::chain(function3(), std::move(h3)));

  invoke(std::experimental::chain(std::move(f3)));
  invoke(std::experimental::chain(std::move(f3), handler1));
  invoke(std::experimental::chain(std::move(f3), &handler1));
  invoke(std::experimental::chain(std::move(f3), handler2()));
  invoke(std::experimental::chain(std::move(f3), h2));
  invoke(std::experimental::chain(std::move(f3), ch2));
  invoke(std::experimental::chain(std::move(f3), handler3()));
  invoke(std::experimental::chain(std::move(f3), std::move(h3)));

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 15
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  auto rel_time = std::chrono::milliseconds(100);

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 16
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  auto abs_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);

  std::experimental::dispatch_at(abs_time, ex, function1, handler1);
  std::experimental::dispatch_at(abs_time, ex, function1, &handler1);
  std::experimental::dispatch_at(abs_time, ex, function1, handler2());
  std::experimental::dispatch_at(abs_time, ex, function1, h2);
  std::experimental::dispatch_at(abs_time, ex, function1, ch2);
  std::experimental::dispatch_at(abs_time, ex, function1, handler3());
  std::experimental::dispatch_at(abs_time, ex, function1, std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch_at(abs_time, ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch_at(abs_time, ex, &function1, handler1);
  std::experimental::dispatch_at(abs_time, ex, &function1, &handler1);
  std::experimental::dispatch_at(abs_time, ex, &function1, handler2());
  std::experimental::dispatch_at(abs_time, ex, &function1, h2);
  std::experimental::dispatch_at(abs_time, ex, &function1, ch2);
  std::experimental::dispatch_at(abs_time, ex, &function1, handler3());
  std::experimental::dispatch_at(abs_time, ex, &function1, std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch_at(abs_time, ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch_at(abs_time, ex, function2(), handler1);
  std::experimental::dispatch_at(abs_time, ex, function2(), &handler1);
  std::experimental::dispatch_at(abs_time, ex, function2(), handler2());
  std::experimental::dispatch_at(abs_time, ex, function2(), h2);
  std::experimental::dispatch_at(abs_time, ex, function2(), ch2);
  std::experimental::dispatch_at(abs_time, ex, function2(), handler3());
  std::experimental::dispatch_at(abs_time, ex, function2(), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch_at(abs_time, ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch_at(abs_time, ex, f2, handler1);
  std::experimental::dispatch_at(abs_time, ex, f2, &handler1);
  std::experimental::dispatch_at(abs_time, ex, f2, handler2());
  std::experimental::dispatch_at(abs_time, ex, f2, h2);
  std::experimental::dispatch_at(abs_time, ex, f2, ch2);
  std::experimental::dispatch_at(abs_time, ex, f2, handler3());
  std::experimental::dispatch_at(abs_time, ex, f2, std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch_at(abs_time, ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch_at(abs_time, ex, cf2, handler1);
  std::experimental::dispatch_at(abs_time, ex, cf2, &handler1);
  std::experimental::dispatch_at(abs_time, ex, cf2, handler2());
  std::experimental::dispatch_at(abs_time, ex, cf2, h2);
  std::experimental::dispatch_at(abs_time, ex, cf2, ch2);
  std::experimental::dispatch_at(abs_time, ex, cf2, handler3());
  std::experimental::dispatch_at(abs_time, ex, cf2, std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch_at(abs_time, ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch_at(abs_time, ex, function3(), handler1);
  std::experimental::dispatch_at(abs_time, ex, function3(), &handler1);
  std::experimental::dispatch_at(abs_time, ex, function3(), handler2());
  std::experimental::dispatch_at(abs_time, ex, function3(), h2);
  std::experimental::dispatch_at(abs_time, ex, function3(), ch2);
  std::experimental::dispatch_at(abs_time, ex, function3(), handler3());
  std::experimental::dispatch_at(abs_time, ex, function3(), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch_at(abs_time, ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler1);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), &handler1);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler2());
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), h2);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), ch2);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler3());
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch_at(abs_time, ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);

  std::future<void> fut8 = std::experimental::dispatch_at(abs_time, ex, function_throw, std::experimental::use_future);
  try
  {
    fut8.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }

  std::future<void> fut9 = std::experimental::dispatch_at(abs_time, ex, std::experimental::package(function_throw));
  try
  {
    fut9.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }
}
Exemplo n.º 17
0
MojErr MojSignalTest::test0()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add0Slot(handler1->m_slot0);
	MojTestAssert(handler1->refCount() == 2);
	source->call0();
	MojTestAssert(handler1->m_handle0Count == 1);
	MojTestAssert(handler1->refCount() == 2);
	source->fire0();
	MojTestAssert(handler1->m_handle0Count == 2);
	MojTestAssert(handler1->refCount() == 1);
	source->fire0();
	MojTestAssert(handler1->m_handle0Count == 2);
	source->call0();
	MojTestAssert(handler1->m_handle0Count == 2);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add0Slot(handler1->m_slot0);
	source->add0Slot(handler2->m_slot0);
	source->call0();
	MojTestAssert(handler1->m_handle0Count == 3);
	MojTestAssert(handler2->m_handle0Count == 1);
	source->fire0();
	MojTestAssert(handler1->m_handle0Count == 4);
	MojTestAssert(handler2->m_handle0Count == 2);
	// cancel
	source->add0Slot(handler1->m_slot0);
	source->add0Slot(handler2->m_slot0);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot0.cancel();
	source->fire0();
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_handle0Count == 4);
	MojTestAssert(handler2->m_handle0Count == 3);
	// cancel from callback
	source->add0Slot(handler1->m_slot0Cancel);
	source->add0Slot(handler2->m_slot0);
	source->fire0();
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_handle0Count == 5);
	MojTestAssert(handler2->m_handle0Count == 4);
	source->add0Slot(handler2->m_slot0);
	source->fire0();
	MojTestAssert(handler1->m_handle0Count == 5);
	MojTestAssert(handler2->m_handle0Count == 5);
	// cancel from callback with call
	source->add0Slot(handler1->m_slot0Cancel);
	source->add0Slot(handler2->m_slot0);
	source->call0();
	MojTestAssert(source->m_numCancels == 2);
	MojTestAssert(handler1->m_handle0Count == 6);
	MojTestAssert(handler2->m_handle0Count == 6);
	source->call0();
	MojTestAssert(handler1->m_handle0Count == 6);
	MojTestAssert(handler2->m_handle0Count == 7);

	return MojErrNone;
}
Exemplo n.º 18
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;
  auto ex = make_executor(pool);

  std::experimental::dispatch(ex, function1, handler1);
  std::experimental::dispatch(ex, function1, &handler1);
  std::experimental::dispatch(ex, function1, handler2());
  std::experimental::dispatch(ex, function1, h2);
  std::experimental::dispatch(ex, function1, ch2);
  std::experimental::dispatch(ex, function1, handler3());
  std::experimental::dispatch(ex, function1, std::move(h3));
  std::future<int> fut1 = std::experimental::dispatch(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex, &function1, handler1);
  std::experimental::dispatch(ex, &function1, &handler1);
  std::experimental::dispatch(ex, &function1, handler2());
  std::experimental::dispatch(ex, &function1, h2);
  std::experimental::dispatch(ex, &function1, ch2);
  std::experimental::dispatch(ex, &function1, handler3());
  std::experimental::dispatch(ex, &function1, std::move(h3));
  std::future<int> fut2 = std::experimental::dispatch(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex, function2(), handler1);
  std::experimental::dispatch(ex, function2(), &handler1);
  std::experimental::dispatch(ex, function2(), handler2());
  std::experimental::dispatch(ex, function2(), h2);
  std::experimental::dispatch(ex, function2(), ch2);
  std::experimental::dispatch(ex, function2(), handler3());
  std::experimental::dispatch(ex, function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::dispatch(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex, f2, handler1);
  std::experimental::dispatch(ex, f2, &handler1);
  std::experimental::dispatch(ex, f2, handler2());
  std::experimental::dispatch(ex, f2, h2);
  std::experimental::dispatch(ex, f2, ch2);
  std::experimental::dispatch(ex, f2, handler3());
  std::experimental::dispatch(ex, f2, std::move(h3));
  std::future<int> fut4 = std::experimental::dispatch(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex, cf2, handler1);
  std::experimental::dispatch(ex, cf2, &handler1);
  std::experimental::dispatch(ex, cf2, handler2());
  std::experimental::dispatch(ex, cf2, h2);
  std::experimental::dispatch(ex, cf2, ch2);
  std::experimental::dispatch(ex, cf2, handler3());
  std::experimental::dispatch(ex, cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::dispatch(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex, function3(), handler1);
  std::experimental::dispatch(ex, function3(), &handler1);
  std::experimental::dispatch(ex, function3(), handler2());
  std::experimental::dispatch(ex, function3(), h2);
  std::experimental::dispatch(ex, function3(), ch2);
  std::experimental::dispatch(ex, function3(), handler3());
  std::experimental::dispatch(ex, function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::dispatch(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex, std::move(f3), handler1);
  std::experimental::dispatch(ex, std::move(f3), &handler1);
  std::experimental::dispatch(ex, std::move(f3), handler2());
  std::experimental::dispatch(ex, std::move(f3), h2);
  std::experimental::dispatch(ex, std::move(f3), ch2);
  std::experimental::dispatch(ex, std::move(f3), handler3());
  std::experimental::dispatch(ex, std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::dispatch(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 19
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;

  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function1), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(std::experimental::wrap(pool, function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(std::experimental::wrap(pool, &function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(std::experimental::wrap(pool, function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, f2), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(std::experimental::wrap(pool, f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(std::experimental::wrap(pool, cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(std::experimental::wrap(pool, function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 20
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = make_executor(scheduler);

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  std::experimental::post(ex.wrap(function1), handler1);
  std::experimental::post(ex.wrap(function1), &handler1);
  std::experimental::post(ex.wrap(function1), handler2());
  std::experimental::post(ex.wrap(function1), h2);
  std::experimental::post(ex.wrap(function1), ch2);
  std::experimental::post(ex.wrap(function1), handler3());
  std::experimental::post(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex.wrap(&function1), handler1);
  std::experimental::post(ex.wrap(&function1), &handler1);
  std::experimental::post(ex.wrap(&function1), handler2());
  std::experimental::post(ex.wrap(&function1), h2);
  std::experimental::post(ex.wrap(&function1), ch2);
  std::experimental::post(ex.wrap(&function1), handler3());
  std::experimental::post(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex.wrap(function2()), handler1);
  std::experimental::post(ex.wrap(function2()), &handler1);
  std::experimental::post(ex.wrap(function2()), handler2());
  std::experimental::post(ex.wrap(function2()), h2);
  std::experimental::post(ex.wrap(function2()), ch2);
  std::experimental::post(ex.wrap(function2()), handler3());
  std::experimental::post(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex.wrap(f2), handler1);
  std::experimental::post(ex.wrap(f2), &handler1);
  std::experimental::post(ex.wrap(f2), handler2());
  std::experimental::post(ex.wrap(f2), h2);
  std::experimental::post(ex.wrap(f2), ch2);
  std::experimental::post(ex.wrap(f2), handler3());
  std::experimental::post(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex.wrap(cf2), handler1);
  std::experimental::post(ex.wrap(cf2), &handler1);
  std::experimental::post(ex.wrap(cf2), handler2());
  std::experimental::post(ex.wrap(cf2), h2);
  std::experimental::post(ex.wrap(cf2), ch2);
  std::experimental::post(ex.wrap(cf2), handler3());
  std::experimental::post(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex.wrap(function3()), handler1);
  std::experimental::post(ex.wrap(function3()), &handler1);
  std::experimental::post(ex.wrap(function3()), handler2());
  std::experimental::post(ex.wrap(function3()), h2);
  std::experimental::post(ex.wrap(function3()), ch2);
  std::experimental::post(ex.wrap(function3()), handler3());
  std::experimental::post(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex.wrap(std::move(f3)), handler1);
  std::experimental::post(ex.wrap(std::move(f3)), &handler1);
  std::experimental::post(ex.wrap(std::move(f3)), handler2());
  std::experimental::post(ex.wrap(std::move(f3)), h2);
  std::experimental::post(ex.wrap(std::move(f3)), ch2);
  std::experimental::post(ex.wrap(std::move(f3)), handler3());
  std::experimental::post(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 21
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = make_executor(scheduler);
  std::experimental::executor::work w = ex.make_work();
  std::thread t([&](){ scheduler.run(); });

  std::experimental::post(ex, function1, handler1);
  std::experimental::post(ex, function1, &handler1);
  std::experimental::post(ex, function1, handler2());
  std::experimental::post(ex, function1, h2);
  std::experimental::post(ex, function1, ch2);
  std::experimental::post(ex, function1, handler3());
  std::experimental::post(ex, function1, std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex, &function1, handler1);
  std::experimental::post(ex, &function1, &handler1);
  std::experimental::post(ex, &function1, handler2());
  std::experimental::post(ex, &function1, h2);
  std::experimental::post(ex, &function1, ch2);
  std::experimental::post(ex, &function1, handler3());
  std::experimental::post(ex, &function1, std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex, function2(), handler1);
  std::experimental::post(ex, function2(), &handler1);
  std::experimental::post(ex, function2(), handler2());
  std::experimental::post(ex, function2(), h2);
  std::experimental::post(ex, function2(), ch2);
  std::experimental::post(ex, function2(), handler3());
  std::experimental::post(ex, function2(), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex, f2, handler1);
  std::experimental::post(ex, f2, &handler1);
  std::experimental::post(ex, f2, handler2());
  std::experimental::post(ex, f2, h2);
  std::experimental::post(ex, f2, ch2);
  std::experimental::post(ex, f2, handler3());
  std::experimental::post(ex, f2, std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex, cf2, handler1);
  std::experimental::post(ex, cf2, &handler1);
  std::experimental::post(ex, cf2, handler2());
  std::experimental::post(ex, cf2, h2);
  std::experimental::post(ex, cf2, ch2);
  std::experimental::post(ex, cf2, handler3());
  std::experimental::post(ex, cf2, std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex, function3(), handler1);
  std::experimental::post(ex, function3(), &handler1);
  std::experimental::post(ex, function3(), handler2());
  std::experimental::post(ex, function3(), h2);
  std::experimental::post(ex, function3(), ch2);
  std::experimental::post(ex, function3(), handler3());
  std::experimental::post(ex, function3(), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex, std::move(f3), handler1);
  std::experimental::post(ex, std::move(f3), &handler1);
  std::experimental::post(ex, std::move(f3), handler2());
  std::experimental::post(ex, std::move(f3), h2);
  std::experimental::post(ex, std::move(f3), ch2);
  std::experimental::post(ex, std::move(f3), handler3());
  std::experimental::post(ex, std::move(f3), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  w = nullptr;
  assert(!w);
  assert(w == nullptr);
  assert(nullptr == w);
  assert(!(w != nullptr));
  assert(!(nullptr != w));

  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 22
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = make_strand(scheduler.get_executor());
  std::experimental::executor_work<decltype(ex)> w(ex);
  std::thread t([&](){ scheduler.run(); });

  std::experimental::post(ex, function1, handler1);
  std::experimental::post(ex, function1, &handler1);
  std::experimental::post(ex, function1, handler2());
  std::experimental::post(ex, function1, h2);
  std::experimental::post(ex, function1, ch2);
  std::experimental::post(ex, function1, handler3());
  std::experimental::post(ex, function1, std::move(h3));
  std::future<int> fut1 = std::experimental::post(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex, &function1, handler1);
  std::experimental::post(ex, &function1, &handler1);
  std::experimental::post(ex, &function1, handler2());
  std::experimental::post(ex, &function1, h2);
  std::experimental::post(ex, &function1, ch2);
  std::experimental::post(ex, &function1, handler3());
  std::experimental::post(ex, &function1, std::move(h3));
  std::future<int> fut2 = std::experimental::post(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex, function2(), handler1);
  std::experimental::post(ex, function2(), &handler1);
  std::experimental::post(ex, function2(), handler2());
  std::experimental::post(ex, function2(), h2);
  std::experimental::post(ex, function2(), ch2);
  std::experimental::post(ex, function2(), handler3());
  std::experimental::post(ex, function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::post(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex, f2, handler1);
  std::experimental::post(ex, f2, &handler1);
  std::experimental::post(ex, f2, handler2());
  std::experimental::post(ex, f2, h2);
  std::experimental::post(ex, f2, ch2);
  std::experimental::post(ex, f2, handler3());
  std::experimental::post(ex, f2, std::move(h3));
  std::future<int> fut4 = std::experimental::post(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex, cf2, handler1);
  std::experimental::post(ex, cf2, &handler1);
  std::experimental::post(ex, cf2, handler2());
  std::experimental::post(ex, cf2, h2);
  std::experimental::post(ex, cf2, ch2);
  std::experimental::post(ex, cf2, handler3());
  std::experimental::post(ex, cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::post(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex, function3(), handler1);
  std::experimental::post(ex, function3(), &handler1);
  std::experimental::post(ex, function3(), handler2());
  std::experimental::post(ex, function3(), h2);
  std::experimental::post(ex, function3(), ch2);
  std::experimental::post(ex, function3(), handler3());
  std::experimental::post(ex, function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::post(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex, std::move(f3), handler1);
  std::experimental::post(ex, std::move(f3), &handler1);
  std::experimental::post(ex, std::move(f3), handler2());
  std::experimental::post(ex, std::move(f3), h2);
  std::experimental::post(ex, std::move(f3), ch2);
  std::experimental::post(ex, std::move(f3), handler3());
  std::experimental::post(ex, std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::post(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  w.reset();
  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 23
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = scheduler.get_executor();
  std::experimental::executor_work<decltype(ex)> w(ex);
  std::thread t([&](){ scheduler.run(); });

  std::experimental::dispatch(ex.wrap(function1), handler1);
  std::experimental::dispatch(ex.wrap(function1), &handler1);
  std::experimental::dispatch(ex.wrap(function1), handler2());
  std::experimental::dispatch(ex.wrap(function1), h2);
  std::experimental::dispatch(ex.wrap(function1), ch2);
  std::experimental::dispatch(ex.wrap(function1), handler3());
  std::experimental::dispatch(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex.wrap(&function1), handler1);
  std::experimental::dispatch(ex.wrap(&function1), &handler1);
  std::experimental::dispatch(ex.wrap(&function1), handler2());
  std::experimental::dispatch(ex.wrap(&function1), h2);
  std::experimental::dispatch(ex.wrap(&function1), ch2);
  std::experimental::dispatch(ex.wrap(&function1), handler3());
  std::experimental::dispatch(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex.wrap(function2()), handler1);
  std::experimental::dispatch(ex.wrap(function2()), &handler1);
  std::experimental::dispatch(ex.wrap(function2()), handler2());
  std::experimental::dispatch(ex.wrap(function2()), h2);
  std::experimental::dispatch(ex.wrap(function2()), ch2);
  std::experimental::dispatch(ex.wrap(function2()), handler3());
  std::experimental::dispatch(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex.wrap(f2), handler1);
  std::experimental::dispatch(ex.wrap(f2), &handler1);
  std::experimental::dispatch(ex.wrap(f2), handler2());
  std::experimental::dispatch(ex.wrap(f2), h2);
  std::experimental::dispatch(ex.wrap(f2), ch2);
  std::experimental::dispatch(ex.wrap(f2), handler3());
  std::experimental::dispatch(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex.wrap(cf2), handler1);
  std::experimental::dispatch(ex.wrap(cf2), &handler1);
  std::experimental::dispatch(ex.wrap(cf2), handler2());
  std::experimental::dispatch(ex.wrap(cf2), h2);
  std::experimental::dispatch(ex.wrap(cf2), ch2);
  std::experimental::dispatch(ex.wrap(cf2), handler3());
  std::experimental::dispatch(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex.wrap(function3()), handler1);
  std::experimental::dispatch(ex.wrap(function3()), &handler1);
  std::experimental::dispatch(ex.wrap(function3()), handler2());
  std::experimental::dispatch(ex.wrap(function3()), h2);
  std::experimental::dispatch(ex.wrap(function3()), ch2);
  std::experimental::dispatch(ex.wrap(function3()), handler3());
  std::experimental::dispatch(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex.wrap(std::move(f3)), handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), &handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler2());
  std::experimental::dispatch(ex.wrap(std::move(f3)), h2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), ch2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler3());
  std::experimental::dispatch(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  w.reset();
  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 24
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  invoke(std::experimental::chain(ex.wrap(function1)));
  invoke(std::experimental::chain(ex.wrap(function1), handler1));
  invoke(std::experimental::chain(ex.wrap(function1), &handler1));
  invoke(std::experimental::chain(ex.wrap(function1), handler2()));
  invoke(std::experimental::chain(ex.wrap(function1), h2));
  invoke(std::experimental::chain(ex.wrap(function1), ch2));
  invoke(std::experimental::chain(ex.wrap(function1), handler3()));
  invoke(std::experimental::chain(ex.wrap(function1), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(&function1)));
  invoke(std::experimental::chain(ex.wrap(&function1), handler1));
  invoke(std::experimental::chain(ex.wrap(&function1), &handler1));
  invoke(std::experimental::chain(ex.wrap(&function1), handler2()));
  invoke(std::experimental::chain(ex.wrap(&function1), h2));
  invoke(std::experimental::chain(ex.wrap(&function1), ch2));
  invoke(std::experimental::chain(ex.wrap(&function1), handler3()));
  invoke(std::experimental::chain(ex.wrap(&function1), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(function2())));
  invoke(std::experimental::chain(ex.wrap(function2()), handler1));
  invoke(std::experimental::chain(ex.wrap(function2()), &handler1));
  invoke(std::experimental::chain(ex.wrap(function2()), handler2()));
  invoke(std::experimental::chain(ex.wrap(function2()), h2));
  invoke(std::experimental::chain(ex.wrap(function2()), ch2));
  invoke(std::experimental::chain(ex.wrap(function2()), handler3()));
  invoke(std::experimental::chain(ex.wrap(function2()), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(f2)));
  invoke(std::experimental::chain(ex.wrap(f2), handler1));
  invoke(std::experimental::chain(ex.wrap(f2), &handler1));
  invoke(std::experimental::chain(ex.wrap(f2), handler2()));
  invoke(std::experimental::chain(ex.wrap(f2), h2));
  invoke(std::experimental::chain(ex.wrap(f2), ch2));
  invoke(std::experimental::chain(ex.wrap(f2), handler3()));
  invoke(std::experimental::chain(ex.wrap(f2), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(cf2)));
  invoke(std::experimental::chain(ex.wrap(cf2), handler1));
  invoke(std::experimental::chain(ex.wrap(cf2), &handler1));
  invoke(std::experimental::chain(ex.wrap(cf2), handler2()));
  invoke(std::experimental::chain(ex.wrap(cf2), h2));
  invoke(std::experimental::chain(ex.wrap(cf2), ch2));
  invoke(std::experimental::chain(ex.wrap(cf2), handler3()));
  invoke(std::experimental::chain(ex.wrap(cf2), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(function3())));
  invoke(std::experimental::chain(ex.wrap(function3()), handler1));
  invoke(std::experimental::chain(ex.wrap(function3()), &handler1));
  invoke(std::experimental::chain(ex.wrap(function3()), handler2()));
  invoke(std::experimental::chain(ex.wrap(function3()), h2));
  invoke(std::experimental::chain(ex.wrap(function3()), ch2));
  invoke(std::experimental::chain(ex.wrap(function3()), handler3()));
  invoke(std::experimental::chain(ex.wrap(function3()), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(std::move(f3))));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler1));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), &handler1));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler2()));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), h2));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), ch2));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler3()));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), std::move(h3)));

  assert(function_count == 56);
  assert(handler_count == 49);
}
Exemplo n.º 25
0
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NIImporter_DlrNavteq::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
    // check whether the option is set (properly)
    if (!oc.isSet("dlr-navteq-prefix")) {
        return;
    }
    time_t csTime;
    time(&csTime);
    // parse file(s)
    LineReader lr;
    // load nodes
    std::map<std::string, PositionVector> myGeoms;
    PROGRESS_BEGIN_MESSAGE("Loading nodes");
    std::string file = oc.getString("dlr-navteq-prefix") + "_nodes_unsplitted.txt";
    NodesHandler handler1(nb.getNodeCont(), file, myGeoms);
    if (!lr.setFile(file)) {
        throw ProcessError("The file '" + file + "' could not be opened.");
    }
    lr.readAll(handler1);
    PROGRESS_DONE_MESSAGE();

    // load street names if given and wished
    std::map<std::string, std::string> streetNames; // nameID : name
    if (oc.getBool("output.street-names")) {
        file = oc.getString("dlr-navteq-prefix") + "_names.txt";
        if (lr.setFile(file)) {
            PROGRESS_BEGIN_MESSAGE("Loading Street Names");
            NamesHandler handler4(file, streetNames);
            lr.readAll(handler4);
            PROGRESS_DONE_MESSAGE();
        } else {
            WRITE_WARNING("Output will not contain street names because the file '" + file + "' was not found");
        }
    }

    // load edges
    PROGRESS_BEGIN_MESSAGE("Loading edges");
    file = oc.getString("dlr-navteq-prefix") + "_links_unsplitted.txt";
    // parse the file
    EdgesHandler handler2(nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), file, myGeoms, streetNames);
    if (!lr.setFile(file)) {
        throw ProcessError("The file '" + file + "' could not be opened.");
    }
    lr.readAll(handler2);
    nb.getEdgeCont().recheckLaneSpread();
    PROGRESS_DONE_MESSAGE();

    // load traffic lights if given
    file = oc.getString("dlr-navteq-prefix") + "_traffic_signals.txt";
    if (lr.setFile(file)) {
        PROGRESS_BEGIN_MESSAGE("Loading traffic lights");
        TrafficlightsHandler handler3(nb.getNodeCont(), nb.getTLLogicCont(), nb.getEdgeCont(), file);
        lr.readAll(handler3);
        PROGRESS_DONE_MESSAGE();
    }

    // load prohibited manoeuvres if given
    file = oc.getString("dlr-navteq-prefix") + "_prohibited_manoeuvres.txt";
    if (lr.setFile(file)) {
        PROGRESS_BEGIN_MESSAGE("Loading prohibited manoeuvres");
        ProhibitionHandler handler6(nb.getEdgeCont(), file, csTime);
        lr.readAll(handler6);
        PROGRESS_DONE_MESSAGE();
    }

    // load connected lanes if given
    file = oc.getString("dlr-navteq-prefix") + "_connected_lanes.txt";
    if (lr.setFile(file)) {
        PROGRESS_BEGIN_MESSAGE("Loading connected lanes");
        ConnectedLanesHandler handler7(nb.getEdgeCont());
        lr.readAll(handler7);
        PROGRESS_DONE_MESSAGE();
    }

    // load time restrictions if given
    file = oc.getString("dlr-navteq-prefix") + "_links_timerestrictions.txt";
    if (lr.setFile(file)) {
        PROGRESS_BEGIN_MESSAGE("Loading time restrictions");
        if (!oc.isDefault("construction-date")) {
            csTime = readDate(oc.getString("construction-date"));
        }
        TimeRestrictionsHandler handler5(nb.getEdgeCont(), nb.getDistrictCont(), csTime);
        lr.readAll(handler5);
        handler5.printSummary();
        PROGRESS_DONE_MESSAGE();
    }
}
Exemplo n.º 26
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;
  auto ex = make_executor(pool);

  std::experimental::post(ex.wrap(function1), handler1);
  std::experimental::post(ex.wrap(function1), &handler1);
  std::experimental::post(ex.wrap(function1), handler2());
  std::experimental::post(ex.wrap(function1), h2);
  std::experimental::post(ex.wrap(function1), ch2);
  std::experimental::post(ex.wrap(function1), handler3());
  std::experimental::post(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex.wrap(&function1), handler1);
  std::experimental::post(ex.wrap(&function1), &handler1);
  std::experimental::post(ex.wrap(&function1), handler2());
  std::experimental::post(ex.wrap(&function1), h2);
  std::experimental::post(ex.wrap(&function1), ch2);
  std::experimental::post(ex.wrap(&function1), handler3());
  std::experimental::post(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex.wrap(function2()), handler1);
  std::experimental::post(ex.wrap(function2()), &handler1);
  std::experimental::post(ex.wrap(function2()), handler2());
  std::experimental::post(ex.wrap(function2()), h2);
  std::experimental::post(ex.wrap(function2()), ch2);
  std::experimental::post(ex.wrap(function2()), handler3());
  std::experimental::post(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex.wrap(f2), handler1);
  std::experimental::post(ex.wrap(f2), &handler1);
  std::experimental::post(ex.wrap(f2), handler2());
  std::experimental::post(ex.wrap(f2), h2);
  std::experimental::post(ex.wrap(f2), ch2);
  std::experimental::post(ex.wrap(f2), handler3());
  std::experimental::post(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex.wrap(cf2), handler1);
  std::experimental::post(ex.wrap(cf2), &handler1);
  std::experimental::post(ex.wrap(cf2), handler2());
  std::experimental::post(ex.wrap(cf2), h2);
  std::experimental::post(ex.wrap(cf2), ch2);
  std::experimental::post(ex.wrap(cf2), handler3());
  std::experimental::post(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex.wrap(function3()), handler1);
  std::experimental::post(ex.wrap(function3()), &handler1);
  std::experimental::post(ex.wrap(function3()), handler2());
  std::experimental::post(ex.wrap(function3()), h2);
  std::experimental::post(ex.wrap(function3()), ch2);
  std::experimental::post(ex.wrap(function3()), handler3());
  std::experimental::post(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex.wrap(std::move(f3)), handler1);
  std::experimental::post(ex.wrap(std::move(f3)), &handler1);
  std::experimental::post(ex.wrap(std::move(f3)), handler2());
  std::experimental::post(ex.wrap(std::move(f3)), h2);
  std::experimental::post(ex.wrap(std::move(f3)), ch2);
  std::experimental::post(ex.wrap(std::move(f3)), handler3());
  std::experimental::post(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}