Files
LihonT/tests/test_comment_photos_patch.py
cheb0chik 1d5a9a1fad LihonT 2 Luna
Ghost mode for stories and chats, several photos in one comment, .ltp plugins (rights, defender, rollback, downloads
only with consent), custom chat bubbles with a text colour of your choice, the lihont-ltp SDK and the plugin docs,
streak flames as widgets with a keeper, avatar shapes, Material 3 surfaces.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 18:19:27 +03:00

110 lines
3.6 KiB
Python

import unittest
from pathlib import Path
from lihont import comment_photos_patch
ROOT = Path(__file__).resolve().parents[1]
# LX/09Pr;->LIZ()Z of TikTok 47.1.3 as baksmali writes it (the line markers are real).
GATE = """.class public final LX/09Pr;
.super Ljava/lang/Object;
.source "SourceFile"
# static fields
.field public static final LIZ:LX/0AK0;
# direct methods
.method public static constructor <clinit>()V
.registers 2
return-void
.end method
.method public static LIZ()Z
.registers 3
.prologue
sget-object v0, LX/09Pr;->LIZ:LX/0AK0;
.line 33554432
invoke-interface {v0}, LX/0AK0;->getValue()Ljava/lang/Object;
.line 33554433
move-result-object v0
check-cast v0, Ljava/lang/Number;
invoke-virtual {v0}, Ljava/lang/Number;->intValue()I
move-result v2
if-eqz v2, :cond_14
const/4 v1, 0x1
if-eq v2, v1, :cond_14
const/4 v0, 0x2
if-eq v2, v0, :cond_15
:cond_14
const/4 v1, 0x0
:cond_15
return v1
.end method
"""
class GateTest(unittest.TestCase):
def test_the_answer_passes_through_the_hook_just_before_it_is_returned(self):
text = comment_photos_patch.rewrite_gate(GATE)
self.assertIn(
" :cond_15\n invoke-static {v1}, %s\n\n move-result v1\n\n return v1\n.end method"
% comment_photos_patch.HOOK, text)
# nothing else of the class changes
self.assertEqual(text.count("CommentPhotos"), 1)
self.assertIn("if-eq v2, v0, :cond_15", text)
self.assertIn(".registers 3", text)
def test_a_second_pass_is_refused(self):
once = comment_photos_patch.rewrite_gate(GATE)
with self.assertRaises(ValueError):
comment_photos_patch.rewrite_gate(once)
def test_another_method_shape_is_refused(self):
with self.assertRaises(ValueError):
comment_photos_patch.rewrite_gate(GATE.replace("Ljava/lang/Number;->intValue()I", "Ljava/lang/Number;->longValue()J"))
with self.assertRaises(ValueError):
comment_photos_patch.rewrite_gate(GATE.replace(".registers 3", ".registers 4"))
with self.assertRaises(ValueError):
comment_photos_patch.rewrite_gate(GATE.replace("LIZ()Z", "LIZZ()Z"))
def test_two_returns_are_refused(self):
with self.assertRaises(ValueError):
comment_photos_patch.rewrite_gate(GATE.replace(" :cond_14\n", " return v1\n :cond_14\n"))
def test_runtime_target_matches_the_hook(self):
self.assertEqual(comment_photos_patch.runtime_targets(), [comment_photos_patch.HOOK])
source = (ROOT / "src" / "lihont" / "two" / "comments" / "CommentPhotos.java").read_text(encoding="utf-8")
self.assertIn("public static boolean gate(boolean original)", source)
# the hook is the only thing that makes the answer "yes": TikTok's own answer is never turned into "no"
self.assertIn("original || on", source)
def test_the_build_applies_the_patch_and_checks_its_hook(self):
build = (ROOT / "lihont" / "upgrade.py").read_text(encoding="utf-8")
self.assertIn('step("comment_photos", patch_comment_photos', build)
self.assertIn("comment_photos_patch.runtime_targets()", build)
def test_the_settings_screen_has_the_switch_and_it_is_on_by_default(self):
screen = (ROOT / "src" / "lihont" / "two" / "settings" / "LihonTSettingsActivity.java").read_text(encoding="utf-8")
self.assertIn("commentPhotosRow()", screen)
source = (ROOT / "src" / "lihont" / "two" / "comments" / "CommentPhotos.java").read_text(encoding="utf-8")
self.assertIn("getBoolean(KEY, true)", source)
if __name__ == "__main__":
unittest.main()