Add Tests
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#include "MultipleConnections.h"
|
||||
#include "MySQLClient.h"
|
||||
#include <Logging.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace Test {
|
||||
|
||||
bool MultipleConnections()
|
||||
{
|
||||
Logging::Log(Logging::Severity::Info, "MultipleConnections");
|
||||
|
||||
try
|
||||
{
|
||||
std::string hostname1 = "MySQL";
|
||||
std::string username1 = "datalog";
|
||||
std::string password1 = "NfhdUwjjdRbslR";
|
||||
std::string database1 = "datalog";
|
||||
|
||||
std::string hostname2 = "Pi";
|
||||
std::string username2 = "root";
|
||||
std::string password2 = "Wh1sK3y";
|
||||
std::string database2 = "domotica";
|
||||
|
||||
MySQL::MySQLClient MySQLClient1;
|
||||
MySQL::MySQLClient MySQLClient2;
|
||||
|
||||
MySQLClient1.Connect(hostname1, username1, password1, database1);
|
||||
MySQLClient2.Connect(hostname2, username2, password2, database2);
|
||||
|
||||
if (!MySQLClient1.Connected() || !MySQLClient2.Connected())
|
||||
return false;
|
||||
|
||||
std::stringstream query1;
|
||||
query1 << "SELECT * FROM `datalog` LIMIT 1;";
|
||||
|
||||
std::stringstream query2;
|
||||
query2 << "SELECT * FROM `device` LIMIT 1;";
|
||||
|
||||
auto result1 = MySQLClient1.ExecuteQuery(query1.str());
|
||||
auto result2 = MySQLClient2.ExecuteQuery(query2.str());
|
||||
|
||||
if (result1.RowsCount() == 0 || result2.RowsCount() == 0)
|
||||
return false;
|
||||
|
||||
result1.First();
|
||||
result2.First();
|
||||
|
||||
auto id1 = result1.Int("device_id");
|
||||
auto id2 = result2.Int("id");
|
||||
|
||||
if (id1 == 0 || id2 == 0)
|
||||
return false;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "ERROR: " << e.what() << std::endl;
|
||||
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Test
|
||||
Reference in New Issue
Block a user