86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
#include "./helper.h"
|
|
#include "../syncthingconfig.h"
|
|
#include "../utils.h"
|
|
|
|
#include <c++utilities/tests/testutils.h>
|
|
#include <c++utilities/chrono/datetime.h>
|
|
#include <c++utilities/chrono/timespan.h>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <QUrl>
|
|
|
|
using namespace std;
|
|
using namespace Data;
|
|
using namespace ChronoUtilities;
|
|
using namespace TestUtilities;
|
|
|
|
using namespace CPPUNIT_NS;
|
|
|
|
/*!
|
|
* \brief The MiscTests class tests various features of the connector library.
|
|
*/
|
|
class MiscTests : public TestFixture
|
|
{
|
|
CPPUNIT_TEST_SUITE(MiscTests);
|
|
CPPUNIT_TEST(testParsingConfig);
|
|
CPPUNIT_TEST(testUtils);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
MiscTests();
|
|
|
|
void testParsingConfig();
|
|
void testUtils();
|
|
|
|
void setUp();
|
|
void tearDown();
|
|
|
|
private:
|
|
};
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(MiscTests);
|
|
|
|
MiscTests::MiscTests()
|
|
{}
|
|
|
|
//
|
|
// test setup
|
|
//
|
|
|
|
void MiscTests::setUp()
|
|
{}
|
|
|
|
void MiscTests::tearDown()
|
|
{}
|
|
|
|
//
|
|
// actual test
|
|
//
|
|
|
|
/*!
|
|
* \brief Tests basic behaviour of the SyncthingConnection class.
|
|
*/
|
|
void MiscTests::testParsingConfig()
|
|
{
|
|
SyncthingConfig config;
|
|
config.restore(QString::fromLocal8Bit(testFilePath("testconfig/config.xml").data()));
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("address", QStringLiteral("127.0.0.1:4001"), config.guiAddress);
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("API key", QStringLiteral("syncthingconnectortest"), config.guiApiKey);
|
|
CPPUNIT_ASSERT_MESSAGE("TLS", !config.guiEnforcesSecureConnection);
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("url", QStringLiteral("http://127.0.0.1:4001"), config.syncthingUrl());
|
|
config.guiEnforcesSecureConnection = true;
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("url", QStringLiteral("https://127.0.0.1:4001"), config.syncthingUrl());
|
|
}
|
|
|
|
void MiscTests::testUtils()
|
|
{
|
|
CPPUNIT_ASSERT_EQUAL(QStringLiteral("right now"), agoString(DateTime::now()));
|
|
CPPUNIT_ASSERT_EQUAL(QStringLiteral("5 h ago"), agoString(DateTime::now() - TimeSpan::fromHours(5.0)));
|
|
CPPUNIT_ASSERT(isLocal(QUrl(QStringLiteral("http://127.0.0.1"))));
|
|
CPPUNIT_ASSERT(isLocal(QUrl(QStringLiteral("http://[::1]"))));
|
|
CPPUNIT_ASSERT(isLocal(QUrl(QStringLiteral("http://localhost/"))));
|
|
CPPUNIT_ASSERT(!isLocal(QUrl(QStringLiteral("http://157.3.52.34"))));
|
|
}
|
|
|