Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2578149
matrix-link-test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
matrix-link-test.cpp
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<kazv-defs.hpp>
#include
<vector>
#include
<QtTest>
#include
"matrix-link.hpp"
class
MatrixLinkTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
testInvalidLink
();
void
testUserLink
();
void
testRoomLink
();
void
testEventLink
();
void
testRoutingServers
();
};
void
MatrixLinkTest::testInvalidLink
()
{
std
::
vector
<
QUrl
>
links
=
{
QUrl
(
"https://matrix.to/#"
),
QUrl
(
"https://matrix.to/#/"
),
QUrl
(
"https://matrix.to/#//"
),
QUrl
(
"https://matrix.to/#///"
),
QUrl
(
"http://matrix.to/#/%40alice%3Aexample.org"
),
QUrl
(
"https://lol.lol/#/%40alice%3Aexample.org"
),
QUrl
(
"https://matrix.to/#%40alice%3Aexample.org"
),
};
for
(
auto
link
:
links
)
{
MatrixLink
ml
(
link
);
QVERIFY
(
!
ml
.
isValid
());
}
}
void
MatrixLinkTest::testUserLink
()
{
std
::
vector
<
QUrl
>
links
=
{
QUrl
(
"https://matrix.to/#/%40alice%3Aexample.org"
),
QUrl
(
"https://matrix.to/#/@alice%3Aexample.org"
),
QUrl
(
"https://matrix.to/#/%40alice:example.org"
),
QUrl
(
"https://matrix.to/#/@alice:example.org"
),
};
for
(
auto
link
:
links
)
{
MatrixLink
ml
(
link
);
QVERIFY
(
ml
.
isUser
());
QCOMPARE
(
ml
.
identifiers
(),
QStringList
{
"@alice:example.org"
});
}
}
void
MatrixLinkTest::testRoomLink
()
{
std
::
vector
<
std
::
tuple
<
QUrl
,
QString
>>
links
=
{
{
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/%23somewhere:example.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/#somewhere%3Aexample.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/#somewhere:example.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere%3Aexample.org?via=elsewhere.ca"
),
"!somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere:example.org?via=elsewhere.ca"
),
"!somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere%3Aexample.org"
),
"!somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere:example.org"
),
"!somewhere:example.org"
},
};
for
(
auto
[
link
,
pointed
]
:
links
)
{
MatrixLink
ml
(
link
);
QVERIFY
(
ml
.
isRoom
());
QCOMPARE
(
ml
.
identifiers
(),
QStringList
{
pointed
});
}
}
void
MatrixLinkTest::testEventLink
()
{
std
::
vector
<
std
::
tuple
<
QUrl
,
QString
>>
links
=
{
{
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event%3Aexample.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org"
),
"#somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere%3Aexample.org/%24event%3Aexample.org?via=elsewhere.ca"
),
"!somewhere:example.org"
},
{
QUrl
(
"https://matrix.to/#/!somewhere%3Aexample.org/$event:example.org?via=elsewhere.ca"
),
"!somewhere:example.org"
},
};
for
(
auto
[
link
,
pointed
]
:
links
)
{
MatrixLink
ml
(
link
);
QVERIFY
(
ml
.
isRoom
());
QCOMPARE
(
ml
.
identifiers
(),
(
QStringList
{
pointed
,
"$event:example.org"
}));
}
}
void
MatrixLinkTest::testRoutingServers
()
{
QCOMPARE
(
MatrixLink
(
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org"
)).
routingServers
(),
(
QStringList
{}));
QCOMPARE
(
MatrixLink
(
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org?via=a.org"
)).
routingServers
(),
(
QStringList
{
"a.org"
}));
QCOMPARE
(
MatrixLink
(
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org?via=a.org&via=b.org"
)).
routingServers
(),
(
QStringList
{
"a.org"
,
"b.org"
}));
QCOMPARE
(
MatrixLink
(
QUrl
(
"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org?foo=bar&via=a.org&via=b.org"
)).
routingServers
(),
(
QStringList
{
"a.org"
,
"b.org"
}));
}
QTEST_MAIN
(
MatrixLinkTest
)
#include
"matrix-link-test.moc"
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Jun 24, 9:36 PM (23 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
235030
Default Alt Text
matrix-link-test.cpp (3 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment