Fix possible assertion violation in text.

Fixes #31047.
This commit is contained in:
John Preston
2026-07-24 18:19:42 +04:00
parent 816bd7b677
commit 089b4ca9cb
5 changed files with 64 additions and 7 deletions
+5
View File
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "tests/test_main.h"
#include "base/base_file_utilities.h"
#include "base/invoke_queued.h"
#include "base/integration.h"
#include "ui/effects/animations.h"
@@ -171,6 +172,10 @@ int main(int argc, char *argv[]) {
auto app = App(argc, argv);
app.installNativeEventFilter(&app);
#ifdef Q_OS_MAC
base::RegisterBundledResources(u"test_text.rcc"_q);
#endif // Q_OS_MAC
const auto ratio = app.devicePixelRatio();
const auto useRatio = std::clamp(qCeil(ratio), 1, 3);
style::SetDevicePixelRatio(useRatio);
+6 -5
View File
@@ -36,6 +36,12 @@ void test(not_null<Ui::RpWindow*> window, not_null<Ui::RpWidget*> widget);
};
class App final : public QApplication, public QAbstractNativeEventFilter {
private:
auto createEventNestingLevel() {
incrementEventNestingLevel();
return gsl::finally([=] { decrementEventNestingLevel(); });
}
public:
using QApplication::QApplication;
@@ -56,11 +62,6 @@ private:
FnMut<void()> callable;
};
auto createEventNestingLevel() {
incrementEventNestingLevel();
return gsl::finally([=] { decrementEventNestingLevel(); });
}
void checkForEmptyLoopNestingLevel();
void processPostponedCalls(int level);
void incrementEventNestingLevel();
+41 -1
View File
@@ -438,7 +438,7 @@ void test(not_null<Ui::RpWindow*> window, not_null<Ui::RpWidget*> body) {
Expects(!HasEntityType(formulaMime.rich.entities, EntityType::CustomEmoji));
Expects(formulaMime.tags.size() == 1);
const auto expectedFormulaTag = TextForMimeDataTag{
.offset = formulaPosition,
.offset = int(formulaPosition),
.length = int(formulaReplacementText.size()),
.id = Ui::InputField::kTagIvMath,
};
@@ -464,6 +464,46 @@ void test(not_null<Ui::RpWindow*> window, not_null<Ui::RpWidget*> body) {
Expects(!formulaText->isOnlyCustomEmoji());
Expects(!formulaText->isIsolatedEmoji());
auto longFormulaSource = QString();
while (longFormulaSource.size() <= 4096) {
longFormulaSource.append(u"\\alpha+\\beta "_q);
}
auto longFormulaData = TextWithEntities();
longFormulaData.append(u"Before "_q);
const auto longFormulaPosition = longFormulaData.text.size();
longFormulaData.append(longFormulaSource);
longFormulaData.entities.push_back(EntityInText(
EntityType::CustomEmoji,
longFormulaPosition,
longFormulaSource.size(),
formulaEntityData));
longFormulaData.append(u" after"_q);
const auto longFormulaText = Ui::Text::String(
st::defaultTextStyle,
longFormulaData,
kMarkupTextOptions,
scale(64),
context);
Expects(longFormulaText.maxWidth() >= formulaImage.width());
Expects(longFormulaText.countHeight(scale(200)) > 0);
Expects(
longFormulaText.toString()
== u"Before "_q + formulaReplacementText + u" after"_q);
const auto longFormulaRender = RenderTextOffscreen(
longFormulaText,
scale(200));
Expects(HasPaintedPixels(longFormulaRender));
const auto longSpacedEmojiText = Ui::Text::String(
st::defaultTextStyle,
QString::fromUtf8("\xF0\x9F\x98\x80")
+ QString(4100, QChar(' '))
+ u"x"_q,
kDefaultTextOptions,
scale(64));
Expects(longSpacedEmojiText.maxWidth() > 0);
Expects(longSpacedEmojiText.countHeight(scale(200)) > 0);
auto controlData = TextWithEntities();
controlData.append(QChar::ObjectReplacementCharacter);
controlData.entities.push_back(EntityInText(
+11
View File
@@ -42,3 +42,14 @@ set_target_properties(test_text PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINA
add_dependencies(Telegram test_text)
target_prepare_qrc(test_text)
if (APPLE)
add_custom_command(TARGET test_text POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:test_text>/Contents/Resources"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/test_text.rcc"
"${CMAKE_BINARY_DIR}/lib_ui.rcc"
"$<TARGET_FILE_DIR:test_text>/Contents/Resources/"
)
endif()