Files
metin2-server/tests/features/test_shared_wire_headers.py
T

37 lines
1.5 KiB
Python

"""Compile common protocol headers without relying on a game-only include order."""
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT=Path(__file__).resolve().parents[2]
class SharedWireHeaders(unittest.TestCase):
def test_game_and_db_include_order_share_enabled_fields(self):
body=r'''
#include <cstdint>
#include <cstring>
#include <iostream>
using BYTE=uint8_t;using WORD=uint16_t;using DWORD=uint32_t;using LONG=int32_t;using INT=int32_t;
SERVICE
#include "src/server/common/tables.h"
static_assert(OFFLINE_SHOP_HOST_ITEM_MAX_NUM==80);
static_assert(SHOP_SIGN_MAX_LEN==45);
static_assert(PET_LEVELABLE==0 && PET_FEEDSTUFF==14);
static_assert(APPLY_RESIST_HUMAN==99);
static_assert(sizeof(TShopItemTable)==17);
int main(){
TPlayerTable player={};player.shopFlag=1;player.inventory_unlock[0]=1;
TOfflineShop shop={};OFFLINE_SHOP_ITEM item={};
std::cout<<sizeof(player)<<' '<<sizeof(shop)<<' '<<sizeof(item)<<' '<<sizeof(TShopTable);
}
'''
with tempfile.TemporaryDirectory() as tmp:
outputs=[]
for index,include in enumerate(('', '#include "src/server/common/service.h"')):
src=Path(tmp)/('probe%d.cpp'%index);exe=src.with_suffix('');src.write_text(body.replace('SERVICE',include))
subprocess.run(['c++','-std=c++23','-I'+str(ROOT),str(src),'-o',str(exe)],check=True)
outputs.append(subprocess.check_output([str(exe)]))
self.assertEqual(outputs[0],outputs[1])
if __name__=='__main__':unittest.main()