コード例 #1
0
ファイル: tstMatch.cpp プロジェクト: Foorgol/QTournament
void tstMatch::testGetPairs()
{
  printStartMsg("tstMatch::testGetGroup");

  TournamentDB* db = getScenario04(true);
  Tournament t(getSqliteFileName());
  MatchMngr* mm = Tournament::getMatchMngr();
  Category mx = Tournament::getCatMngr()->getCategoryById(5);

  ERR e;
  auto mg = mm->getMatchGroup(mx, 1, 1, &e);
  CPPUNIT_ASSERT(e == OK);
  CPPUNIT_ASSERT(mg != nullptr);

  auto mgl = mg->getMatches();
  CPPUNIT_ASSERT(mgl.count() == 1);
  Match ma = mgl.at(0);

  // test the getPair-functions
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == false);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == false);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair1(), std::runtime_error);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair2(), std::runtime_error);

  // (artificially) assign one pair
  PlayerPair pp1 = Tournament::getPlayerMngr()->getPlayerPair(1);
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR1_REF, pp1.getPairId());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == true);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == false);
  CPPUNIT_ASSERT(ma.getPlayerPair1().getPairId() == pp1.getPairId());
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair2(), std::runtime_error);

  // (artificially) assign the second pair
  PlayerPair pp2 = Tournament::getPlayerMngr()->getPlayerPair(2);
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR2_REF, pp2.getPairId());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == true);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == true);
  CPPUNIT_ASSERT(ma.getPlayerPair1().getPairId() == pp1.getPairId());
  CPPUNIT_ASSERT(ma.getPlayerPair2().getPairId() == pp2.getPairId());

  // remove the first one
  (*db)[TAB_MATCH][ma.getId()].update(MA_PAIR1_REF, QVariant());

  // test again
  CPPUNIT_ASSERT(ma.hasPlayerPair1() == false);
  CPPUNIT_ASSERT(ma.hasPlayerPair2() == true);
  CPPUNIT_ASSERT_THROW(ma.getPlayerPair1(), std::runtime_error);
  CPPUNIT_ASSERT(ma.getPlayerPair2().getPairId() == pp2.getPairId());

  delete db;
  printEndMsg();
}
コード例 #2
0
bool BracketVisElement::linkToMatch(const Match& ma) const
{
  Category myCat = getLinkedCategory();
  if (ma.getCategory() != myCat) return false;

  // lock the database before writing
  DbLockHolder lh{db, DatabaseAccessRoles::MainThread};

  row.update(BV_MATCH_REF, ma.getId());
  return true;
}
コード例 #3
0
ファイル: DataBase.cpp プロジェクト: cabelitos/DotaMetrics
bool DataBase::_insertMatch(const Match &match) {
  QSqlQuery query(_db);
  query.prepare("insert into Match (match_id, time_stamp, game_type)"\
		" values(?, ?, ?)");
  query.addBindValue(match.getId());
  query.addBindValue(match.getDate().toTime_t());
  query.addBindValue(static_cast<int>(match.getMatchType()));
  if (!query.exec()) {
    qCritical() << "Could not insert match!\n";
    return false;
  }
  return _insertMatchDetails(match.getDetails());
}