Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobert <krzmbrzl@gmail.com>2020-09-11 19:29:33 +0300
committerRobert <krzmbrzl@gmail.com>2020-09-11 19:29:33 +0300
commitaf7dac72f4063dd8d4dac71973ea51c25896089a (patch)
tree35558695aea94d48fd9e77d164d63fd8b7c76e90 /src/tests
parent40b28b03c150b453e00c6bc4f8d6957caea59c51 (diff)
FORMAT: Run clang-format 10 on all C/CXX source-files
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Benchmark.cpp259
-rw-r--r--src/tests/Collections.cpp81
-rw-r--r--src/tests/Emit.cpp70
-rw-r--r--src/tests/Hash.cpp57
-rw-r--r--src/tests/Lock.cpp56
-rw-r--r--src/tests/OverlayTest.cpp189
-rw-r--r--src/tests/ProtoBuf.cpp48
-rw-r--r--src/tests/Resample.cpp46
-rw-r--r--src/tests/TestCrypt/TestCrypt.cpp144
-rw-r--r--src/tests/TestCryptographicHash/TestCryptographicHash.cpp71
-rw-r--r--src/tests/TestCryptographicRandom/TestCryptographicRandom.cpp32
-rw-r--r--src/tests/TestFFDHE/TestFFDHE.cpp28
-rw-r--r--src/tests/TestLink.cpp37
-rw-r--r--src/tests/TestPacketDataStream/TestPacketDataStream.cpp50
-rw-r--r--src/tests/TestPasswordGenerator/TestPasswordGenerator.cpp14
-rw-r--r--src/tests/TestSSLLocks/TestSSLLocks.cpp21
-rw-r--r--src/tests/TestSelfSignedCertificate/TestSelfSignedCertificate.cpp22
-rw-r--r--src/tests/TestServerAddress/TestServerAddress.cpp22
-rw-r--r--src/tests/TestServerResolver/TestServerResolver.cpp42
-rw-r--r--src/tests/TestStdAbs/TestStdAbs.cpp8
-rw-r--r--src/tests/TestTimer/TestTimer.cpp21
-rw-r--r--src/tests/TestUnresolvedServerAddress/TestUnresolvedServerAddress.cpp26
-rw-r--r--src/tests/TestXMLTools/TestXMLTools.cpp235
23 files changed, 826 insertions, 753 deletions
diff --git a/src/tests/Benchmark.cpp b/src/tests/Benchmark.cpp
index 7919c7049..216d266ea 100644
--- a/src/tests/Benchmark.cpp
+++ b/src/tests/Benchmark.cpp
@@ -7,62 +7,61 @@
#include <QtNetwork>
#ifndef Q_OS_WIN
-#include <unistd.h>
+# include <unistd.h>
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/stat.h>
#include <sys/types.h>
#ifndef Q_OS_WIN
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <sys/utsname.h>
+# include <netinet/in.h>
+# include <netinet/ip.h>
+# include <sys/socket.h>
+# include <sys/utsname.h>
#endif
#include <errno.h>
+#include "Message.h"
+#include "Mumble.pb.h"
#include "PacketDataStream.h"
#include "Timer.h"
-#include "Message.h"
#include "crypto/CryptState.h"
-#include "Mumble.pb.h"
-#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
- #include <QRandomGenerator>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+# include <QRandomGenerator>
#endif
class Client : public QThread {
- Q_OBJECT
- public:
- bool udp;
- bool sender;
- struct sockaddr_in srv;
- unsigned int uiSession;
- CryptStateOCB2 crypt;
- int rcvd;
- int socket;
- int seq;
- void run();
- void ping();
- void sendVoice();
- int numbytes;
- int ptype;
- QSslSocket *ssl;
- Client(QObject *parent, QHostAddress srvaddr, unsigned short prt, bool send, bool tcponly);
- void doUdp(const unsigned char *buffer, int size);
- void sendMessage(const ::google::protobuf::Message &msg, unsigned int msgType);
- ~Client();
- public slots:
- void readyRead();
- void disconnected();
+ Q_OBJECT
+public:
+ bool udp;
+ bool sender;
+ struct sockaddr_in srv;
+ unsigned int uiSession;
+ CryptStateOCB2 crypt;
+ int rcvd;
+ int socket;
+ int seq;
+ void run();
+ void ping();
+ void sendVoice();
+ int numbytes;
+ int ptype;
+ QSslSocket *ssl;
+ Client(QObject *parent, QHostAddress srvaddr, unsigned short prt, bool send, bool tcponly);
+ void doUdp(const unsigned char *buffer, int size);
+ void sendMessage(const ::google::protobuf::Message &msg, unsigned int msgType);
+ ~Client();
+public slots:
+ void readyRead();
+ void disconnected();
};
Client::Client(QObject *p, QHostAddress qha, unsigned short prt, bool send, bool tcponly) : QThread(p) {
- srv.sin_family = AF_INET;
+ srv.sin_family = AF_INET;
srv.sin_addr.s_addr = htonl(qha.toIPv4Address());
- srv.sin_port = htons(prt);
+ srv.sin_port = htons(prt);
- udp = ! tcponly;
+ udp = !tcponly;
sender = send;
ssl = new QSslSocket(this);
@@ -73,7 +72,7 @@ Client::Client(QObject *p, QHostAddress qha, unsigned short prt, bool send, bool
ssl->setProtocol(QSsl::TlsV1);
ssl->connectToHostEncrypted(qha.toString(), prt);
ssl->ignoreSslErrors();
- if (! ssl->waitForEncrypted())
+ if (!ssl->waitForEncrypted())
qFatal("Connection failure");
static int ctr = 1;
@@ -108,8 +107,8 @@ Client::Client(QObject *p, QHostAddress qha, unsigned short prt, bool send, bool
if (udp)
socket = ::socket(PF_INET, SOCK_DGRAM, 0);
- seq = 0;
- rcvd = 0;
+ seq = 0;
+ rcvd = 0;
numbytes = -1;
}
@@ -123,12 +122,12 @@ void Client::sendMessage(const ::google::protobuf::Message &msg, unsigned int ms
int len = msg.ByteSize();
Q_ASSERT(len < 4090);
- * reinterpret_cast<quint16 *>(& uc[0]) = qToBigEndian(static_cast<quint16>(msgType));
- * reinterpret_cast<quint32 *>(& uc[2]) = qToBigEndian(static_cast<quint32>(len));
+ *reinterpret_cast< quint16 * >(&uc[0]) = qToBigEndian(static_cast< quint16 >(msgType));
+ *reinterpret_cast< quint32 * >(&uc[2]) = qToBigEndian(static_cast< quint32 >(len));
msg.SerializeToArray(uc + 6, len);
- ssl->write(reinterpret_cast<const char *>(uc), len + 6);
+ ssl->write(reinterpret_cast< const char * >(uc), len + 6);
}
void Client::ping() {
@@ -146,7 +145,7 @@ void Client::ping() {
void Client::sendVoice() {
unsigned char buffer[1024];
-#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
int len = 32 + (QRandomGenerator::global()->generate() & 0x3f);
#else
// Qt 5.10 introduces the QRandomGenerator class and in Qt 5.15 qrand got deprecated in its favor
@@ -165,13 +164,14 @@ void Client::sendVoice() {
}
void Client::doUdp(const unsigned char *buffer, int size) {
- if (! udp || ! crypt.isValid())
+ if (!udp || !crypt.isValid())
return;
unsigned char crypted[2048];
- crypt.encrypt(reinterpret_cast<const unsigned char *>(buffer), crypted, size);
- ::sendto(socket, reinterpret_cast<const char *>(crypted), size+4, 0, reinterpret_cast<struct sockaddr *>(&srv), sizeof(srv));
+ crypt.encrypt(reinterpret_cast< const unsigned char * >(buffer), crypted, size);
+ ::sendto(socket, reinterpret_cast< const char * >(crypted), size + 4, 0,
+ reinterpret_cast< struct sockaddr * >(&srv), sizeof(srv));
}
@@ -181,12 +181,13 @@ void Client::run() {
socklen_t sz;
int len;
- if (! udp)
+ if (!udp)
return;
forever {
- sz = sizeof(addr);
- len = ::recvfrom(socket, reinterpret_cast<char *>(buffer), 1024, 0, reinterpret_cast<struct sockaddr *>(&addr), &sz);
+ sz = sizeof(addr);
+ len = ::recvfrom(socket, reinterpret_cast< char * >(buffer), 1024, 0,
+ reinterpret_cast< struct sockaddr * >(&addr), &sz);
if (len <= 0)
break;
if (len >= 32)
@@ -201,10 +202,10 @@ void Client::readyRead() {
if (avail < 6)
break;
unsigned char b[6];
- ssl->read(reinterpret_cast<char *>(b), 6);
+ ssl->read(reinterpret_cast< char * >(b), 6);
- ptype = qFromBigEndian(* reinterpret_cast<quint16 *>(& b[0]));
- numbytes = qFromBigEndian(* reinterpret_cast<quint32 *>(& b[2]));
+ ptype = qFromBigEndian(*reinterpret_cast< quint16 * >(&b[0]));
+ numbytes = qFromBigEndian(*reinterpret_cast< quint32 * >(&b[2]));
avail = ssl->bytesAvailable();
}
@@ -213,49 +214,50 @@ void Client::readyRead() {
numbytes = -1;
unsigned char buff[65536];
Q_ASSERT(want < 65536);
- ssl->read(reinterpret_cast<char *>(buff), want);
+ ssl->read(reinterpret_cast< char * >(buff), want);
avail = ssl->bytesAvailable();
switch (ptype) {
case MessageHandler::CryptSetup: {
- MumbleProto::CryptSetup msg;
- if (! msg.ParseFromArray(buff, want))
- qFatal("Failed parse crypt");
-
- if (msg.has_key() && msg.has_client_nonce() && msg.has_server_nonce()) {
- const std::string &key = msg.key();
- const std::string &client_nonce = msg.client_nonce();
- const std::string &server_nonce = msg.server_nonce();
- if (key.size() == AES_BLOCK_SIZE && client_nonce.size() == AES_BLOCK_SIZE && server_nonce.size() == AES_BLOCK_SIZE)
- crypt.setKey(key, client_nonce, server_nonce);
- } else if (msg.has_server_nonce()) {
- const std::string &server_nonce = msg.server_nonce();
- if (server_nonce.size() == AES_BLOCK_SIZE) {
- crypt.uiResync++;
- crypt.setDecryptIV(server_nonce);
- }
- } else {
- MumbleProto::CryptSetup mpcs;
- mpcs.set_client_nonce(crypt.getEncryptIV());
- sendMessage(mpcs, MessageHandler::CryptSetup);
+ MumbleProto::CryptSetup msg;
+ if (!msg.ParseFromArray(buff, want))
+ qFatal("Failed parse crypt");
+
+ if (msg.has_key() && msg.has_client_nonce() && msg.has_server_nonce()) {
+ const std::string &key = msg.key();
+ const std::string &client_nonce = msg.client_nonce();
+ const std::string &server_nonce = msg.server_nonce();
+ if (key.size() == AES_BLOCK_SIZE && client_nonce.size() == AES_BLOCK_SIZE
+ && server_nonce.size() == AES_BLOCK_SIZE)
+ crypt.setKey(key, client_nonce, server_nonce);
+ } else if (msg.has_server_nonce()) {
+ const std::string &server_nonce = msg.server_nonce();
+ if (server_nonce.size() == AES_BLOCK_SIZE) {
+ crypt.uiResync++;
+ crypt.setDecryptIV(server_nonce);
}
- break;
+ } else {
+ MumbleProto::CryptSetup mpcs;
+ mpcs.set_client_nonce(crypt.getEncryptIV());
+ sendMessage(mpcs, MessageHandler::CryptSetup);
}
+ break;
+ }
case MessageHandler::ServerSync: {
- MumbleProto::ServerSync msg;
- if (! msg.ParseFromArray(buff, want))
- qFatal("Failed parse sync");
- uiSession = msg.session();
- break;
- }
+ MumbleProto::ServerSync msg;
+ if (!msg.ParseFromArray(buff, want))
+ qFatal("Failed parse sync");
+ uiSession = msg.session();
+ break;
+ }
case MessageHandler::UDPTunnel: {
- unsigned int msgUDPType = (buff[0] >> 5) & 0x7;
- if (msgUDPType == MessageHandler::UDPVoiceCELTAlpha)
- rcvd++;
- break;
- }
+ unsigned int msgUDPType = (buff[0] >> 5) & 0x7;
+ if (msgUDPType == MessageHandler::UDPVoiceCELTAlpha)
+ rcvd++;
+ break;
+ }
}
} else {
break;
@@ -269,38 +271,38 @@ void Client::disconnected() {
}
class Container : public QObject {
- Q_OBJECT
- public:
- int sent;
- int numsender, numudplistener, numtcplistener;
- int isender, iudplistener, itcplistener;
- bool live, forceping;
- QHostAddress qha;
- unsigned short port;
- QTimer qtTick;
- Timer tickPing, tickVoice, tickGo, tickSpawn;
- QList<Client *> speakers;
- QList<Client *> clients;
- Container(QHostAddress srvaddr, unsigned short port, int nsend, int nudp, int ntcp);
- public slots:
- void tick();
- void go();
+ Q_OBJECT
+public:
+ int sent;
+ int numsender, numudplistener, numtcplistener;
+ int isender, iudplistener, itcplistener;
+ bool live, forceping;
+ QHostAddress qha;
+ unsigned short port;
+ QTimer qtTick;
+ Timer tickPing, tickVoice, tickGo, tickSpawn;
+ QList< Client * > speakers;
+ QList< Client * > clients;
+ Container(QHostAddress srvaddr, unsigned short port, int nsend, int nudp, int ntcp);
+public slots:
+ void tick();
+ void go();
};
Container::Container(QHostAddress qha, unsigned short port, int numsend, int numudp, int numtcp) {
isender = iudplistener = itcplistener = 0;
- live = false;
- forceping = false;
- sent = 0;
+ live = false;
+ forceping = false;
+ sent = 0;
Timer t;
- qWarning("Spawning %d speakers and %d listeners (%d UDP, %d TCP)", numsend, numudp+numtcp, numudp, numtcp);
+ qWarning("Spawning %d speakers and %d listeners (%d UDP, %d TCP)", numsend, numudp + numtcp, numudp, numtcp);
- this->qha = qha;
+ this->qha = qha;
this->port = port;
- numsender = numsend;
+ numsender = numsend;
numudplistener = numudp;
numtcplistener = numtcp;
@@ -315,34 +317,35 @@ void Container::tick() {
if (forceping || tickPing.isElapsed(5000000ULL)) {
forceping = false;
- foreach(Client *c, clients)
+ foreach (Client *c, clients)
c->ping();
if (live) {
-
- int lost = 0;
+ int lost = 0;
quint64 totrcv = 0;
- int nrcv = 0;
- foreach(Client *c, clients) {
- if (! c->sender) {
+ int nrcv = 0;
+ foreach (Client *c, clients) {
+ if (!c->sender) {
totrcv += c->rcvd;
lost += sent - c->rcvd;
nrcv++;
}
}
- qWarning("Sent: %8d Rcvd: %8lld Lost: %8d BW: %6.1fMbit/s", sent, totrcv / nrcv, (lost + nrcv - 1) / nrcv, (totrcv * 8.0 * 123.0) / (tickGo.elapsed() * 1.0));
+ qWarning("Sent: %8d Rcvd: %8lld Lost: %8d BW: %6.1fMbit/s", sent, totrcv / nrcv,
+ (lost + nrcv - 1) / nrcv, (totrcv * 8.0 * 123.0) / (tickGo.elapsed() * 1.0));
} else {
- qWarning("Spawned %3d/%3d", isender + iudplistener + itcplistener, numsender + numudplistener + numtcplistener);
+ qWarning("Spawned %3d/%3d", isender + iudplistener + itcplistener,
+ numsender + numudplistener + numtcplistener);
}
}
if (live && tickVoice.isElapsed(10000ULL)) {
- foreach(Client *c, speakers) {
+ foreach (Client *c, speakers) {
sent++;
c->sendVoice();
}
}
- if (! live) {
+ if (!live) {
if (isender < numsender) {
// Spawn a sender
Client *c = new Client(this, qha, port, true, false);
@@ -363,12 +366,13 @@ void Container::tick() {
clients << c;
itcplistener++;
} else {
- live = true;
+ live = true;
quint64 elapsed = tickSpawn.elapsed();
- qWarning("Spawning took %lld ms (%lld us per client)", elapsed / 1000ULL, elapsed / (numsender+numudplistener+numtcplistener));
- foreach(Client *c, clients)
+ qWarning("Spawning took %lld ms (%lld us per client)", elapsed / 1000ULL,
+ elapsed / (numsender + numudplistener + numtcplistener));
+ foreach (Client *c, clients)
c->rcvd = 0;
- sent = 0;
+ sent = 0;
forceping = true;
qtTick.start(10);
}
@@ -376,7 +380,7 @@ void Container::tick() {
}
void Container::go() {
- foreach(Client *c, clients)
+ foreach (Client *c, clients)
c->start();
qtTick.start(10);
tickGo.restart();
@@ -388,11 +392,12 @@ int main(int argc, char **argv) {
qWarning("Maximum # sockets is %d", FD_SETSIZE);
if (argc != 6)
- qFatal("Invalid number of arguments. These need to be passed: <host address> <port> <numsend> <numudp> <numtcp>");
+ qFatal(
+ "Invalid number of arguments. These need to be passed: <host address> <port> <numsend> <numudp> <numtcp>");
- QHostAddress qha = QHostAddress(argv[1]);
- int port = atoi(argv[2]);
- int numsender = atoi(argv[3]);
+ QHostAddress qha = QHostAddress(argv[1]);
+ int port = atoi(argv[2]);
+ int numsender = atoi(argv[3]);
int numudplistener = atoi(argv[4]);
int numtcplistener = atoi(argv[5]);
diff --git a/src/tests/Collections.cpp b/src/tests/Collections.cpp
index 8114bcb9a..30a5b3930 100644
--- a/src/tests/Collections.cpp
+++ b/src/tests/Collections.cpp
@@ -12,17 +12,14 @@ using namespace std;
#define SL 10000
#define NE 300
-template<class T>
-class QListSet {
- public:
- QList<T> l;
- void insert(const T &i) {
- if (! l.contains(i))
- l.append(i);
- }
- void remove(const T &i) {
- l.removeAll(i);
- }
+template< class T > class QListSet {
+public:
+ QList< T > l;
+ void insert(const T &i) {
+ if (!l.contains(i))
+ l.append(i);
+ }
+ void remove(const T &i) { l.removeAll(i); }
};
int main(int argc, char **argv) {
@@ -32,14 +29,14 @@ int main(int argc, char **argv) {
{
t.restart();
- QSet<int> s;
+ QSet< int > s;
s.reserve(NE);
- for (int i=0;i<NE;i++)
+ for (int i = 0; i < NE; i++)
s.insert(i);
usins = t.restart();
- sum = 0;
- for (int j=0;j<SL;j++)
- foreach(int v, s)
+ sum = 0;
+ for (int j = 0; j < SL; j++)
+ foreach (int v, s)
sum += v;
usiter = t.restart();
}
@@ -47,13 +44,13 @@ int main(int argc, char **argv) {
{
t.restart();
- QList<int> s;
- for (int i=0;i<NE;i++)
+ QList< int > s;
+ for (int i = 0; i < NE; i++)
s.append(i);
usins = t.restart();
- sum = 0;
- for (int j=0;j<SL;j++)
- foreach(int v, s)
+ sum = 0;
+ for (int j = 0; j < SL; j++)
+ foreach (int v, s)
sum += v;
usiter = t.restart();
}
@@ -61,14 +58,14 @@ int main(int argc, char **argv) {
{
t.restart();
- QVector<int> s;
+ QVector< int > s;
s.reserve(NE);
- for (int i=0;i<NE;i++)
+ for (int i = 0; i < NE; i++)
s.append(i);
usins = t.restart();
- sum = 0;
- for (int j=0;j<SL;j++)
- foreach(int v, s)
+ sum = 0;
+ for (int j = 0; j < SL; j++)
+ foreach (int v, s)
sum += v;
usiter = t.restart();
}
@@ -76,14 +73,14 @@ int main(int argc, char **argv) {
{
t.restart();
- vector<int> s;
- for (int i=0;i<NE;i++)
+ vector< int > s;
+ for (int i = 0; i < NE; i++)
s.push_back(i);
- usins = t.restart();
- sum = 0;
+ usins = t.restart();
+ sum = 0;
int sz = s.size();
- for (int j=0;j<SL;j++)
- for (int i=0;i<sz;i++)
+ for (int j = 0; j < SL; j++)
+ for (int i = 0; i < sz; i++)
sum += s[i];
usiter = t.restart();
}
@@ -92,12 +89,12 @@ int main(int argc, char **argv) {
{
t.restart();
int s[NE];
- for (int i=0;i<NE;i++)
- s[i]=i;
+ for (int i = 0; i < NE; i++)
+ s[i] = i;
usins = t.restart();
- sum = 0;
- for (int j=0;j<SL;j++)
- for (int i=0;i<NE;i++)
+ sum = 0;
+ for (int j = 0; j < SL; j++)
+ for (int i = 0; i < NE; i++)
sum += s[i];
usiter = t.restart();
}
@@ -106,13 +103,13 @@ int main(int argc, char **argv) {
{
t.restart();
- QListSet<int> s;
- for (int i=0;i<NE;i++)
+ QListSet< int > s;
+ for (int i = 0; i < NE; i++)
s.insert(i);
usins = t.restart();
- sum = 0;
- for (int j=0;j<SL;j++)
- foreach(int v, s.l)
+ sum = 0;
+ for (int j = 0; j < SL; j++)
+ foreach (int v, s.l)
sum += v;
usiter = t.restart();
}
diff --git a/src/tests/Emit.cpp b/src/tests/Emit.cpp
index 533c31fda..81417573c 100644
--- a/src/tests/Emit.cpp
+++ b/src/tests/Emit.cpp
@@ -1,100 +1,92 @@
+#include "Timer.h"
#include <QtCore>
-#include <boost/signals.hpp>
#include <boost/bind.hpp>
-#include "Timer.h"
+#include <boost/signals.hpp>
class Slotter : public QObject {
- Q_OBJECT;
- public:
- Slotter(QObject *p = nullptr) : QObject(p) {};
- public Q_SLOTS:
- virtual void slottest(int &res) {
- res+= 1;
- };
+ Q_OBJECT;
+
+public:
+ Slotter(QObject *p = nullptr) : QObject(p){};
+public Q_SLOTS:
+ virtual void slottest(int &res) { res += 1; };
};
class Emitter : public QObject {
- Q_OBJECT;
- public:
- Slotter *s;
- Emitter(Slotter *s) : QObject(s) {
- this->s = s;
- };
-
- boost::signal< void(int &) > bsig;
- Q_SIGNALS:
- void sig(int &);
- public Q_SLOTS:
- void emittest(int &val) {
- Q_EMIT sig(val);
- };
- void directtest(int &val) {
- s->slottest(val);
- };
- void boosttest(int &val) {
- bsig(val);
- }
+ Q_OBJECT;
+
+public:
+ Slotter *s;
+ Emitter(Slotter *s) : QObject(s) { this->s = s; };
+
+ boost::signal< void(int &) > bsig;
+Q_SIGNALS:
+ void sig(int &);
+public Q_SLOTS:
+ void emittest(int &val) { Q_EMIT sig(val); };
+ void directtest(int &val) { s->slottest(val); };
+ void boosttest(int &val) { bsig(val); }
};
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
Timer t;
- Slotter *s = new Slotter();
+ Slotter *s = new Slotter();
Slotter *s2 = new Slotter();
- Emitter *e = new Emitter(s);
+ Emitter *e = new Emitter(s);
int v;
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
s->slottest(v);
printf("Raw : %8lld %d\n", t.elapsed(), v);
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->directtest(v);
printf("Direct: %8lld %d\n", t.elapsed(), v);
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->emittest(v);
printf("NoSig : %8lld %d\n", t.elapsed(), v);
QObject::connect(e, SIGNAL(sig(int &)), s, SLOT(slottest(int &)));
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->emittest(v);
printf("Signal: %8lld %d\n", t.elapsed(), v);
QObject::connect(e, SIGNAL(sig(int &)), s2, SLOT(slottest(int &)));
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->emittest(v);
printf("2Slots: %8lld %d\n", t.elapsed(), v);
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->boosttest(v);
printf("BNoSig: %8lld %d\n", t.elapsed(), v);
e->bsig.connect(boost::bind(&Slotter::slottest, s, _1));
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->boosttest(v);
printf("Boost: %8lld %d\n", t.elapsed(), v);
e->bsig.connect(boost::bind(&Slotter::slottest, s2, _1));
v = 0;
t.restart();
- for (int i=0;i<1000000;++i)
+ for (int i = 0; i < 1000000; ++i)
e->boosttest(v);
printf("2Boost: %8lld %d\n", t.elapsed(), v);
}
diff --git a/src/tests/Hash.cpp b/src/tests/Hash.cpp
index ad6b0713a..a82408177 100644
--- a/src/tests/Hash.cpp
+++ b/src/tests/Hash.cpp
@@ -4,46 +4,42 @@
#define ITER 100000
-typedef QPair<quint64,int> tr;
+typedef QPair< quint64, int > tr;
-template<class T>
-class SpeedTest {
- public:
- QList<T> list;
+template< class T > class SpeedTest {
+public:
+ QList< T > list;
- SpeedTest() {
- }
+ SpeedTest() {}
- void add(T v) {
- list << v;
- }
+ void add(T v) { list << v; }
- tr testres(T v) {
- int val = 0;
- Timer t;
- t.restart();
- for (int i=0;i<ITER;i++) {
- if (list.contains(v))
- val++;
- }
- return tr(t.elapsed(), val);
+ tr testres(T v) {
+ int val = 0;
+ Timer t;
+ t.restart();
+ for (int i = 0; i < ITER; i++) {
+ if (list.contains(v))
+ val++;
}
+ return tr(t.elapsed(), val);
+ }
};
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
- QSet<int> set;
- SpeedTest<QVariant> stv;
- SpeedTest<int> sti;
- SpeedTest<QList<QVariant> > stl;
- SpeedTest<QVariant> stvl;
+ QSet< int > set;
+ SpeedTest< QVariant > stv;
+ SpeedTest< int > sti;
+ SpeedTest< QList< QVariant > > stl;
+ SpeedTest< QVariant > stvl;
- for (int i=0;i<300;i++) {
+ for (int i = 0; i < 300; i++) {
set.insert(i);
QVariant v = i;
- QList<QVariant> ql;
+ QList< QVariant > ql;
ql << v;
QVariant vl = QVariant(ql);
@@ -53,9 +49,9 @@ int main(int argc, char **argv) {
stvl.add(vl);
}
- int i = 397;
+ int i = 397;
QVariant v = i;
- QList<QVariant> ql;
+ QList< QVariant > ql;
ql << v;
QVariant vl = QVariant(ql);
@@ -63,10 +59,10 @@ int main(int argc, char **argv) {
tr t;
int val = 0;
tt.restart();
- for (int i=0;i<ITER;i++)
+ for (int i = 0; i < ITER; i++)
if (set.contains(i))
val++;
- t.first = tt.elapsed();
+ t.first = tt.elapsed();
t.second = val;
qWarning("set: %llu", t.first);
@@ -81,7 +77,6 @@ int main(int argc, char **argv) {
t = stvl.testres(vl);
qWarning("vls: %llu", t.first / ITER);
-
}
#include "Hash.moc"
diff --git a/src/tests/Lock.cpp b/src/tests/Lock.cpp
index 22b83d0ea..48edf602b 100644
--- a/src/tests/Lock.cpp
+++ b/src/tests/Lock.cpp
@@ -12,14 +12,14 @@
// one timeslice.
#define ITER 100000000
-typedef QPair<quint64,int> tr;
+typedef QPair< quint64, int > tr;
class SillyLock {
- public:
- int counter;
- SillyLock();
- void lock();
- void unlock();
+public:
+ int counter;
+ SillyLock();
+ void lock();
+ void unlock();
};
SillyLock::SillyLock() {
@@ -41,11 +41,11 @@ void SillyLock::unlock() {
}
class PosixLock {
- public:
- pthread_mutex_t m;
- PosixLock();
- void lock();
- void unlock();
+public:
+ pthread_mutex_t m;
+ PosixLock();
+ void lock();
+ void unlock();
};
PosixLock::PosixLock() {
@@ -60,23 +60,21 @@ void PosixLock::unlock() {
pthread_mutex_unlock(&m);
}
-template<class T>
-class SpeedTest {
- public:
- T &lock;
+template< class T > class SpeedTest {
+public:
+ T &lock;
- SpeedTest(T &l) : lock(l) {
- }
+ SpeedTest(T &l) : lock(l) {}
- quint64 test() {
- Timer t;
- t.restart();
- for (int i=0;i<ITER;i++) {
- lock.lock();
- lock.unlock();
- }
- return t.elapsed();
+ quint64 test() {
+ Timer t;
+ t.restart();
+ for (int i = 0; i < ITER; i++) {
+ lock.lock();
+ lock.unlock();
}
+ return t.elapsed();
+ }
};
int main(int argc, char **argv) {
@@ -87,10 +85,10 @@ int main(int argc, char **argv) {
SillyLock sl;
PosixLock pl;
- SpeedTest<QMutex> stqm(qm);
- SpeedTest<QMutex> stqmr(qmr);
- SpeedTest<SillyLock> stsl(sl);
- SpeedTest<PosixLock> stpl(pl);
+ SpeedTest< QMutex > stqm(qm);
+ SpeedTest< QMutex > stqmr(qmr);
+ SpeedTest< SillyLock > stsl(sl);
+ SpeedTest< PosixLock > stpl(pl);
quint64 elapsed;
diff --git a/src/tests/OverlayTest.cpp b/src/tests/OverlayTest.cpp
index f909af245..56152c6c3 100644
--- a/src/tests/OverlayTest.cpp
+++ b/src/tests/OverlayTest.cpp
@@ -8,51 +8,52 @@
#include "Timer.h"
#ifdef Q_OS_WIN
-# include "win.h"
+# include "win.h"
#endif
#include <QtCore>
-#include <QtNetwork>
#include <QtGui>
+#include <QtNetwork>
#include <ctime>
class OverlayWidget : public QWidget {
- Q_OBJECT
-
- protected:
- QImage img;
- OverlayMsg om;
- QLocalSocket *qlsSocket;
- SharedMemory2 *smMem;
- QTimer *qtTimer;
- QRect qrActive;
- QTime qtWall;
-
- unsigned int iFrameCount;
- int iLastFpsUpdate;
-
- unsigned int uiWidth, uiHeight;
-
- void resizeEvent(QResizeEvent *);
- void paintEvent(QPaintEvent *);
- void init(const QSize &);
- void detach();
-
- void keyPressEvent(QKeyEvent *);
- protected slots:
- void connected();
- void disconnected();
- void readyRead();
- void error(QLocalSocket::LocalSocketError);
- void update();
- public:
- OverlayWidget(QWidget *p = nullptr);
+ Q_OBJECT
+
+protected:
+ QImage img;
+ OverlayMsg om;
+ QLocalSocket *qlsSocket;
+ SharedMemory2 *smMem;
+ QTimer *qtTimer;
+ QRect qrActive;
+ QTime qtWall;
+
+ unsigned int iFrameCount;
+ int iLastFpsUpdate;
+
+ unsigned int uiWidth, uiHeight;
+
+ void resizeEvent(QResizeEvent *);
+ void paintEvent(QPaintEvent *);
+ void init(const QSize &);
+ void detach();
+
+ void keyPressEvent(QKeyEvent *);
+protected slots:
+ void connected();
+ void disconnected();
+ void readyRead();
+ void error(QLocalSocket::LocalSocketError);
+ void update();
+
+public:
+ OverlayWidget(QWidget *p = nullptr);
};
OverlayWidget::OverlayWidget(QWidget *p) : QWidget(p) {
qlsSocket = nullptr;
- smMem = nullptr;
+ smMem = nullptr;
uiWidth = uiHeight = 0;
setFocusPolicy(Qt::StrongFocus);
@@ -72,20 +73,21 @@ void OverlayWidget::keyPressEvent(QKeyEvent *evt) {
void OverlayWidget::resizeEvent(QResizeEvent *evt) {
QWidget::resizeEvent(evt);
- if (! img.isNull())
+ if (!img.isNull())
img = img.scaled(evt->size().width(), evt->size().height());
init(evt->size());
}
void OverlayWidget::paintEvent(QPaintEvent *) {
- if (! qlsSocket || qlsSocket->state() == QLocalSocket::UnconnectedState) {
+ if (!qlsSocket || qlsSocket->state() == QLocalSocket::UnconnectedState) {
detach();
qlsSocket = new QLocalSocket(this);
connect(qlsSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(qlsSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(qlsSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
- connect(qlsSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(error(QLocalSocket::LocalSocketError)));
+ connect(qlsSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), this,
+ SLOT(error(QLocalSocket::LocalSocketError)));
#ifdef Q_OS_WIN
qlsSocket->connectToServer(QLatin1String("MumbleOverlayPipe"));
#else
@@ -94,7 +96,7 @@ void OverlayWidget::paintEvent(QPaintEvent *) {
}
QPainter painter(this);
- painter.fillRect(0, 0, width(), height(), QColor(128,0,128));
+ painter.fillRect(0, 0, width(), height(), QColor(128, 0, 128));
painter.setClipRect(qrActive);
painter.drawImage(0, 0, img);
}
@@ -103,14 +105,14 @@ void OverlayWidget::init(const QSize &sz) {
qWarning() << "Init" << sz.width() << sz.height();
qtWall.start();
- iFrameCount = 0;
+ iFrameCount = 0;
iLastFpsUpdate = 0;
OverlayMsg m;
- m.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
- m.omh.uiType = OVERLAY_MSGTYPE_INIT;
- m.omh.iLength = sizeof(OverlayMsgInit);
- m.omi.uiWidth = sz.width();
+ m.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
+ m.omh.uiType = OVERLAY_MSGTYPE_INIT;
+ m.omh.iLength = sizeof(OverlayMsgInit);
+ m.omi.uiWidth = sz.width();
m.omi.uiHeight = sz.height();
if (qlsSocket && qlsSocket->state() == QLocalSocket::ConnectedState)
@@ -135,7 +137,7 @@ void OverlayWidget::connected() {
OverlayMsg m;
m.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
- m.omh.uiType = OVERLAY_MSGTYPE_PID;
+ m.omh.uiType = OVERLAY_MSGTYPE_PID;
m.omh.iLength = sizeof(OverlayMsgPid);
#ifdef Q_OS_WIN
m.omp.pid = GetCurrentProcessId();
@@ -152,7 +154,7 @@ void OverlayWidget::connected() {
void OverlayWidget::disconnected() {
qWarning() << "disconnected";
- QLocalSocket *qls = qobject_cast<QLocalSocket *>(sender());
+ QLocalSocket *qls = qobject_cast< QLocalSocket * >(sender());
if (qls == qlsSocket) {
detach();
}
@@ -166,21 +168,21 @@ void OverlayWidget::error(QLocalSocket::LocalSocketError) {
void OverlayWidget::update() {
++iFrameCount;
- clock_t t = clock();
- float elapsed = static_cast<float>(qtWall.elapsed() - iLastFpsUpdate) / 1000.0f;
+ clock_t t = clock();
+ float elapsed = static_cast< float >(qtWall.elapsed() - iLastFpsUpdate) / 1000.0f;
if (elapsed > OVERLAY_FPS_INTERVAL) {
struct OverlayMsg om;
om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
- om.omh.uiType = OVERLAY_MSGTYPE_FPS;
+ om.omh.uiType = OVERLAY_MSGTYPE_FPS;
om.omh.iLength = sizeof(struct OverlayMsgFps);
- om.omf.fps = static_cast<int>(static_cast<float>(iFrameCount) / elapsed);
+ om.omf.fps = static_cast< int >(static_cast< float >(iFrameCount) / elapsed);
if (qlsSocket && qlsSocket->state() == QLocalSocket::ConnectedState) {
- qlsSocket->write(reinterpret_cast<char*>(&om), sizeof(OverlayMsgHeader) + om.omh.iLength);
+ qlsSocket->write(reinterpret_cast< char * >(&om), sizeof(OverlayMsgHeader) + om.omh.iLength);
}
- iFrameCount = 0;
+ iFrameCount = 0;
iLastFpsUpdate = 0;
qtWall.start();
}
@@ -189,7 +191,7 @@ void OverlayWidget::update() {
}
void OverlayWidget::readyRead() {
- QLocalSocket *qls = qobject_cast<QLocalSocket *>(sender());
+ QLocalSocket *qls = qobject_cast< QLocalSocket * >(sender());
if (qls != qlsSocket)
return;
@@ -200,8 +202,9 @@ void OverlayWidget::readyRead() {
if (ready < sizeof(OverlayMsgHeader))
break;
else {
- qlsSocket->read(reinterpret_cast<char *>(om.headerbuffer), sizeof(OverlayMsgHeader));
- if ((om.omh.uiMagic != OVERLAY_MAGIC_NUMBER) || (om.omh.iLength < 0) || (om.omh.iLength > sizeof(OverlayMsgShmem))) {
+ qlsSocket->read(reinterpret_cast< char * >(om.headerbuffer), sizeof(OverlayMsgHeader));
+ if ((om.omh.uiMagic != OVERLAY_MAGIC_NUMBER) || (om.omh.iLength < 0)
+ || (om.omh.iLength > sizeof(OverlayMsgShmem))) {
detach();
return;
}
@@ -221,53 +224,50 @@ void OverlayWidget::readyRead() {
switch (om.omh.uiType) {
case OVERLAY_MSGTYPE_SHMEM: {
- OverlayMsgShmem *oms = & om.oms;
- QString key = QString::fromUtf8(oms->a_cName, length);
- qWarning() << "SHMAT" << key;
- if (smMem)
- delete smMem;
- smMem = new SharedMemory2(this, width() * height() * 4, key);
- if (! smMem->data()) {
- qWarning() << "SHMEM FAIL";
- delete smMem;
- smMem = nullptr;
- } else {
- qWarning() << "SHMEM" << smMem->size();
- }
+ OverlayMsgShmem *oms = &om.oms;
+ QString key = QString::fromUtf8(oms->a_cName, length);
+ qWarning() << "SHMAT" << key;
+ if (smMem)
+ delete smMem;
+ smMem = new SharedMemory2(this, width() * height() * 4, key);
+ if (!smMem->data()) {
+ qWarning() << "SHMEM FAIL";
+ delete smMem;
+ smMem = nullptr;
+ } else {
+ qWarning() << "SHMEM" << smMem->size();
}
- break;
+ } break;
case OVERLAY_MSGTYPE_BLIT: {
- OverlayMsgBlit *omb = & om.omb;
- length -= sizeof(OverlayMsgBlit);
-
- qWarning() << "BLIT" << omb->x << omb->y << omb->w << omb->h;
+ OverlayMsgBlit *omb = &om.omb;
+ length -= sizeof(OverlayMsgBlit);
- if (! smMem)
- break;
+ qWarning() << "BLIT" << omb->x << omb->y << omb->w << omb->h;
- if (((omb->x + omb->w) > img.width()) ||
- ((omb->y + omb->h) > img.height()))
- break;
+ if (!smMem)
+ break;
+ if (((omb->x + omb->w) > img.width()) || ((omb->y + omb->h) > img.height()))
+ break;
- for (int y = 0; y < omb->h; ++y) {
- unsigned char *src = reinterpret_cast<unsigned char *>(smMem->data()) + 4 * (width() * (y + omb->y) + omb->x);
- unsigned char *dst = img.scanLine(y + omb->y) + omb->x * 4;
- memcpy(dst, src, omb->w * 4);
- }
- update();
+ for (int y = 0; y < omb->h; ++y) {
+ unsigned char *src =
+ reinterpret_cast< unsigned char * >(smMem->data()) + 4 * (width() * (y + omb->y) + omb->x);
+ unsigned char *dst = img.scanLine(y + omb->y) + omb->x * 4;
+ memcpy(dst, src, omb->w * 4);
}
- break;
+
+ update();
+ } break;
case OVERLAY_MSGTYPE_ACTIVE: {
- OverlayMsgActive *oma = & om.oma;
+ OverlayMsgActive *oma = &om.oma;
- qWarning() << "ACTIVE" << oma->x << oma->y << oma->w << oma->h;
+ qWarning() << "ACTIVE" << oma->x << oma->y << oma->w << oma->h;
- qrActive = QRect(oma->x, oma->y, oma->w, oma->h);
- update();
- };
- break;
+ qrActive = QRect(oma->x, oma->y, oma->w, oma->h);
+ update();
+ }; break;
default:
break;
}
@@ -280,12 +280,13 @@ void OverlayWidget::readyRead() {
}
class TestWin : public QObject {
- Q_OBJECT
+ Q_OBJECT
+
+protected:
+ QWidget *qw;
- protected:
- QWidget *qw;
- public:
- TestWin();
+public:
+ TestWin();
};
TestWin::TestWin() {
diff --git a/src/tests/ProtoBuf.cpp b/src/tests/ProtoBuf.cpp
index e5f7c5e2c..faa47081c 100644
--- a/src/tests/ProtoBuf.cpp
+++ b/src/tests/ProtoBuf.cpp
@@ -2,12 +2,12 @@
* Protobuf binding benchmarks (serialisation, deserialization, ...).
*/
-#include <QtCore>
-#include <vector>
-#include "Timer.h"
#include "Message.h"
#include "PacketDataStream.h"
#include "ProtoBuf.pb.h"
+#include "Timer.h"
+#include <QtCore>
+#include <vector>
using namespace std;
@@ -25,11 +25,11 @@ int main(int argc, char **argv) {
int v;
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
MessageServerAuthenticate ma;
- Message *m = &ma;
- ma.uiSession = 1;
- ma.iVersion = -1;
+ Message *m = &ma;
+ ma.uiSession = 1;
+ ma.iVersion = -1;
ma.qsUsername = n;
ma.qsPassword = p;
@@ -44,7 +44,7 @@ int main(int argc, char **argv) {
printf("MsgBased : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Authenticate apb;
apb.set_version(-1);
apb.set_session(1);
@@ -54,7 +54,7 @@ int main(int argc, char **argv) {
std::string str;
Universal u;
- * (u.mutable_authenticate()) = apb;
+ *(u.mutable_authenticate()) = apb;
u.SerializeToString(&str);
u.ParseFromString(str);
@@ -70,7 +70,7 @@ int main(int argc, char **argv) {
printf("ProtoBuf : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Universal u;
Authenticate *apb = u.mutable_authenticate();
apb->set_version(-1);
@@ -96,7 +96,7 @@ int main(int argc, char **argv) {
std::string sp = p.toStdString();
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Universal u;
Authenticate *apb = u.mutable_authenticate();
apb->set_version(-1);
@@ -119,7 +119,7 @@ int main(int argc, char **argv) {
printf("PBStdStr : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Universal u;
Authenticate *apb = u.mutable_authenticate();
apb->set_version(-1);
@@ -142,7 +142,7 @@ int main(int argc, char **argv) {
printf("PBArray : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Universal u;
Authenticate *apb = u.MutableExtension(extauth);
apb->set_version(-1);
@@ -165,7 +165,7 @@ int main(int argc, char **argv) {
printf("PBExt : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
Authenticate apb;
apb.set_version(-1);
apb.set_session(1);
@@ -185,7 +185,7 @@ int main(int argc, char **argv) {
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
LongUniversal u;
Authenticate *apb = u.mutable_z();
apb->set_version(-1);
@@ -210,7 +210,7 @@ int main(int argc, char **argv) {
LongUniversal u;
const LongUniversal::Reflection *r = u.GetReflection();
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
u.Clear();
Authenticate *apb = u.mutable_z();
@@ -219,20 +219,22 @@ int main(int argc, char **argv) {
apb->set_name(n.toStdString());
apb->set_pw(p.toStdString());
-// std::string str;
+ // std::string str;
v = u.ByteSize();
u.SerializeToArray(buff, v);
u.Clear();
u.ParseFromArray(buff, v);
-// u.DiscardUnknownFields();
+ // u.DiscardUnknownFields();
-// vector<const google::protobuf::FieldDescriptor *> v;
-// r->ListFields(u, &v);
-// printf("%d\n", v.size());
+ // vector<const google::protobuf::FieldDescriptor *> v;
+ // r->ListFields(u, &v);
+ // printf("%d\n", v.size());
- if (u.has_a() || u.has_b() || u.has_c() || u.has_d() || u.has_e() || u.has_f() || u.has_g() || u.has_h() || u.has_i() || u.has_j() || u.has_k() || u.has_l() || u.has_m() || u.has_n() || u.has_o() || u.has_p() || u.has_q())
+ if (u.has_a() || u.has_b() || u.has_c() || u.has_d() || u.has_e() || u.has_f() || u.has_g() || u.has_h()
+ || u.has_i() || u.has_j() || u.has_k() || u.has_l() || u.has_m() || u.has_n() || u.has_o() || u.has_p()
+ || u.has_q())
continue;
@@ -246,7 +248,7 @@ int main(int argc, char **argv) {
printf("PBCache : %8lld %d\n", t.elapsed(), v);
t.restart();
- for (int i=0;i<1000000;++i) {
+ for (int i = 0; i < 1000000; ++i) {
QString nn = QString::fromStdString(n.toStdString());
QString np = QString::fromStdString(p.toStdString());
}
diff --git a/src/tests/Resample.cpp b/src/tests/Resample.cpp
index 56a9d7f82..909b62554 100644
--- a/src/tests/Resample.cpp
+++ b/src/tests/Resample.cpp
@@ -3,7 +3,7 @@
*/
#ifdef Q_OS_WIN
-# include "win.h"
+# include "win.h"
#endif
#include "Timer.h"
@@ -24,7 +24,7 @@ int main(int argc, char **argv) {
ippSetNumThreads(1);
#ifdef Q_OS_WIN
- if (!SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS))
+ if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
qWarning("Application: Failed to set priority!");
#endif
@@ -32,10 +32,10 @@ int main(int argc, char **argv) {
SpeexResamplerState *srs;
- int iMicFreq = 44100;
+ int iMicFreq = 44100;
int iSampleRate = 48000;
- int iFrameSize = iSampleRate / 100;
- int err = 0;
+ int iFrameSize = iSampleRate / 100;
+ int err = 0;
srs = speex_resampler_init(1, iMicFreq, iSampleRate, 3, &err);
@@ -43,14 +43,14 @@ int main(int argc, char **argv) {
qWarning() << iMicFreq << iSampleRate << iFrameSize << iMicLength;
- float *pfInput = new float[iMicLength];
+ float *pfInput = new float[iMicLength];
float *pfOutput = new float[iFrameSize];
- for (int i=0;i<iMicLength;++i) {
+ for (int i = 0; i < iMicLength; ++i) {
pfInput[i] = sinf((M_PI * i * 20) / iMicLength);
}
- for (int i=0;i<iFrameSize;++i)
+ for (int i = 0; i < iFrameSize; ++i)
pfOutput[i] = 0;
qWarning() << "speex resampler latency: " << speex_resampler_get_input_latency(srs);
@@ -58,8 +58,8 @@ int main(int argc, char **argv) {
Timer t;
- for (int i=0;i<ITER;++i) {
- spx_uint32_t inlen = iMicLength;
+ for (int i = 0; i < ITER; ++i) {
+ spx_uint32_t inlen = iMicLength;
spx_uint32_t outlen = iFrameSize;
speex_resampler_process_float(srs, 0, pfInput, &inlen, pfOutput, &outlen);
}
@@ -71,35 +71,35 @@ int main(int argc, char **argv) {
float min = 0.0;
float max = 0.0;
- for (int i=0;i<iFrameSize;++i) {
+ for (int i = 0; i < iFrameSize; ++i) {
min = qMin(min, pfOutput[i]);
max = qMax(max, pfOutput[i]);
}
qWarning() << "Speex bounds" << min << max;
- delete [] pfOutput;
+ delete[] pfOutput;
- int history=24;
+ int history = 24;
int lastread = history;
- double time = history;
- int olen = 0;
+ double time = history;
+ int olen = 0;
- float *inBuf = ippsMalloc_32f(iMicLength+history*2+2);
- ippsZero_32f(inBuf, iMicLength+history*2+2);
+ float *inBuf = ippsMalloc_32f(iMicLength + history * 2 + 2);
+ ippsZero_32f(inBuf, iMicLength + history * 2 + 2);
- pfOutput = ippsMalloc_32f(iFrameSize+2);
+ pfOutput = ippsMalloc_32f(iFrameSize + 2);
- for (int i=0;i<iFrameSize;++i)
+ for (int i = 0; i < iFrameSize; ++i)
pfOutput[i] = 0;
IppsResamplingPolyphaseFixed_32f *pSpec = nullptr;
- ippsResamplePolyphaseFixedInitAlloc_32f(&pSpec, iMicFreq, iSampleRate, 2*history, 0.90f, 8.0f, ippAlgHintFast);
+ ippsResamplePolyphaseFixedInitAlloc_32f(&pSpec, iMicFreq, iSampleRate, 2 * history, 0.90f, 8.0f, ippAlgHintFast);
t.restart();
- for (int i=0;i<ITER;++i) {
+ for (int i = 0; i < ITER; ++i) {
ippsCopy_32f(pfInput, inBuf + history, iMicLength);
ippsResamplePolyphaseFixed_32f(pSpec, inBuf, iMicLength, pfOutput, .99f, &time, &olen);
@@ -115,14 +115,14 @@ int main(int argc, char **argv) {
min = 0.0;
max = 0.0;
- for (int i=0;i<iFrameSize;++i) {
+ for (int i = 0; i < iFrameSize; ++i) {
min = qMin(min, pfOutput[i]);
max = qMax(max, pfOutput[i]);
}
qWarning() << "IPP bounds" << min << max;
- delete [] pfInput;
+ delete[] pfInput;
return 0;
}
diff --git a/src/tests/TestCrypt/TestCrypt.cpp b/src/tests/TestCrypt/TestCrypt.cpp
index 2eb9e3e8c..abc1ec370 100644
--- a/src/tests/TestCrypt/TestCrypt.cpp
+++ b/src/tests/TestCrypt/TestCrypt.cpp
@@ -6,23 +6,23 @@
#include <QtCore>
#include <QtTest>
-#include <string>
#include "SSL.h"
#include "Timer.h"
-#include "crypto/CryptStateOCB2.h"
#include "Utils.h"
+#include "crypto/CryptStateOCB2.h"
+#include <string>
class TestCrypt : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void testvectors();
- void authcrypt();
- void xexstarAttack();
- void ivrecovery();
- void reverserecovery();
- void tamper();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void testvectors();
+ void authcrypt();
+ void xexstarAttack();
+ void ivrecovery();
+ void reverserecovery();
+ void tamper();
};
void TestCrypt::initTestCase() {
@@ -40,7 +40,7 @@ void TestCrypt::reverserecovery() {
// For our testcase, we're going to FORCE iv
char encrypt_iv[AES_BLOCK_SIZE];
memset(encrypt_iv, 0x55, AES_BLOCK_SIZE);
- enc.setEncryptIV(std::string(reinterpret_cast<const char*>(encrypt_iv), AES_BLOCK_SIZE));
+ enc.setEncryptIV(std::string(reinterpret_cast< const char * >(encrypt_iv), AES_BLOCK_SIZE));
dec.setKey(enc.getRawKey(), enc.getDecryptIV(), enc.getEncryptIV());
unsigned char secret[10] = "abcdefghi";
@@ -69,24 +69,24 @@ void TestCrypt::reverserecovery() {
int i;
- for (i=0;i<128;i++)
+ for (i = 0; i < 128; i++)
enc.encrypt(secret, crypted[i], 10);
- for (i=0;i<30;i++)
- QVERIFY(dec.decrypt(crypted[127-i], decr, 14));
- for (;i<128;i++)
- QVERIFY(!dec.decrypt(crypted[127-i], decr, 14));
- for (i=0;i<30;i++)
- QVERIFY(!dec.decrypt(crypted[127-i], decr, 14));
+ for (i = 0; i < 30; i++)
+ QVERIFY(dec.decrypt(crypted[127 - i], decr, 14));
+ for (; i < 128; i++)
+ QVERIFY(!dec.decrypt(crypted[127 - i], decr, 14));
+ for (i = 0; i < 30; i++)
+ QVERIFY(!dec.decrypt(crypted[127 - i], decr, 14));
// Extensive replay attack test
- for (i=0;i<512;i++)
+ for (i = 0; i < 512; i++)
enc.encrypt(secret, crypted[i], 10);
- for (i=0;i<512;i++)
+ for (i = 0; i < 512; i++)
QVERIFY(dec.decrypt(crypted[i], decr, 14));
- for (i=0;i<512;i++)
+ for (i = 0; i < 512; i++)
QVERIFY(!dec.decrypt(crypted[i], decr, 14));
}
@@ -97,7 +97,7 @@ void TestCrypt::ivrecovery() {
// For our testcase, we're going to FORCE iv
char encrypt_iv[AES_BLOCK_SIZE];
memset(encrypt_iv, 0x55, AES_BLOCK_SIZE);
- enc.setEncryptIV(std::string(reinterpret_cast<const char*>(encrypt_iv), AES_BLOCK_SIZE));
+ enc.setEncryptIV(std::string(reinterpret_cast< const char * >(encrypt_iv), AES_BLOCK_SIZE));
dec.setKey(enc.getRawKey(), enc.getDecryptIV(), enc.getEncryptIV());
unsigned char secret[10] = "abcdefghi";
@@ -109,21 +109,21 @@ void TestCrypt::ivrecovery() {
// Can decrypt.
QVERIFY(dec.decrypt(crypted, decr, 14));
// .. correctly.
- QVERIFY(memcmp(secret, decr, 10)==0);
+ QVERIFY(memcmp(secret, decr, 10) == 0);
// But will refuse to reuse same IV.
- QVERIFY(! dec.decrypt(crypted, decr, 14));
+ QVERIFY(!dec.decrypt(crypted, decr, 14));
// Recover from lost packet.
- for (int i=0;i<16;i++)
+ for (int i = 0; i < 16; i++)
enc.encrypt(secret, crypted, 10);
QVERIFY(dec.decrypt(crypted, decr, 14));
// Wraparound.
- for (int i=0;i<128;i++) {
+ for (int i = 0; i < 128; i++) {
dec.uiLost = 0;
- for (int j=0;j<15;j++)
+ for (int j = 0; j < 15; j++)
enc.encrypt(secret, crypted, 10);
QVERIFY(dec.decrypt(crypted, decr, 14));
QCOMPARE(dec.uiLost, 14U);
@@ -132,10 +132,10 @@ void TestCrypt::ivrecovery() {
QVERIFY(enc.getEncryptIV() == dec.getDecryptIV());
// Wrap too far
- for (int i=0;i<257;i++)
+ for (int i = 0; i < 257; i++)
enc.encrypt(secret, crypted, 10);
- QVERIFY(! dec.decrypt(crypted, decr, 14));
+ QVERIFY(!dec.decrypt(crypted, decr, 14));
// Sync it
dec.setDecryptIV(enc.getEncryptIV());
@@ -146,47 +146,53 @@ void TestCrypt::ivrecovery() {
void TestCrypt::testvectors() {
// Test vectors are from draft-krovetz-ocb-00.txt
- const unsigned char rawkey[AES_BLOCK_SIZE] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
+ const unsigned char rawkey[AES_BLOCK_SIZE] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
CryptStateOCB2 cs;
- std::string rawkey_str = std::string(reinterpret_cast<const char*>(rawkey), AES_BLOCK_SIZE);
+ std::string rawkey_str = std::string(reinterpret_cast< const char * >(rawkey), AES_BLOCK_SIZE);
cs.setKey(rawkey_str, rawkey_str, rawkey_str);
unsigned char tag[16];
QVERIFY(cs.ocb_encrypt(nullptr, nullptr, 0, rawkey, tag));
- const unsigned char blanktag[AES_BLOCK_SIZE] = {0xBF,0x31,0x08,0x13,0x07,0x73,0xAD,0x5E,0xC7,0x0E,0xC6,0x9E,0x78,0x75,0xA7,0xB0};
- for (int i=0;i<AES_BLOCK_SIZE;i++)
+ const unsigned char blanktag[AES_BLOCK_SIZE] = { 0xBF, 0x31, 0x08, 0x13, 0x07, 0x73, 0xAD, 0x5E,
+ 0xC7, 0x0E, 0xC6, 0x9E, 0x78, 0x75, 0xA7, 0xB0 };
+ for (int i = 0; i < AES_BLOCK_SIZE; i++)
QCOMPARE(tag[i], blanktag[i]);
unsigned char source[40];
unsigned char crypt[40];
- for (int i=0;i<40;i++)
- source[i]=i;
+ for (int i = 0; i < 40; i++)
+ source[i] = i;
QVERIFY(cs.ocb_encrypt(source, crypt, 40, rawkey, tag));
- const unsigned char longtag[AES_BLOCK_SIZE] = {0x9D,0xB0,0xCD,0xF8,0x80,0xF7,0x3E,0x3E,0x10,0xD4,0xEB,0x32,0x17,0x76,0x66,0x88};
- const unsigned char crypted[40] = {0xF7,0x5D,0x6B,0xC8,0xB4,0xDC,0x8D,0x66,0xB8,0x36,0xA2,0xB0,0x8B,0x32,0xA6,0x36,0x9F,0x1C,0xD3,0xC5,0x22,0x8D,0x79,0xFD,
- 0x6C,0x26,0x7F,0x5F,0x6A,0xA7,0xB2,0x31,0xC7,0xDF,0xB9,0xD5,0x99,0x51,0xAE,0x9C
- };
-
- for (int i=0;i<AES_BLOCK_SIZE;i++)
+ const unsigned char longtag[AES_BLOCK_SIZE] = { 0x9D, 0xB0, 0xCD, 0xF8, 0x80, 0xF7, 0x3E, 0x3E,
+ 0x10, 0xD4, 0xEB, 0x32, 0x17, 0x76, 0x66, 0x88 };
+ const unsigned char crypted[40] = { 0xF7, 0x5D, 0x6B, 0xC8, 0xB4, 0xDC, 0x8D, 0x66, 0xB8, 0x36,
+ 0xA2, 0xB0, 0x8B, 0x32, 0xA6, 0x36, 0x9F, 0x1C, 0xD3, 0xC5,
+ 0x22, 0x8D, 0x79, 0xFD, 0x6C, 0x26, 0x7F, 0x5F, 0x6A, 0xA7,
+ 0xB2, 0x31, 0xC7, 0xDF, 0xB9, 0xD5, 0x99, 0x51, 0xAE, 0x9C };
+
+ for (int i = 0; i < AES_BLOCK_SIZE; i++)
QCOMPARE(tag[i], longtag[i]);
- for (int i=0;i<40;i++)
+ for (int i = 0; i < 40; i++)
QCOMPARE(crypt[i], crypted[i]);
}
void TestCrypt::authcrypt() {
- for (int len=0;len<128;len++) {
- const unsigned char rawkey[AES_BLOCK_SIZE] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
- const unsigned char nonce[AES_BLOCK_SIZE] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
- std::string rawkey_str = std::string(reinterpret_cast<const char*>(rawkey), AES_BLOCK_SIZE);
- std::string nonce_str = std::string(reinterpret_cast<const char*>(nonce), AES_BLOCK_SIZE);
+ for (int len = 0; len < 128; len++) {
+ const unsigned char rawkey[AES_BLOCK_SIZE] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
+ const unsigned char nonce[AES_BLOCK_SIZE] = { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
+ 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
+ std::string rawkey_str = std::string(reinterpret_cast< const char * >(rawkey), AES_BLOCK_SIZE);
+ std::string nonce_str = std::string(reinterpret_cast< const char * >(nonce), AES_BLOCK_SIZE);
CryptStateOCB2 cs;
cs.setKey(rawkey_str, nonce_str, nonce_str);
STACKVAR(unsigned char, src, len);
- for (int i=0;i<len;i++)
+ for (int i = 0; i < len; i++)
src[i] = (i + 1);
unsigned char enctag[AES_BLOCK_SIZE];
@@ -197,20 +203,22 @@ void TestCrypt::authcrypt() {
QVERIFY(cs.ocb_encrypt(src, encrypted, len, nonce, enctag));
QVERIFY(cs.ocb_decrypt(encrypted, decrypted, len, nonce, dectag));
- for (int i=0;i<AES_BLOCK_SIZE;i++)
+ for (int i = 0; i < AES_BLOCK_SIZE; i++)
QCOMPARE(enctag[i], dectag[i]);
- for (int i=0;i<len;i++)
+ for (int i = 0; i < len; i++)
QCOMPARE(src[i], decrypted[i]);
}
}
// Test prevention of the attack described in section 4.1 of https://eprint.iacr.org/2019/311
void TestCrypt::xexstarAttack() {
- const unsigned char rawkey[AES_BLOCK_SIZE] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
- const unsigned char nonce[AES_BLOCK_SIZE] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
- std::string rawkey_str = std::string(reinterpret_cast<const char*>(rawkey), AES_BLOCK_SIZE);
- std::string nonce_str = std::string(reinterpret_cast<const char*>(nonce), AES_BLOCK_SIZE);
+ const unsigned char rawkey[AES_BLOCK_SIZE] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
+ const unsigned char nonce[AES_BLOCK_SIZE] = { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
+ 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
+ std::string rawkey_str = std::string(reinterpret_cast< const char * >(rawkey), AES_BLOCK_SIZE);
+ std::string nonce_str = std::string(reinterpret_cast< const char * >(nonce), AES_BLOCK_SIZE);
CryptStateOCB2 cs;
cs.setKey(rawkey_str, nonce_str, nonce_str);
@@ -246,26 +254,28 @@ void TestCrypt::xexstarAttack() {
}
void TestCrypt::tamper() {
- const unsigned char rawkey[AES_BLOCK_SIZE] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
- const unsigned char nonce[AES_BLOCK_SIZE] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
- std::string rawkey_str = std::string(reinterpret_cast<const char*>(rawkey), AES_BLOCK_SIZE);
- std::string nonce_str = std::string(reinterpret_cast<const char*>(nonce), AES_BLOCK_SIZE);
+ const unsigned char rawkey[AES_BLOCK_SIZE] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
+ const unsigned char nonce[AES_BLOCK_SIZE] = { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
+ 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
+ std::string rawkey_str = std::string(reinterpret_cast< const char * >(rawkey), AES_BLOCK_SIZE);
+ std::string nonce_str = std::string(reinterpret_cast< const char * >(nonce), AES_BLOCK_SIZE);
CryptStateOCB2 cs;
cs.setKey(rawkey_str, nonce_str, nonce_str);
const unsigned char msg[] = "It was a funky funky town!";
- int len = sizeof(msg);
+ int len = sizeof(msg);
- STACKVAR(unsigned char, encrypted, len+4);
+ STACKVAR(unsigned char, encrypted, len + 4);
STACKVAR(unsigned char, decrypted, len);
cs.encrypt(msg, encrypted, len);
- for (int i=0;i<len*8;i++) {
- encrypted[i/8] ^= 1 << (i % 8);
- QVERIFY(! cs.decrypt(encrypted, decrypted, len+4));
- encrypted[i/8] ^= 1 << (i % 8);
+ for (int i = 0; i < len * 8; i++) {
+ encrypted[i / 8] ^= 1 << (i % 8);
+ QVERIFY(!cs.decrypt(encrypted, decrypted, len + 4));
+ encrypted[i / 8] ^= 1 << (i % 8);
}
- QVERIFY(cs.decrypt(encrypted, decrypted, len+4));
+ QVERIFY(cs.decrypt(encrypted, decrypted, len + 4));
}
QTEST_MAIN(TestCrypt)
diff --git a/src/tests/TestCryptographicHash/TestCryptographicHash.cpp b/src/tests/TestCryptographicHash/TestCryptographicHash.cpp
index 90be99485..c1bfce51a 100644
--- a/src/tests/TestCryptographicHash/TestCryptographicHash.cpp
+++ b/src/tests/TestCryptographicHash/TestCryptographicHash.cpp
@@ -3,29 +3,29 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+#include <QLatin1String>
#include <QtCore>
#include <QtTest>
-#include <QLatin1String>
#include "SSL.h"
#include "crypto/CryptographicHash.h"
class TestCryptographicHash : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
- void sha1_data();
- void sha1();
+ void sha1_data();
+ void sha1();
- void sha256_data();
- void sha256();
+ void sha256_data();
+ void sha256();
- void staticHashVsObject();
- void multipleResultCalls();
- void addDataAfterResult();
+ void staticHashVsObject();
+ void multipleResultCalls();
+ void addDataAfterResult();
};
void TestCryptographicHash::initTestCase() {
@@ -55,15 +55,20 @@ static QByteArray normalizeHash(QByteArray buf) {
}
void TestCryptographicHash::sha1_data() {
- QTest::addColumn<QString>("input");
- QTest::addColumn<QString>("expectedOutput");
+ QTest::addColumn< QString >("input");
+ QTest::addColumn< QString >("expectedOutput");
// First 4 SHA1 test vectors from http://www.di-mgt.com.au/sha_testvectors.html
// ...The rest are a bit too excessive to put in a table-based test.
- QTest::newRow("1") << QString(QLatin1String("abc")) << normalizeHash(QLatin1String("a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d"));
- QTest::newRow("2") << QString(QLatin1String("")) << normalizeHash(QLatin1String("da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709"));
- QTest::newRow("3") << QString(QLatin1String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")) << normalizeHash(QLatin1String("84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1"));
- QTest::newRow("4") << QString(QLatin1String("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")) << normalizeHash(QLatin1String("a49b2446 a02c645b f419f995 b6709125 3a04a259"));
+ QTest::newRow("1") << QString(QLatin1String("abc"))
+ << normalizeHash(QLatin1String("a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d"));
+ QTest::newRow("2") << QString(QLatin1String(""))
+ << normalizeHash(QLatin1String("da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709"));
+ QTest::newRow("3") << QString(QLatin1String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))
+ << normalizeHash(QLatin1String("84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1"));
+ QTest::newRow("4") << QString(QLatin1String("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmn"
+ "opjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"))
+ << normalizeHash(QLatin1String("a49b2446 a02c645b f419f995 b6709125 3a04a259"));
}
void TestCryptographicHash::sha1() {
@@ -72,21 +77,29 @@ void TestCryptographicHash::sha1() {
QByteArray outBuf = CryptographicHash::hash(input.toLatin1(), CryptographicHash::Sha1);
QByteArray hexBuf = outBuf.toHex();
- QString output = QString::fromLatin1(hexBuf);
+ QString output = QString::fromLatin1(hexBuf);
QCOMPARE(output, expectedOutput);
}
void TestCryptographicHash::sha256_data() {
- QTest::addColumn<QString>("input");
- QTest::addColumn<QString>("expectedOutput");
+ QTest::addColumn< QString >("input");
+ QTest::addColumn< QString >("expectedOutput");
// First 4 SHA256 test vectors from http://www.di-mgt.com.au/sha_testvectors.html
// ...The rest are a bit too excessive to put in a table-based test.
- QTest::newRow("1") << QString(QLatin1String("abc")) << normalizeHash(QLatin1String("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad"));
- QTest::newRow("2") << QString(QLatin1String("")) << normalizeHash(QLatin1String("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855"));
- QTest::newRow("3") << QString(QLatin1String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")) << normalizeHash(QLatin1String("248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1"));
- QTest::newRow("4") << QString(QLatin1String("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")) << normalizeHash(QLatin1String("cf5b16a7 78af8380 036ce59e 7b049237 0b249b11 e8f07a51 afac4503 7afee9d1"));
+ QTest::newRow("1") << QString(QLatin1String("abc"))
+ << normalizeHash(
+ QLatin1String("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad"));
+ QTest::newRow("2") << QString(QLatin1String(
+ "")) << normalizeHash(QLatin1String("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855"));
+ QTest::newRow("3") << QString(QLatin1String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))
+ << normalizeHash(
+ QLatin1String("248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1"));
+ QTest::newRow("4") << QString(QLatin1String("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmn"
+ "opjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"))
+ << normalizeHash(
+ QLatin1String("cf5b16a7 78af8380 036ce59e 7b049237 0b249b11 e8f07a51 afac4503 7afee9d1"));
}
void TestCryptographicHash::sha256() {
@@ -98,7 +111,7 @@ void TestCryptographicHash::sha256() {
QVERIFY(!outBuf.isEmpty());
QByteArray hexBuf = outBuf.toHex();
- QString output = QString::fromLatin1(hexBuf);
+ QString output = QString::fromLatin1(hexBuf);
QCOMPARE(output, expectedOutput);
}
@@ -128,7 +141,8 @@ void TestCryptographicHash::multipleResultCalls() {
QVERIFY(!result2.isEmpty());
QVERIFY(!result3.isEmpty());
- QCOMPARE(result1.toHex(), normalizeHash(QByteArray("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad")));
+ QCOMPARE(result1.toHex(),
+ normalizeHash(QByteArray("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad")));
QCOMPARE(result1, result2);
QCOMPARE(result1, result3);
}
@@ -139,7 +153,8 @@ void TestCryptographicHash::addDataAfterResult() {
QByteArray result1 = h.result();
- QCOMPARE(result1.toHex(), normalizeHash(QByteArray("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad")));
+ QCOMPARE(result1.toHex(),
+ normalizeHash(QByteArray("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad")));
// Adding data after getting the result of a
// CryptographicHash is an error.
diff --git a/src/tests/TestCryptographicRandom/TestCryptographicRandom.cpp b/src/tests/TestCryptographicRandom/TestCryptographicRandom.cpp
index ee1a2edd7..1c6dcd1d7 100644
--- a/src/tests/TestCryptographicRandom/TestCryptographicRandom.cpp
+++ b/src/tests/TestCryptographicRandom/TestCryptographicRandom.cpp
@@ -10,18 +10,18 @@
#include "crypto/CryptographicRandom.h"
+#include <limits>
#include <stdint.h>
#include <stdlib.h>
-#include <limits>
class TestCryptographicRandom : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void fillBuffer();
- void uint32();
- void uniform();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void fillBuffer();
+ void uint32();
+ void uniform();
};
void TestCryptographicRandom::initTestCase() {
@@ -48,7 +48,7 @@ void TestCryptographicRandom::fillBuffer() {
const int buflen = 1000000;
for (int i = 0; i < 10; i++) {
- unsigned char *buf = reinterpret_cast<unsigned char *>(calloc(buflen, 1));
+ unsigned char *buf = reinterpret_cast< unsigned char * >(calloc(buflen, 1));
CryptographicRandom::fillBuffer(buf, buflen);
QVERIFY(verifyEntropy(buf, buflen));
free(buf);
@@ -59,15 +59,15 @@ void TestCryptographicRandom::uint32() {
const int buflen = 1000000;
for (int i = 0; i < 10; i++) {
- unsigned char *buf = reinterpret_cast<unsigned char *>(calloc(buflen, 1));
- int niter = buflen / sizeof(uint32_t);
+ unsigned char *buf = reinterpret_cast< unsigned char * >(calloc(buflen, 1));
+ int niter = buflen / sizeof(uint32_t);
for (int j = 0; j < niter; j++) {
- int off = j * sizeof(uint32_t);
+ int off = j * sizeof(uint32_t);
uint32_t val = CryptographicRandom::uint32();
- buf[off] = val & 0xff;
- buf[off+1] = (val >> 8) & 0xff;
- buf[off+2] = (val >> 16) & 0xff;
- buf[off+3] = (val >> 24) & 0xff;
+ buf[off] = val & 0xff;
+ buf[off + 1] = (val >> 8) & 0xff;
+ buf[off + 2] = (val >> 16) & 0xff;
+ buf[off + 3] = (val >> 24) & 0xff;
}
QVERIFY(verifyEntropy(buf, buflen));
free(buf);
diff --git a/src/tests/TestFFDHE/TestFFDHE.cpp b/src/tests/TestFFDHE/TestFFDHE.cpp
index 4d1a4548a..926963ceb 100644
--- a/src/tests/TestFFDHE/TestFFDHE.cpp
+++ b/src/tests/TestFFDHE/TestFFDHE.cpp
@@ -7,22 +7,22 @@
#include <QtTest>
#if defined(USE_QSSLDIFFIEHELLMANPARAMETERS)
-# include <QtNetwork/QSslDiffieHellmanParameters>
+# include <QtNetwork/QSslDiffieHellmanParameters>
#endif
-#include "SSL.h"
#include "FFDHE.h"
+#include "SSL.h"
class TestFFDHE : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
#if defined(USE_QSSLDIFFIEHELLMANPARAMETERS)
- void exercise_data();
- void exercise();
- void namedGroupsMethod();
+ void exercise_data();
+ void exercise();
+ void namedGroupsMethod();
#endif
};
@@ -36,8 +36,8 @@ void TestFFDHE::cleanupTestCase() {
#if defined(USE_QSSLDIFFIEHELLMANPARAMETERS)
void TestFFDHE::exercise_data() {
- QTest::addColumn<QString>("name");
- QTest::addColumn<bool>("expectedToWork");
+ QTest::addColumn< QString >("name");
+ QTest::addColumn< bool >("expectedToWork");
QTest::newRow("ffdhe2048") << QString(QLatin1String("ffdhe2048")) << true;
QTest::newRow("ffdhe3072") << QString(QLatin1String("ffdhe3072")) << true;
@@ -61,7 +61,7 @@ static bool tryFFDHELookupByName(QString name) {
}
if (ok) {
QSslDiffieHellmanParameters dh = QSslDiffieHellmanParameters::fromEncoded(pem, QSsl::Pem);
- ok = dh.isValid();
+ ok = dh.isValid();
if (!ok) {
qWarning("QSslDiffieHellman error: %s", qPrintable(dh.errorString()));
}
@@ -77,9 +77,7 @@ void TestFFDHE::exercise() {
}
void TestFFDHE::namedGroupsMethod() {
- foreach (QString name, FFDHE::NamedGroups()) {
- QCOMPARE(tryFFDHELookupByName(name), true);
- }
+ foreach (QString name, FFDHE::NamedGroups()) { QCOMPARE(tryFFDHELookupByName(name), true); }
}
#endif
diff --git a/src/tests/TestLink.cpp b/src/tests/TestLink.cpp
index 09996bdf8..327f00cb6 100644
--- a/src/tests/TestLink.cpp
+++ b/src/tests/TestLink.cpp
@@ -9,30 +9,30 @@
#include <QtCore>
#ifdef Q_OS_WIN
-# include "win.h"
+# include "win.h"
#else
-# include <fcntl.h>
-# include <sys/mman.h>
+# include <fcntl.h>
+# include <sys/mman.h>
#endif
struct LinkedMem {
#ifdef WIN32
- UINT32 uiVersion;
- DWORD uiTick;
+ UINT32 uiVersion;
+ DWORD uiTick;
#else
uint32_t uiVersion;
uint32_t uiTick;
#endif
- float fAvatarPosition[3];
- float fAvatarFront[3];
- float fAvatarTop[3];
- wchar_t name[256];
- float fCameraPosition[3];
- float fCameraFront[3];
- float fCameraTop[3];
- wchar_t identity[256];
+ float fAvatarPosition[3];
+ float fAvatarFront[3];
+ float fAvatarTop[3];
+ wchar_t name[256];
+ float fCameraPosition[3];
+ float fCameraFront[3];
+ float fCameraTop[3];
+ wchar_t identity[256];
#ifdef WIN32
- UINT32 context_len;
+ UINT32 context_len;
#else
uint32_t context_len;
#endif
@@ -44,7 +44,6 @@ LinkedMem *lm = nullptr;
void initMumble() {
-
#ifdef WIN32
HANDLE hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
if (!hMapObject)
@@ -66,9 +65,9 @@ void initMumble() {
return;
}
- lm = (LinkedMem *)(mmap(nullptr, sizeof(struct LinkedMem), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd,0));
+ lm = (LinkedMem *) (mmap(nullptr, sizeof(struct LinkedMem), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0));
- if (lm == (void *)(-1)) {
+ if (lm == (void *) (-1)) {
lm = nullptr;
return;
}
@@ -76,7 +75,7 @@ void initMumble() {
}
void updateMumble() {
- if (! lm)
+ if (!lm)
return;
if (lm->uiVersion != 2) {
@@ -144,7 +143,7 @@ int main(int argc, char **argv) {
#ifdef WIN32
Sleep(100);
#else
- usleep(100*1000);
+ usleep(100 * 1000);
#endif
}
}
diff --git a/src/tests/TestPacketDataStream/TestPacketDataStream.cpp b/src/tests/TestPacketDataStream/TestPacketDataStream.cpp
index 95f121871..94ea14ab4 100644
--- a/src/tests/TestPacketDataStream/TestPacketDataStream.cpp
+++ b/src/tests/TestPacketDataStream/TestPacketDataStream.cpp
@@ -3,29 +3,29 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+#include "Message.h"
+#include "PacketDataStream.h"
+#include <QObject>
#include <QtCore>
#include <QtNetwork>
#include <QtTest>
-#include <QObject>
-#include "PacketDataStream.h"
-#include "Message.h"
class TestPacketDataStream : public QObject {
- Q_OBJECT
- private slots:
- void integer();
- void integer_data();
- void string();
- void string_data();
- void space();
- void floating();
- void floating_data();
- void undersize();
+ Q_OBJECT
+private slots:
+ void integer();
+ void integer_data();
+ void string();
+ void string_data();
+ void space();
+ void floating();
+ void floating_data();
+ void undersize();
};
void TestPacketDataStream::floating_data() {
- QTest::addColumn<double>("value");
- for (int i=1;i<256;i++) {
+ QTest::addColumn< double >("value");
+ for (int i = 1; i < 256; i++) {
double v = 1.0L / (1.0L * i);
QTest::newRow("Positive") << v;
QTest::newRow("Negative") << -v;
@@ -51,11 +51,11 @@ void TestPacketDataStream::undersize() {
QByteArray qba(32, 'Z');
char buff[256];
- for (unsigned int i=0;i<32;i++) {
+ for (unsigned int i = 0; i < 32; i++) {
PacketDataStream out(buff, i);
out << qba;
- QCOMPARE(33-i, out.undersize());
- QVERIFY(! out.isValid());
+ QCOMPARE(33 - i, out.undersize());
+ QVERIFY(!out.isValid());
QVERIFY(out.left() == 0);
}
PacketDataStream out(buff, 33);
@@ -66,8 +66,8 @@ void TestPacketDataStream::undersize() {
}
void TestPacketDataStream::integer_data() {
- QTest::addColumn<quint64>("value");
- for (int i=0;i<64;i++) {
+ QTest::addColumn< quint64 >("value");
+ for (int i = 0; i < 64; i++) {
quint64 v = 1ULL << i;
QTest::newRow("Integer") << v;
QTest::newRow("~Integer") << ~v;
@@ -90,7 +90,7 @@ void TestPacketDataStream::integer() {
}
void TestPacketDataStream::string_data() {
- QTest::addColumn<QString>("string");
+ QTest::addColumn< QString >("string");
QTest::newRow("Empty") << QString("");
QTest::newRow("Null") << QString();
QTest::newRow("Bærtur") << QString("Bærtur");
@@ -113,8 +113,8 @@ void TestPacketDataStream::string() {
void TestPacketDataStream::space() {
char buff[256];
- for (int i=0;i<256;i++)
- buff[i]= 0x55;
+ for (int i = 0; i < 256; i++)
+ buff[i] = 0x55;
PacketDataStream out(buff, 1);
@@ -128,7 +128,7 @@ void TestPacketDataStream::space() {
out << val;
- QVERIFY(! out.isValid());
+ QVERIFY(!out.isValid());
QVERIFY(out.size() == 1);
QVERIFY(out.left() == 0);
QVERIFY(buff[1] == 0x55);
@@ -144,7 +144,7 @@ void TestPacketDataStream::space() {
QVERIFY(in.left() == 0);
in >> v;
- QVERIFY(! in.isValid());
+ QVERIFY(!in.isValid());
QVERIFY(in.size() == 1);
QVERIFY(in.left() == 0);
}
diff --git a/src/tests/TestPasswordGenerator/TestPasswordGenerator.cpp b/src/tests/TestPasswordGenerator/TestPasswordGenerator.cpp
index bfb368f24..6d7e80291 100644
--- a/src/tests/TestPasswordGenerator/TestPasswordGenerator.cpp
+++ b/src/tests/TestPasswordGenerator/TestPasswordGenerator.cpp
@@ -11,14 +11,14 @@
#include "PasswordGenerator.h"
// Get the password alphabet from PasswordGenerator.
-extern QVector<QChar> mumble_password_generator_alphabet();
+extern QVector< QChar > mumble_password_generator_alphabet();
class TestPasswordGenerator : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void random();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void random();
};
void TestPasswordGenerator::initTestCase() {
@@ -30,7 +30,7 @@ void TestPasswordGenerator::cleanupTestCase() {
}
void TestPasswordGenerator::random() {
- QVector<QChar> alphabet = mumble_password_generator_alphabet();
+ QVector< QChar > alphabet = mumble_password_generator_alphabet();
for (int i = 0; i < 100; i++) {
QString out = PasswordGenerator::generatePassword(i);
QVERIFY(out.size() == i);
diff --git a/src/tests/TestSSLLocks/TestSSLLocks.cpp b/src/tests/TestSSLLocks/TestSSLLocks.cpp
index 68d8ec784..4aa430de0 100644
--- a/src/tests/TestSSLLocks/TestSSLLocks.cpp
+++ b/src/tests/TestSSLLocks/TestSSLLocks.cpp
@@ -22,10 +22,7 @@ public:
bool m_seed;
QAtomicInt *m_running;
- SSLRacer(QAtomicInt *running, bool seed)
- : m_seed(seed)
- , m_running(running) {
- }
+ SSLRacer(QAtomicInt *running, bool seed) : m_seed(seed), m_running(running) {}
void run() {
unsigned char buf[64];
@@ -34,7 +31,7 @@ public:
#else
// Qt 5.14 introduced QAtomicInteger::loadRelaxed() which deprecates QAtomicInteger::load()
while (m_running->load() == 1) {
-#endif
+#endif
for (int i = 0; i < 1024; i++) {
if (m_seed) {
RAND_seed(buf, sizeof(buf));
@@ -47,11 +44,11 @@ public:
};
class TestSSLLocks : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void stress();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void stress();
};
void TestSSLLocks::initTestCase() {
@@ -76,7 +73,7 @@ void TestSSLLocks::cleanupTestCase() {
/// The idea is that without proper locking, the data races we're causing
/// should quite quickly cause the process to crash.
void TestSSLLocks::stress() {
- std::vector<SSLRacer *> racers;
+ std::vector< SSLRacer * > racers;
QAtomicInt running(1);
// Spawn 24 threads in total. 12 readers, and 12 writers.
@@ -84,7 +81,7 @@ void TestSSLLocks::stress() {
// pass or crash, so the threads will be cleaned up either way.
int nthreads = 24;
for (int i = 0; i < nthreads; i++) {
- bool seeder = i % 2;
+ bool seeder = i % 2;
SSLRacer *racer = new SSLRacer(&running, seeder);
racers.push_back(racer);
racer->start();
diff --git a/src/tests/TestSelfSignedCertificate/TestSelfSignedCertificate.cpp b/src/tests/TestSelfSignedCertificate/TestSelfSignedCertificate.cpp
index 4c4f957a7..b65d15f23 100644
--- a/src/tests/TestSelfSignedCertificate/TestSelfSignedCertificate.cpp
+++ b/src/tests/TestSelfSignedCertificate/TestSelfSignedCertificate.cpp
@@ -11,12 +11,12 @@
#include "SelfSignedCertificate.h"
class TestSelfSignedCertificate : public QObject {
- Q_OBJECT
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void exerciseClientCert();
- void exerciseServerCert();
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void exerciseClientCert();
+ void exerciseServerCert();
};
void TestSelfSignedCertificate::initTestCase() {
@@ -30,8 +30,9 @@ void TestSelfSignedCertificate::cleanupTestCase() {
void TestSelfSignedCertificate::exerciseClientCert() {
QSslCertificate cert;
QSslKey key;
-
- bool ok = SelfSignedCertificate::generateMumbleCertificate(QLatin1String("Test"), QLatin1String("test@test.test"), cert, key);
+
+ bool ok = SelfSignedCertificate::generateMumbleCertificate(QLatin1String("Test"), QLatin1String("test@test.test"),
+ cert, key);
QCOMPARE(ok, true);
QCOMPARE(cert.isNull(), false);
QCOMPARE(key.isNull(), false);
@@ -51,7 +52,8 @@ void TestSelfSignedCertificate::exerciseClientCert() {
// Test that it's possible to create a client certificate with
// both a name and an email.
- ok = SelfSignedCertificate::generateMumbleCertificate(QLatin1String("John Doe"), QLatin1String("john@doe.family"), cert, key);
+ ok = SelfSignedCertificate::generateMumbleCertificate(QLatin1String("John Doe"), QLatin1String("john@doe.family"),
+ cert, key);
QCOMPARE(ok, true);
QCOMPARE(cert.isNull(), false);
QCOMPARE(key.isNull(), false);
@@ -60,7 +62,7 @@ void TestSelfSignedCertificate::exerciseClientCert() {
void TestSelfSignedCertificate::exerciseServerCert() {
QSslCertificate cert;
QSslKey key;
-
+
bool ok = SelfSignedCertificate::generateMurmurV2Certificate(cert, key);
QCOMPARE(ok, true);
QCOMPARE(cert.isNull(), false);
diff --git a/src/tests/TestServerAddress/TestServerAddress.cpp b/src/tests/TestServerAddress/TestServerAddress.cpp
index c4a4b3e66..3fb5656e9 100644
--- a/src/tests/TestServerAddress/TestServerAddress.cpp
+++ b/src/tests/TestServerAddress/TestServerAddress.cpp
@@ -12,14 +12,14 @@
#include "ServerAddress.h"
class TestServerAddress : public QObject {
- Q_OBJECT
- private slots:
- void defaultCtor();
- void isValid();
- void ctor();
- void equals();
- void lessThan();
- void qhash();
+ Q_OBJECT
+private slots:
+ void defaultCtor();
+ void isValid();
+ void ctor();
+ void equals();
+ void lessThan();
+ void qhash();
};
void TestServerAddress::defaultCtor() {
@@ -49,7 +49,7 @@ void TestServerAddress::isValid() {
void TestServerAddress::ctor() {
ServerAddress sa(HostAddress(QHostAddress("127.0.0.1")), 443);
QCOMPARE(sa.host, HostAddress(QHostAddress("127.0.0.1")));
- QCOMPARE(sa.port, static_cast<unsigned short>(443));
+ QCOMPARE(sa.port, static_cast< unsigned short >(443));
}
void TestServerAddress::equals() {
@@ -65,7 +65,7 @@ void TestServerAddress::equals() {
}
void TestServerAddress::lessThan() {
- QList<ServerAddress> testdata;
+ QList< ServerAddress > testdata;
testdata << ServerAddress();
testdata << ServerAddress(HostAddress(), 1);
@@ -80,7 +80,7 @@ void TestServerAddress::lessThan() {
testdata << ServerAddress(HostAddress(QHostAddress("255.255.255.255")), 0);
testdata << ServerAddress(HostAddress(QHostAddress("255.255.255.255")), 65535);
- QList<ServerAddress> sorted(testdata);
+ QList< ServerAddress > sorted(testdata);
std::sort(sorted.begin(), sorted.end());
QVERIFY(testdata == sorted);
}
diff --git a/src/tests/TestServerResolver/TestServerResolver.cpp b/src/tests/TestServerResolver/TestServerResolver.cpp
index cd2fbff3e..d13619860 100644
--- a/src/tests/TestServerResolver/TestServerResolver.cpp
+++ b/src/tests/TestServerResolver/TestServerResolver.cpp
@@ -3,12 +3,12 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+#include <QSignalSpy>
#include <QtCore>
#include <QtTest>
-#include <QSignalSpy>
-#include "ServerResolver.h"
#include "PlatformCheck.h"
+#include "ServerResolver.h"
void signalSpyWait(QSignalSpy &spy) {
// We increase the timeout from 5s to 8s because travis builds could fail otherwise (slow network response).
@@ -17,13 +17,13 @@ void signalSpyWait(QSignalSpy &spy) {
}
class TestServerResolver : public QObject {
- Q_OBJECT
- private slots:
- void simpleSrv();
- void srvCustomPort();
- void simpleA();
- void simpleAAAA();
- void simpleCNAME();
+ Q_OBJECT
+private slots:
+ void simpleSrv();
+ void srvCustomPort();
+ void simpleA();
+ void simpleAAAA();
+ void simpleCNAME();
};
void TestServerResolver::simpleSrv() {
@@ -37,7 +37,7 @@ void TestServerResolver::simpleSrv() {
QSignalSpy spy(&r, SIGNAL(resolved()));
QString hostname = QString::fromLatin1("simple.serverresolver.mumble.info");
- quint16 port = 64738;
+ quint16 port = 64738;
r.resolve(hostname, port);
@@ -45,7 +45,7 @@ void TestServerResolver::simpleSrv() {
QCOMPARE(spy.count(), 1);
- QList<ServerResolverRecord> records = r.records();
+ QList< ServerResolverRecord > records = r.records();
QCOMPARE(records.size(), 1);
ServerResolverRecord record = records.at(0);
@@ -85,7 +85,7 @@ void TestServerResolver::srvCustomPort() {
ServerResolver r;
QSignalSpy spy(&r, SIGNAL(resolved()));
- QString hostname = QString::fromLatin1("customport.serverresolver.mumble.info");
+ QString hostname = QString::fromLatin1("customport.serverresolver.mumble.info");
quint16 customPort = 36001;
r.resolve(hostname, 64738);
@@ -93,7 +93,7 @@ void TestServerResolver::srvCustomPort() {
QCOMPARE(spy.count(), 1);
- QList<ServerResolverRecord> records = r.records();
+ QList< ServerResolverRecord > records = r.records();
QCOMPARE(records.size(), 1);
ServerResolverRecord record = records.at(0);
@@ -129,7 +129,7 @@ void TestServerResolver::simpleCNAME() {
QSignalSpy spy(&r, SIGNAL(resolved()));
QString hostname = QString::fromLatin1("cname.serverresolver.mumble.info");
- quint16 port = 64738;
+ quint16 port = 64738;
r.resolve(hostname, port);
@@ -137,7 +137,7 @@ void TestServerResolver::simpleCNAME() {
QCOMPARE(spy.count(), 1);
- QList<ServerResolverRecord> records = r.records();
+ QList< ServerResolverRecord > records = r.records();
QCOMPARE(records.size(), 1);
ServerResolverRecord record = records.at(0);
@@ -171,7 +171,7 @@ void TestServerResolver::simpleA() {
QSignalSpy spy(&r, SIGNAL(resolved()));
QString hostname = QString::fromLatin1("simplea.serverresolver.mumble.info");
- quint16 port = 64738;
+ quint16 port = 64738;
r.resolve(hostname, port);
@@ -179,7 +179,7 @@ void TestServerResolver::simpleA() {
QCOMPARE(spy.count(), 1);
- QList<ServerResolverRecord> records = r.records();
+ QList< ServerResolverRecord > records = r.records();
// Since not all systems have IPv4 support, we have to
// skip this test if we get no matches. Not ideal, but
// at least we get some test coverage on IPv4 systems.
@@ -194,7 +194,7 @@ void TestServerResolver::simpleA() {
QCOMPARE(record.hostname(), hostname);
QCOMPARE(record.port(), port);
QCOMPARE(record.addresses().size(), 1);
- QCOMPARE(record.priority(), static_cast<qint64>(0));
+ QCOMPARE(record.priority(), static_cast< qint64 >(0));
HostAddress want(QHostAddress(QLatin1String("127.0.0.1")));
HostAddress got = record.addresses().at(0);
@@ -206,7 +206,7 @@ void TestServerResolver::simpleAAAA() {
QSignalSpy spy(&r, SIGNAL(resolved()));
QString hostname = QString::fromLatin1("simpleaaaa.serverresolver.mumble.info");
- quint16 port = 64738;
+ quint16 port = 64738;
r.resolve(hostname, port);
@@ -214,7 +214,7 @@ void TestServerResolver::simpleAAAA() {
QCOMPARE(spy.count(), 1);
- QList<ServerResolverRecord> records = r.records();
+ QList< ServerResolverRecord > records = r.records();
// Since not all systems have IPv6 support, we have to
// skip this test if we get no matches. Not ideal, but
// at least we get some test coverage on IPv6 systems.
@@ -229,7 +229,7 @@ void TestServerResolver::simpleAAAA() {
QCOMPARE(record.hostname(), hostname);
QCOMPARE(record.port(), port);
QCOMPARE(record.addresses().size(), 1);
- QCOMPARE(record.priority(), static_cast<qint64>(0));
+ QCOMPARE(record.priority(), static_cast< qint64 >(0));
HostAddress want(QHostAddress(QLatin1String("::1")));
HostAddress got = record.addresses().at(0);
diff --git a/src/tests/TestStdAbs/TestStdAbs.cpp b/src/tests/TestStdAbs/TestStdAbs.cpp
index 8e6afb6d9..1f572c3eb 100644
--- a/src/tests/TestStdAbs/TestStdAbs.cpp
+++ b/src/tests/TestStdAbs/TestStdAbs.cpp
@@ -16,14 +16,14 @@
/// function.
/// Test that it works for us.
class TestStdAbs : public QObject {
- Q_OBJECT
- private slots:
- void floatWorks();
+ Q_OBJECT
+private slots:
+ void floatWorks();
};
void TestStdAbs::floatWorks() {
const float in = -1.5;
- float out = std::abs(in);
+ float out = std::abs(in);
QVERIFY(out > 1.2 && out < 1.8);
}
diff --git a/src/tests/TestTimer/TestTimer.cpp b/src/tests/TestTimer/TestTimer.cpp
index 4dd9e5cc2..08dfb984f 100644
--- a/src/tests/TestTimer/TestTimer.cpp
+++ b/src/tests/TestTimer/TestTimer.cpp
@@ -9,10 +9,10 @@
#include "Timer.h"
class TestTimer : public QObject {
- Q_OBJECT
- private slots:
- void resolution();
- void order();
+ Q_OBJECT
+private slots:
+ void resolution();
+ void order();
};
// This tests that the timer implemented by the Timer
@@ -24,7 +24,7 @@ void TestTimer::resolution() {
t.restart();
- quint64 nchanges = 0;
+ quint64 nchanges = 0;
quint64 lastElapsed = 0;
quint64 curElapsed = 0;
@@ -36,11 +36,11 @@ void TestTimer::resolution() {
lastElapsed = curElapsed;
} while (curElapsed < 150000); // 150 ms
- quint64 totalElapsed = t.elapsed();
- double usecsPerChange = static_cast<double>(totalElapsed) / static_cast<double>(nchanges);
+ quint64 totalElapsed = t.elapsed();
+ double usecsPerChange = static_cast< double >(totalElapsed) / static_cast< double >(nchanges);
- qWarning("Total elapsed time: %llu microseconds", static_cast<unsigned long long>(totalElapsed));
- qWarning("Number of elapsed changes: %llu", static_cast<unsigned long long>(nchanges));
+ qWarning("Total elapsed time: %llu microseconds", static_cast< unsigned long long >(totalElapsed));
+ qWarning("Number of elapsed changes: %llu", static_cast< unsigned long long >(nchanges));
qWarning("Resolution: %.2f microseconds", usecsPerChange);
if (usecsPerChange >= 100.0f) {
@@ -51,7 +51,8 @@ void TestTimer::resolution() {
void TestTimer::order() {
Timer a;
- while (a.elapsed() == 0) {};
+ while (a.elapsed() == 0) {
+ };
Timer b;
diff --git a/src/tests/TestUnresolvedServerAddress/TestUnresolvedServerAddress.cpp b/src/tests/TestUnresolvedServerAddress/TestUnresolvedServerAddress.cpp
index 98fcf3971..4ec0540c8 100644
--- a/src/tests/TestUnresolvedServerAddress/TestUnresolvedServerAddress.cpp
+++ b/src/tests/TestUnresolvedServerAddress/TestUnresolvedServerAddress.cpp
@@ -9,15 +9,15 @@
#include "UnresolvedServerAddress.h"
class TestUnresolvedServerAddress : public QObject {
- Q_OBJECT
- private slots:
- void defaultCtor();
- void isValid();
- void ctor();
- void caseInsensitive();
- void equals();
- void lessThan();
- void qhash();
+ Q_OBJECT
+private slots:
+ void defaultCtor();
+ void isValid();
+ void ctor();
+ void caseInsensitive();
+ void equals();
+ void lessThan();
+ void qhash();
};
void TestUnresolvedServerAddress::defaultCtor() {
@@ -47,7 +47,7 @@ void TestUnresolvedServerAddress::isValid() {
void TestUnresolvedServerAddress::ctor() {
UnresolvedServerAddress usa(QLatin1String("mumble.info"), 443);
QCOMPARE(usa.hostname, QString::fromLatin1("mumble.info"));
- QCOMPARE(usa.port, static_cast<unsigned short>(443));
+ QCOMPARE(usa.port, static_cast< unsigned short >(443));
}
void TestUnresolvedServerAddress::caseInsensitive() {
@@ -72,7 +72,7 @@ void TestUnresolvedServerAddress::equals() {
}
void TestUnresolvedServerAddress::lessThan() {
- QList<UnresolvedServerAddress> testdata;
+ QList< UnresolvedServerAddress > testdata;
testdata << UnresolvedServerAddress();
testdata << UnresolvedServerAddress(QString(), 1);
@@ -87,11 +87,11 @@ void TestUnresolvedServerAddress::lessThan() {
testdata << UnresolvedServerAddress(QLatin1String("zaaaa"), 0);
testdata << UnresolvedServerAddress(QLatin1String("zaaaa"), 65535);
- QList<UnresolvedServerAddress> sorted(testdata);
+ QList< UnresolvedServerAddress > sorted(testdata);
std::sort(sorted.begin(), sorted.end());
int i = 0;
- foreach(const UnresolvedServerAddress &unresolved, sorted) {
+ foreach (const UnresolvedServerAddress &unresolved, sorted) {
qWarning("%i -> %s:%i", i, qPrintable(unresolved.hostname), unresolved.port);
i += 1;
}
diff --git a/src/tests/TestXMLTools/TestXMLTools.cpp b/src/tests/TestXMLTools/TestXMLTools.cpp
index df3e61ee2..535cae0a7 100644
--- a/src/tests/TestXMLTools/TestXMLTools.cpp
+++ b/src/tests/TestXMLTools/TestXMLTools.cpp
@@ -3,46 +3,46 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
-#include <QtCore>
-#include <QtTest>
+#include <QBuffer>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
-#include <QBuffer>
+#include <QtCore>
+#include <QtTest>
#include "XMLTools.h"
class TestXMLTools : public QObject {
- Q_OBJECT
- public:
- TestXMLTools(QObject *parent=0);
- private slots:
- void testParseExtractBody();
- void testParseConvertStyleBold();
- void testParseConvertStyleUnderline();
- void testParseConvertStyleItalic();
- void testParseKeepTags();
- void testParseDropEmptyFirstParagraphs();
- void testUndupNoopB();
- void testUndupNoopU();
- void testUndupNoopI();
- void testUndupNoopA();
- void testUndupSimpleB();
- void testUndupSimpleU();
- void testUndupSimpleI();
- void testUndupSimpleA();
- void testUndupMixedBU();
- void testUndupMixedBUIA();
- void testUndupWithSpace();
- void testUndupAnchor();
- void testUndupLinkSameHref();
- void testUndupLinkDifferingHref();
- void testUndupNoRootUndupTag();
- void testUndupUndupTagsRemoval();
- void testUndupStandard();
-// void testUndupInvalidXml1();
- private:
- QString doParse(QString input);
- QString doUnduplicate(QString input);
+ Q_OBJECT
+public:
+ TestXMLTools(QObject *parent = 0);
+private slots:
+ void testParseExtractBody();
+ void testParseConvertStyleBold();
+ void testParseConvertStyleUnderline();
+ void testParseConvertStyleItalic();
+ void testParseKeepTags();
+ void testParseDropEmptyFirstParagraphs();
+ void testUndupNoopB();
+ void testUndupNoopU();
+ void testUndupNoopI();
+ void testUndupNoopA();
+ void testUndupSimpleB();
+ void testUndupSimpleU();
+ void testUndupSimpleI();
+ void testUndupSimpleA();
+ void testUndupMixedBU();
+ void testUndupMixedBUIA();
+ void testUndupWithSpace();
+ void testUndupAnchor();
+ void testUndupLinkSameHref();
+ void testUndupLinkDifferingHref();
+ void testUndupNoRootUndupTag();
+ void testUndupUndupTagsRemoval();
+ void testUndupStandard();
+ // void testUndupInvalidXml1();
+private:
+ QString doParse(QString input);
+ QString doUnduplicate(QString input);
};
TestXMLTools::TestXMLTools(QObject *parent) : QObject(parent) {
@@ -54,7 +54,7 @@ QString TestXMLTools::doParse(QString input) {
QXmlStreamWriter writerOut(&outBuf);
outBuf.open(QIODevice::WriteOnly);
int paragraphs = 0;
- QMap<QString, QString> pstyle;
+ QMap< QString, QString > pstyle;
XMLTools::recurseParse(reader, writerOut, paragraphs, pstyle);
outBuf.close();
return QString(outBuf.data());
@@ -62,8 +62,10 @@ QString TestXMLTools::doParse(QString input) {
void TestXMLTools::testParseExtractBody() {
QCOMPARE(doParse(QLatin1String("<html><head></head><body>one</body></html>")), QLatin1String("one"));
- QCOMPARE(doParse(QLatin1String("<!DOCTYPE invalid><html><head></head><body>one</body></html>")), QLatin1String("one"));
- QCOMPARE(doParse(QLatin1String("<html><head><title>ttt</title></head><body>one</body></html>")), QLatin1String("one"));
+ QCOMPARE(doParse(QLatin1String("<!DOCTYPE invalid><html><head></head><body>one</body></html>")),
+ QLatin1String("one"));
+ QCOMPARE(doParse(QLatin1String("<html><head><title>ttt</title></head><body>one</body></html>")),
+ QLatin1String("one"));
QCOMPARE(doParse(QLatin1String("<html><head></head><body><b>one</b></body></html>")), QLatin1String("<b>one</b>"));
}
@@ -73,50 +75,90 @@ void TestXMLTools::testParseConvertStyleBold() {
// For fonts wiht more boldness levels, the conversion we do here from a weight value to a <b> tag is problematic.
// http://doc.qt.io/qt-4.8/stylesheet-reference.html#list-of-property-types
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:100\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:100\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:100;\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:100\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:200;\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:200\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:300;\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:300\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:400;\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:400\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:500;\">one</span></body></html>")), QLatin1String("<span style=\"font-weight:500\">one</span>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:600\">one</span></body></html>")), QLatin1String("<b>one</b>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:600;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight: 600;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight: 600\">one</span></body></html>")), QLatin1String("<b>one</b>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:100\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:100\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:100;\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:100\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:200;\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:200\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:300;\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:300\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:400;\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:400\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:500;\">one</span></body></html>")),
+ QLatin1String("<span style=\"font-weight:500\">one</span>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:600\">one</span></body></html>")),
+ QLatin1String("<b>one</b>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:600;\">one</span></body></html>")),
+ QLatin1String("<b>one</b>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight: 600;\">one</span></body></html>")),
+ QLatin1String("<b>one</b>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-weight: 600\">one</span></body></html>")),
+ QLatin1String("<b>one</b>"));
// These currently fail
-// QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:700;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
-// QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:800;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
-// QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:900;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
-// QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-weight:bold;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
+ // QCOMPARE(doParse(QLatin1String("<html><head></head><body><span
+ //style=\"font-weight:700;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
+ // QCOMPARE(doParse(QLatin1String("<html><head></head><body><span
+ //style=\"font-weight:800;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
+ // QCOMPARE(doParse(QLatin1String("<html><head></head><body><span
+ //style=\"font-weight:900;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
+ // QCOMPARE(doParse(QLatin1String("<html><head></head><body><span
+ //style=\"font-weight:bold;\">one</span></body></html>")), QLatin1String("<b>one</b>"));
}
void TestXMLTools::testParseConvertStyleUnderline() {
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"text-decoration:underline\">one</span></body></html>")), QLatin1String("<u>one</u>"));
- // We only convert spans, so this will not create a u tag
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><b style=\"text-decoration:underline\">one</b></body></html>")), QLatin1String("<b style=\"text-decoration:underline\">one</b>"));
+ QCOMPARE(doParse(QLatin1String(
+ "<html><head></head><body><span style=\"text-decoration:underline\">one</span></body></html>")),
+ QLatin1String("<u>one</u>"));
+ // We only convert spans, so this will not create a u tag
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><b style=\"text-decoration:underline\">one</b></body></html>")),
+ QLatin1String("<b style=\"text-decoration:underline\">one</b>"));
}
void TestXMLTools::testParseConvertStyleItalic() {
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><span style=\"font-style:italic\">one</span></body></html>")), QLatin1String("<i>one</i>"));
+ QCOMPARE(
+ doParse(QLatin1String("<html><head></head><body><span style=\"font-style:italic\">one</span></body></html>")),
+ QLatin1String("<i>one</i>"));
}
void TestXMLTools::testParseKeepTags() {
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><b>one</b><i>two</i><u>three</u></body></html>")), QLatin1String("<b>one</b><i>two</i><u>three</u>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><i><b><u>one</u></b></i></body></html>")), QLatin1String("<i><b><u>one</u></b></i>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><b>one</b><i>two</i><u>three</u></body></html>")),
+ QLatin1String("<b>one</b><i>two</i><u>three</u>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><i><b><u>one</u></b></i></body></html>")),
+ QLatin1String("<i><b><u>one</u></b></i>"));
}
void TestXMLTools::testParseDropEmptyFirstParagraphs() {
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p>one</p></body></html>")), QLatin1String("<p>one</p>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p>one</p><p></p></body></html>")), QLatin1String("<p>one</p><p/>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p></p><p>one</p><p></p></body></html>")), QLatin1String("<p/><p>one</p><p/>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><div>one</div></body></html>")), QLatin1String("<div>one</div>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p>one</p></body></html>")),
+ QLatin1String("<p>one</p>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p>one</p><p></p></body></html>")),
+ QLatin1String("<p>one</p><p/>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><p></p><p>one</p><p></p></body></html>")),
+ QLatin1String("<p/><p>one</p><p/>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p></p><div>one</div></body></html>")),
+ QLatin1String("<div>one</div>"));
// <br> would be invalid XML. It is not dropped "correctly".
-// QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br></p><p>one</p></body></html>")), QLatin1String("<p>one</p>"));
+ // QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br></p><p>one</p></body></html>")),
+ //QLatin1String("<p>one</p>"));
// This is different from what is expected from a comment in the method being tested. It says
// contents of empty paragraph would be dropped as well, but the br/space persists.
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br/></p><p>one</p></body></html>")), QLatin1String("<br/><p>one</p>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br /></p><p>one</p></body></html>")), QLatin1String("<br/><p>one</p>"));
- QCOMPARE(doParse(QLatin1String("<html><head></head><body><p> </p><p>one</p></body></html>")), QLatin1String(" <p>one</p>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br/></p><p>one</p></body></html>")),
+ QLatin1String("<br/><p>one</p>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p><br /></p><p>one</p></body></html>")),
+ QLatin1String("<br/><p>one</p>"));
+ QCOMPARE(doParse(QLatin1String("<html><head></head><body><p> </p><p>one</p></body></html>")),
+ QLatin1String(" <p>one</p>"));
}
QString TestXMLTools::doUnduplicate(QString input) {
@@ -146,52 +188,65 @@ void TestXMLTools::testUndupNoopA() {
}
void TestXMLTools::testUndupSimpleB() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><b>two</b></unduplicate>")), QLatin1String("<b>onetwo</b>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><b>two</b></unduplicate>")),
+ QLatin1String("<b>onetwo</b>"));
}
void TestXMLTools::testUndupSimpleU() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><u>one</u><u>two</u></unduplicate>")), QLatin1String("<u>onetwo</u>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><u>one</u><u>two</u></unduplicate>")),
+ QLatin1String("<u>onetwo</u>"));
}
void TestXMLTools::testUndupSimpleI() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><i>one</i><i>two</i></unduplicate>")), QLatin1String("<i>onetwo</i>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><i>one</i><i>two</i></unduplicate>")),
+ QLatin1String("<i>onetwo</i>"));
}
void TestXMLTools::testUndupSimpleA() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a>one</a><a>two</a></unduplicate>")), QLatin1String("<a>onetwo</a>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a>one</a><a>two</a></unduplicate>")),
+ QLatin1String("<a>onetwo</a>"));
}
void TestXMLTools::testUndupWithSpace() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><b> two</b></unduplicate>")), QLatin1String("<b>one two</b>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><b> two</b></unduplicate>")),
+ QLatin1String("<b>one two</b>"));
}
void TestXMLTools::testUndupMixedBU() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><u>two</u></unduplicate>")), QLatin1String("<b>one</b><u>two</u>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><u>two</u></unduplicate>")),
+ QLatin1String("<b>one</b><u>two</u>"));
}
void TestXMLTools::testUndupMixedBUIA() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a><i><b>one</b><u>two</u></i></a></unduplicate>")), QLatin1String("<a><i><b>one</b><u>two</u></i></a>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a><i><b>one</b><u>two</u></i></a></unduplicate>")),
+ QLatin1String("<a><i><b>one</b><u>two</u></i></a>"));
}
void TestXMLTools::testUndupAnchor() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a>one</a><a>two</a></unduplicate>")), QLatin1String("<a>onetwo</a>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a>one</a><a>two</a></unduplicate>")),
+ QLatin1String("<a>onetwo</a>"));
}
void TestXMLTools::testUndupLinkSameHref() {
QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"#\">one</a><a href=\"#\">two</a></unduplicate>")),
QLatin1String("<a href=\"#\">onetwo</a>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"http://example.org\">one</a><a href=\"http://example.org\">two</a></unduplicate>")),
- QLatin1String("<a href=\"http://example.org\">onetwo</a>"));
+ QCOMPARE(
+ doUnduplicate(QLatin1String(
+ "<unduplicate><a href=\"http://example.org\">one</a><a href=\"http://example.org\">two</a></unduplicate>")),
+ QLatin1String("<a href=\"http://example.org\">onetwo</a>"));
}
void TestXMLTools::testUndupLinkDifferingHref() {
QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"#\">one</a><a>two</a></unduplicate>")),
QLatin1String("<a href=\"#\">one</a><a>two</a>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"http://example.org\">one</a><a>two</a></unduplicate>")),
- QLatin1String("<a href=\"http://example.org\">one</a><a>two</a>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a>one</a><a href=\"http://example.org\">two</a></unduplicate>")),
- QLatin1String("<a>one</a><a href=\"http://example.org\">two</a>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"http://example.org/path1\">one</a><a href=\"http://example.org/path2\">two</a></unduplicate>")),
+ QCOMPARE(
+ doUnduplicate(QLatin1String("<unduplicate><a href=\"http://example.org\">one</a><a>two</a></unduplicate>")),
+ QLatin1String("<a href=\"http://example.org\">one</a><a>two</a>"));
+ QCOMPARE(
+ doUnduplicate(QLatin1String("<unduplicate><a>one</a><a href=\"http://example.org\">two</a></unduplicate>")),
+ QLatin1String("<a>one</a><a href=\"http://example.org\">two</a>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><a href=\"http://example.org/path1\">one</a><a "
+ "href=\"http://example.org/path2\">two</a></unduplicate>")),
QLatin1String("<a href=\"http://example.org/path1\">one</a><a href=\"http://example.org/path2\">two</a>"));
}
@@ -201,20 +256,26 @@ void TestXMLTools::testUndupNoRootUndupTag() {
}
void TestXMLTools::testUndupUndupTagsRemoval() {
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>one</b><unduplicate><unduplicate></unduplicate><b>two</b></unduplicate></unduplicate>")), QLatin1String("<b>onetwo</b>"));
+ QCOMPARE(
+ doUnduplicate(QLatin1String(
+ "<unduplicate><b>one</b><unduplicate><unduplicate></unduplicate><b>two</b></unduplicate></unduplicate>")),
+ QLatin1String("<b>onetwo</b>"));
}
void TestXMLTools::testUndupStandard() {
-
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i>italic</i></b></unduplicate>")), QLatin1String("<b>bold with <i>italic</i></b>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i></i><i>italic</i></b></unduplicate>")), QLatin1String("<b>bold with <i>italic</i></b>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i>italic</i></b></unduplicate>")),
+ QLatin1String("<b>bold with <i>italic</i></b>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i></i><i>italic</i></b></unduplicate>")),
+ QLatin1String("<b>bold with <i>italic</i></b>"));
QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>test</b></unduplicate>")), QLatin1String("<b>test</b>"));
- QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i></i><i>italic</i></b></unduplicate>")), QLatin1String("<b>bold with <i>italic</i></b>"));
+ QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with </b><b><i></i><i>italic</i></b></unduplicate>")),
+ QLatin1String("<b>bold with <i>italic</i></b>"));
}
// Will warn and fail.
-//void TestXMLTools::testUndupInvalidXml1() {
-// QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with <i></b>italic</i></unduplicate>")), QLatin1String("<b>bold with <i>italic</i></b>"));
+// void TestXMLTools::testUndupInvalidXml1() {
+// QCOMPARE(doUnduplicate(QLatin1String("<unduplicate><b>bold with <i></b>italic</i></unduplicate>")),
+//QLatin1String("<b>bold with <i>italic</i></b>"));
//}
QTEST_MAIN(TestXMLTools)