Esempio n. 1
0
File: line.c Progetto: JakeSc/tig
static struct line_rule *
find_line_rule(struct line_rule *query)
{
	enum line_type type;

	if (!line_rules) {
		LINE_INFO(INIT_BUILTIN_LINE_INFO);
	}

	for (type = 0; type < line_rules; type++) {
		struct line_rule *rule = &line_rule[type];

		if (query->namelen && enum_equals(*rule, query->name, query->namelen))
			return rule;

		if (query->linelen && query->linelen == rule->linelen &&
		    !strncasecmp(rule->line, query->line, rule->linelen))
			return rule;
	}

	return NULL;
}
Esempio n. 2
0
	void SyncTestbed::ResetTestBed()
	{
		Assert::IsTrue(m_serverConnection1->IsConnected(), L"Server connection to client 1 is not connected.", LINE_INFO());
		Assert::IsTrue(m_serverConnection2->IsConnected(), L"Server connection to client 1 is not connected.", LINE_INFO());

		Assert::IsTrue(m_clientConnection1A->IsConnected(), L"Client 1 connection to server is not connected.", LINE_INFO());
		Assert::IsTrue(m_clientConnection2A->IsConnected(), L"Client 2 connection to server is not connected.", LINE_INFO());

		if (m_bConnectOnSight)
		{
			Assert::IsTrue(m_clientConnection1B->IsConnected(), L"Client 1 connection to server is not connected.", LINE_INFO());
			Assert::IsTrue(m_clientConnection2B->IsConnected(), L"Client 2 connection to server is not connected.", LINE_INFO());

			Assert::IsTrue(m_onsightConnection1->IsConnected(), L"Timed out waiting for the operation to complete.", LINE_INFO());
			Assert::IsTrue(m_onsightConnection2->IsConnected(), L"Timed out waiting for the operation to complete.", LINE_INFO());
		}

		m_serverSyncMgr = SyncManager::Create(MessageID::SyncMessage, AuthorityLevel::High, m_userServer);
		m_client1SyncMgr = SyncManager::Create(MessageID::SyncMessage, AuthorityLevel::Medium, m_userClient1);
		m_client2SyncMgr = SyncManager::Create(MessageID::SyncMessage, AuthorityLevel::Medium, m_userClient2);
		m_onsight1SyncMgr = SyncManager::Create(MessageID::SyncMessage, AuthorityLevel::Low, m_userOnSight1);
		m_onsight2SyncMgr = SyncManager::Create(MessageID::SyncMessage, AuthorityLevel::Low, m_userOnSight2);

		m_serverSyncMgr->AddConnection(m_serverConnection1);
		m_serverSyncMgr->AddConnection(m_serverConnection2);

		m_client1SyncMgr->AddConnection(m_clientConnection1A);
		m_client2SyncMgr->AddConnection(m_clientConnection2A);

		if (m_bConnectOnSight)
		{
			m_client1SyncMgr->AddConnection(m_clientConnection1B);
			m_client2SyncMgr->AddConnection(m_clientConnection2B);

			m_onsight1SyncMgr->AddConnection(m_onsightConnection1);
			m_onsight2SyncMgr->AddConnection(m_onsightConnection2);
		}

		// Give the server and client a chance to complete the handshake; though this might not be enough time
		for (int i = 0; i < 10; ++i)
		{
			m_serverSocketMgr->Update();
			m_mslice1SocketMgr->Update();
			m_mslice2SocketMgr->Update();
			m_onsight1SocketMgr->Update();
			m_onsight2SocketMgr->Update();
			Platform::SleepMS(5);
		}

		// Setup objects to wrap the root of the synced data set
		m_serverRoot = new SyncTestObject(m_serverSyncMgr->GetRootObject());
		m_client1Root = new SyncTestObject(m_client1SyncMgr->GetRootObject());
		m_client2Root = new SyncTestObject(m_client2SyncMgr->GetRootObject());
		m_onsight1Root = new SyncTestObject(m_onsight1SyncMgr->GetRootObject());
		m_onsight2Root = new SyncTestObject(m_onsight2SyncMgr->GetRootObject());
	}
std::vector<unsigned char> CTestCaseData::LoadFile(const std::string filename)
{
  std::vector<unsigned char> vectorBuffer;
  char* pFileSamplesPath;
  size_t len = 0;
  if (_dupenv_s(&pFileSamplesPath, &len, "FileSamplesPath") || !pFileSamplesPath)
  {
	  pFileSamplesPath = TEST_DATA_PATH;
  }
  std::string fileSamplesPath(pFileSamplesPath);
  if (fileSamplesPath.size() && (*fileSamplesPath.rbegin() != '\\'))
  {
	  fileSamplesPath += L'\\';
  }
  auto file = fileSamplesPath + filename;
  if (PathFileExistsA(file.c_str()))
  {
    HANDLE hFile = CreateFileA(file.c_str(), FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (hFile != INVALID_HANDLE_VALUE)
    {
      auto fileSize = GetFileSize(hFile, NULL);
      vectorBuffer.resize(fileSize);
      DWORD dwBytesRead = 0;
      ReadFile(hFile, &vectorBuffer[0], fileSize, &dwBytesRead, NULL);
      CloseHandle(hFile);
    }
  }
  else
  {
    vectorBuffer.resize(MAX_PATH);
    GetCurrentDirectoryA(vectorBuffer.size() - 1, (LPSTR)&vectorBuffer[0]);
    std::string filePath((LPSTR)&vectorBuffer[0]);
    filePath += "\\" + file;
    const std::wstring errorMessage(L"File not found: " + CPtoUCS2(filePath, CP_ACP));
    Microsoft::VisualStudio::CppUnitTestFramework::Assert::Fail(errorMessage.c_str(), LINE_INFO());
  }
  return vectorBuffer;
}