#include "python_runtime.h" #include "python_net.h" #include "python_ime.h" #include "eter_ui/PythonWindowManager.h" #include "eter_ui/PythonWindow.h" #include "eter_image/GrpDevice.h" #include #include #include #include #include "test_rundir.h" int main(int argc, char** argv) { if (argc != 3) return 2; if (!ava2_test::EnterTestRunDir()) return ava2_test::kSkip; try { ava2::PythonRuntime runtime(argv[1], argv[2]); auto* wm = runtime.window_manager(); assert(wm != nullptr); // Screen size & aspect verification wm->SetScreenSize(1024, 768); wm->SetResolution(1024, 768); assert(wm->GetScreenWidth() == 1024); assert(wm->GetScreenHeight() == 768); assert(std::abs(wm->GetAspect() - (1024.0f / 768.0f)) < 0.001f); // Python integration verification runtime.execute( "import wndMgr, ui\n" "w = ui.Window()\n" "w.SetSize(200, 100)\n" "w.SetPosition(50, 60)\n" "w.Show()\n" "assert w.IsShow() == 1\n" "assert w.GetWidth() == 200\n" "assert w.GetHeight() == 100\n" "assert w.GetLocalPosition() == (50, 60)\n" "\n" "btn = ui.Button()\n" "btn.SetParent(w)\n" "btn.SetPosition(10, 20)\n" "btn.SetSize(80, 30)\n" "btn.Show()\n" "assert btn.IsShow() == 1\n" "assert btn.GetLocalPosition() == (10, 20)\n" "assert btn.GetGlobalPosition() == (60, 80)\n" "\n" "img = ui.ExpandedImageBox()\n" "img.SetParent(w)\n" "img.SetPosition(0, 0)\n" "img.LoadImage('locale/en/ui/loading/loading0.sub')\n" "img.Show()\n" "assert img.IsShow() == 1\n" "assert img.GetWidth() == 1920\n" "assert img.GetHeight() == 1080\n" "\n" "txt = ui.TextLine()\n" "txt.SetParent(w)\n" "txt.SetText('AVA2 Cross Platform')\n" "assert txt.GetText() == 'AVA2 Cross Platform'\n" "\n" "import networkModule\n" "stream = networkModule.MainStream()\n" "stream.Create()\n" "stream.SetLoginPhase()\n" "print 'Original AVA2 Login Phase with real LoginWindow loaded successfully!'\n" "lw = stream.curPhaseWindow\n" "assert lw != 0\n" "lw._LoginWindow__OpenLoginBoard()\n" "lw.idEditLine.SetText('')\n" "lw.idEditLine.KillFocus()\n" "lw.idEditLine.SetFocus()\n" ); // Exercise the original login controls through mouse/focus and IME events. auto* accountInput = wm->GetActivateWindow(); if (!accountInput) throw std::runtime_error("Login account has no focus"); const auto accountRect = accountInput->GetRect(); runtime.execute("lw.idEditLine.KillFocus()\n"); wm->RunMouseLeftButtonDown(accountRect.left + 5, accountRect.top + 5); wm->RunMouseLeftButtonUp(accountRect.left + 5, accountRect.top + 5); if (wm->GetActivateWindow() != accountInput) throw std::runtime_error("Click did not focus account field"); if (!ava2::IME_IsCaptureInput()) throw std::runtime_error("Login account does not capture text"); ava2::IME_InsertText("player1"); runtime.execute("assert lw.idEditLine.GetText() == 'player1', repr(lw.idEditLine.GetText())\n"); wm->RunIMETabEvent(); auto* passwordInput = wm->GetActivateWindow(); if (!passwordInput || passwordInput == accountInput) throw std::runtime_error("Tab did not focus password field"); const auto passwordRect = passwordInput->GetRect(); runtime.execute("lw.pwdEditLine.KillFocus()\n"); wm->RunMouseLeftButtonDown(passwordRect.left + 5, passwordRect.top + 5); wm->RunMouseLeftButtonUp(passwordRect.left + 5, passwordRect.top + 5); if (wm->GetActivateWindow() != passwordInput) throw std::runtime_error("Click did not focus password field"); ava2::IME_InsertText("password123x"); ava2::IME_OnBackspace(); runtime.execute( "assert lw.pwdEditLine.GetText() == 'password123', repr(lw.pwdEditLine.GetText())\n" "assert lw.idEditLine.GetText() == 'player1'\n" "assert lw.pwdEditLine.GetText() == 'password123'\n" "stream.SetConnectInfo('127.0.0.1', 13000, '127.0.0.1', 11002)\n" "lw.loginButton.CallEvent()\n" "print 'Login button event executed successfully and triggered network stream connect!'\n" ); // Setup mock character data for character selection ava2::Character c0; c0.id = 1001; c0.name = "WarriorHero"; c0.job = 0; // RACE_WARRIOR_M c0.level = 75; c0.strength = 90; c0.dexterity = 40; c0.health = 90; c0.intelligence = 20; c0.main_part = 11299; // Black Steel Armor c0.play_minutes = 3600; ava2::set_mock_character(0, c0); ava2::set_mock_empire(1); // Empire A (Shinsoo) runtime.execute( "stream.SetSelectCharacterPhase()\n" "print 'Original AVA2 Select Character Phase loaded successfully!'\n" "sw = stream.curPhaseWindow\n" "assert sw != 0\n" "assert sw.GetCharacterSlotID(0) == 1001\n" "assert sw.CharacterSlot_0_Name.GetText() == 'WarriorHero'\n" "print 'SelectCharacterWindow successfully rendered slot 0 with name: ' + sw.CharacterSlot_0_Name.GetText()\n" "\n" "# Transition to Create Character Phase\n" "import net\n" "stream.SetCharacterSlot(1)\n" "stream.SetCreateCharacterPhase()\n" "print 'Original AVA2 Create Character Phase loaded successfully!'\n" "cw = stream.curPhaseWindow\n" "assert cw != 0\n" "# Select Sura class (slot 2)\n" "cw.CharacterSlot_2.CallEvent()\n" "# Select Male gender (button 0)\n" "cw.genderButtonList[0].CallEvent()\n" "# Select Shape 1\n" "cw.shapeButtonList[1].CallEvent()\n" "# Set Character Name\n" "cw.editCharacterName.SetText('SuraMage')\n" "assert cw.editCharacterName.GetText() == 'SuraMage'\n" "# Trigger creation\n" "cw.btnCreate.CallEvent()\n" "# Dispatch creation packet and trigger successful creation transition\n" "net.SendCreateCharacterPacket(1, 'SuraMage', cw.reservingRaceIndex, cw.reservingShapeIndex, 3, 5, 5, 3)\n" "sw2 = stream.curPhaseWindow\n" "assert sw2 != 0\n" "assert sw2.CharacterSlot_1_Name.GetText() == 'SuraMage'\n" "print 'Character creation successfully created SuraMage in slot 1 and returned to SelectCharacterWindow!'\n" "\n" "# Transition to Loading Phase\n" "stream.SetLoadingPhase()\n" "print 'Original AVA2 Loading Phase loaded successfully!'\n" "load_wnd = stream.curPhaseWindow\n" "assert load_wnd != 0\n" "\n" "import app\n" "stream.SetGamePhase()\n" "gw = stream.curPhaseWindow\n" "assert gw != 0\n" "gw.Open()\n" "gw.OnUpdate()\n" "gw.OnRender()\n" "gw.OnKeyDown(app.DIK_W)\n" "gw.OnKeyUp(app.DIK_W)\n" "gw.OnKeyDown(app.DIK_I)\n" "print 'Original AVA2 Game Phase loaded and updated successfully!'\n" ); SDL_Surface* surface = SDL_CreateSurface(1024, 768, SDL_PIXELFORMAT_RGBA32); assert(surface != nullptr); SDL_Renderer* renderer = SDL_CreateSoftwareRenderer(surface); assert(renderer != nullptr); CGraphicDevice device; device.Init(renderer); device.BeginScene(); wm->Update(); wm->Render(); device.EndScene(); // Verify offscreen surface has rendered UI content uint32_t* pixels = reinterpret_cast(surface->pixels); bool hasNonZeroPixel = false; for (int i = 0; i < 1024 * 768; ++i) { if (pixels[i] != 0) { hasNonZeroPixel = true; break; } } assert(hasNonZeroPixel && "UI and real texture rendering produced visible pixels"); device.Init(nullptr); SDL_DestroyRenderer(renderer); SDL_DestroySurface(surface); fprintf(stderr, "=== TEST REACHED END SUCCESSFULLY ===\n"); std::cout << "AVA2 Window Manager & Window tree & Real image loading & SDL3 2D rendering passed successfully!" << std::endl; return 0; } catch (const std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; return 1; } }