TEST(MatchDao, saveTeams){ //precisa de um player, id 0 auto connection = loadConnection(); mm::Match match; vector<int> teamA; teamA.push_back(1); teamA.push_back(1); vector<int> teamB; teamB.push_back(1); match.addTeam(teamA); match.addTeam(teamB); auto matchDao = connection->matchDao(); bool saved = matchDao->saveMatch(match); EXPECT_TRUE(saved); mm::Match loadedMatch; loadedMatch.setId(match.id()); bool loaded = matchDao->loadMatch(loadedMatch); if(!loaded){ std::cout << "ERRO: " << matchDao->getError() << std::endl; } EXPECT_TRUE(loaded); int playersCount = loadedMatch.playersCount(); int teamsCount = loadedMatch.teamsCount(); EXPECT_EQ(3, playersCount); EXPECT_EQ(2, teamsCount); bool removed = matchDao->removeMatch(match); EXPECT_FALSE(removed);//match_profile dependencies }
TEST(MatchDao, saveEmpty){ std::shared_ptr<mm::DbConnection> connection; connection = loadConnection(); std::shared_ptr<mm::MatchDao> matchDao = connection->matchDao(); mm::Match match; matchDao->saveMatch(match); int savedMatchId = match.id(); EXPECT_NE(savedMatchId, mm::CustomObject::nullId); bool removed = matchDao->removeMatch(match); EXPECT_TRUE(removed); }
void ConnectionCollector::load (QDomNode connections, DiagramItemCollector* itemCollector) { QList<int> usedID; while(!connections.isNull()) { QDomElement e = connections.toElement(); // try to convert the node to an element. if(!e.isNull()) loadConnection (connections, itemCollector, usedID); connections = connections.nextSibling(); } }
TEST(ProfileDao, save_remove){ auto connection = loadConnection(); auto profileDao = connection->profileDao(); mm::Profile newProfile; std::string nomeTeste = "Nome Teste"; newProfile.setName(nomeTeste); bool saved = profileDao->saveProfile(newProfile); EXPECT_TRUE(saved); EXPECT_NE(newProfile.id(), mm::CustomObject::nullId); bool removed = profileDao->removeProfile(newProfile); EXPECT_TRUE(removed); }
TEST(MatchDao, saveDateTime){ std::shared_ptr<mm::DbConnection> connection; connection = loadConnection(); std::shared_ptr<mm::MatchDao> matchDao = connection->matchDao(); mm::Match match; time_t t = time(0); std::tm currentTime = *localtime(&t); match.setCreationDateTime(currentTime); matchDao->saveMatch(match); mm::Match loadedMatch; loadedMatch.setId(match.id()); matchDao->loadMatch(loadedMatch); std::tm loadedTime = loadedMatch.creationDateTime(); EXPECT_EQ(mktime(&loadedTime), mktime(¤tTime)); bool removed = matchDao->removeMatch(match); EXPECT_TRUE(removed); }
TEST(ProfileDao, load){ auto connection = loadConnection(); auto profileDao = connection->profileDao(); mm::Profile newProfile; std::string testName = "Nome Teste Load"; newProfile.setName(testName); profileDao->saveProfile(newProfile); mm::Profile loadedProfile; loadedProfile.setId(newProfile.id()); bool loaded = profileDao->loadProfile(loadedProfile); EXPECT_TRUE(loaded); EXPECT_EQ(newProfile.name(), loadedProfile.name()); bool removed = profileDao->removeProfile(newProfile); EXPECT_TRUE(removed); loaded = profileDao->loadProfile(loadedProfile); EXPECT_FALSE(loaded); }
/// \brief Create a cached TCP connection /// /// \param host The host that the connection should be for. /// \param sslCertFile The certificate used in a secure connection /// \param sslPassword The password used in a secure connection /// \return CTcp - connection object /// CTcp* ConnectionsCache::aquireConnection(const std::string& host, int port, const std::string& sslCertFile, const std::string& sslPassword, const std::string& sslCertHosts) { TraceComms("ConnectionsCache::aquireConnection host", host.c_str(), port); CTcp* connection = loadConnection(host, port, sslCertFile, sslPassword, sslCertHosts); // if (connection && !connection->CheckOpen()) // { // TraceComms("ConnectionsCache::aquireConnection delete closed TCP connection", connection ? connection->getHost().c_str() : "", -2); // // removeConnection(connection); // delete connection; // connection = NULL; // } // if (connection == NULL) { connection = new CTcp(host, port, sslCertFile, sslPassword, sslCertHosts); TraceComms("ConnectionsCache::aquireConnection create new TCP connection", Format("host=%s, port=%d, connection=%p", connection->getHost().c_str(), connection->getPort(), connection).c_str(), connection->getFD()); } return connection; }