feat(server): save economy hardening and CH5 continuation work
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""Run the production localized-proto search, without a language handshake stub."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
class SearchNames(unittest.TestCase):
|
||||
def test_localized_names_reload_and_bounded_strings(self):
|
||||
text=(ROOT/'src/server/game/src/offlineshop_search_manager.cpp').read_text()
|
||||
methods=text[text.index('bool COfflineShopManager::CheckItemNames'):text.index('void COfflineShopManager::SaveInMemory')]
|
||||
code=r'''
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
using BYTE=uint8_t;using DWORD=uint32_t;using LPCHARACTER=void*;
|
||||
struct TItemTable {char szLocaleName[32];DWORD dwVnum;};
|
||||
struct ITEM_MANAGER {std::vector<TItemTable> tables;static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}const auto& GetTable(){return tables;}};
|
||||
struct COfflineShopManager {
|
||||
std::map<BYTE,std::vector<std::pair<std::string,DWORD>>> m_mapItemNames;
|
||||
bool CheckItemNames(LPCHARACTER,const char*,std::vector<DWORD>&);
|
||||
void LoadSearchLanguage();
|
||||
};
|
||||
'''+methods+r'''
|
||||
int main(){
|
||||
COfflineShopManager shop;auto& tables=ITEM_MANAGER::instance().tables;
|
||||
tables={{{"Dragon Sword"},10},{{"Dragon Sword"},10},{{"龍牙"},20},{{""},30}};
|
||||
TItemTable full={};memset(full.szLocaleName,'x',sizeof(full.szLocaleName));full.dwVnum=40;tables.push_back(full);
|
||||
shop.LoadSearchLanguage();std::vector<DWORD> found;
|
||||
assert(shop.CheckItemNames(&shop,"DRAGON",found) && found==std::vector<DWORD>{10});
|
||||
found.clear();assert(shop.CheckItemNames(&shop,"龍",found) && found==std::vector<DWORD>{20});
|
||||
found.clear();assert(shop.CheckItemNames(&shop,"xxxx",found) && found==std::vector<DWORD>{40});
|
||||
assert(!shop.CheckItemNames(nullptr,"Dragon",found));assert(!shop.CheckItemNames(&shop,nullptr,found));assert(!shop.CheckItemNames(&shop,"",found));
|
||||
tables={{{"Replacement"},50}};shop.LoadSearchLanguage();found.clear();
|
||||
assert(!shop.CheckItemNames(&shop,"Dragon",found));assert(shop.CheckItemNames(&shop,"replace",found) && found==std::vector<DWORD>{50});
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
src=Path(tmp)/'probe.cpp';exe=src.with_suffix('');src.write_text(code)
|
||||
subprocess.run(['c++','-std=c++23','-fsanitize=address,undefined','-fno-sanitize-recover=all',str(src),'-o',str(exe)],check=True)
|
||||
subprocess.run([str(exe)],check=True)
|
||||
entry=(ROOT/'src/server/game/src/input_db.cpp').read_text(encoding='latin1')
|
||||
self.assertEqual(entry.count('COfflineShopManager::instance().LoadSearchLanguage();'),2)
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in New Issue
Block a user