Files
Bubberstation/code/modules/unit_tests/connect_loc.dm
AnturK 4d6a8bc537 515 Compatibility (#71161)
Makes the code compatible with 515.1594+

Few simple changes and one very painful one.
Let's start with the easy:
* puts call behind `LIBCALL` define, so call_ext is properly used in 515
* Adds `NAMEOF_STATIC(_,X)` macro for nameof in static definitions since
src is now invalid there.
* Fixes tgui and devserver. From 515 onward the tmp3333{procid} cache
directory is not appened to base path in browser controls so we don't
check for it in base js and put the dev server dummy window file in
actual directory not the byond root.
* Renames the few things that had /final/ in typepath to ultimate since
final is a new keyword

And the very painful change:
`.proc/whatever` format is no longer valid, so we're replacing it with
new nameof() function. All this wrapped in three new macros.
`PROC_REF(X)`,`TYPE_PROC_REF(TYPE,X)`,`GLOBAL_PROC_REF(X)`. Global is
not actually necessary but if we get nameof that does not allow globals
it would be nice validation.
This is pretty unwieldy but there's no real alternative.
If you notice anything weird in the commits let me know because majority
was done with regex replace.

@tgstation/commit-access Since the .proc/stuff is pretty big change.

Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-15 03:50:11 +00:00

76 lines
2.7 KiB
Plaintext

#define COMSIG_MOCK_SIGNAL "mock_signal"
/// Test that the connect_loc element handles basic movement cases
/datum/unit_test/connect_loc_basic
/datum/unit_test/connect_loc_basic/Run()
var/obj/item/watches_mock_calls/watcher = allocate(/obj/item/watches_mock_calls)
var/turf/current_turf = get_turf(watcher)
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 1, "After firing mock signal, connect_loc didn't send it")
watcher.forceMove(run_loc_floor_top_right)
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 1, "Mock signal was fired on old turf, but connect_loc still picked it up")
current_turf = get_turf(watcher)
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 2, "Mock signal was fired after turf move, but it wasn't picked up")
/// Test that the connect_loc element handles turf changes
/datum/unit_test/connect_loc_change_turf
var/old_turf_type
/datum/unit_test/connect_loc_change_turf/Run()
var/obj/item/watches_mock_calls/watcher = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)
var/turf/current_turf = get_turf(watcher)
old_turf_type = current_turf.type
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 1, "After firing mock signal, connect_loc didn't send it")
current_turf.ChangeTurf(/turf/closed/wall)
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 2, "After changing turf, connect_loc didn't reconnect it")
current_turf.ChangeTurf(/turf/open/floor/carpet)
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 3, "After changing turf a second time, connect_loc didn't reconnect it")
/datum/unit_test/connect_loc_change_turf/Destroy()
run_loc_floor_bottom_left.ChangeTurf(old_turf_type)
return ..()
/// Tests that multiple objects can have connect_loc on the same turf without runtimes.
/datum/unit_test/connect_loc_multiple_on_turf
/datum/unit_test/connect_loc_multiple_on_turf/Run()
var/obj/item/watches_mock_calls/watcher_one = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)
qdel(watcher_one)
var/obj/item/watches_mock_calls/watcher_two = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)
qdel(watcher_two)
/obj/item/watches_mock_calls
var/times_called
/obj/item/watches_mock_calls/Initialize(mapload)
. = ..()
var/static/list/connections = list(
COMSIG_MOCK_SIGNAL = PROC_REF(on_receive_mock_signal),
)
AddElement(/datum/element/connect_loc, connections)
/obj/item/watches_mock_calls/proc/on_receive_mock_signal(datum/source)
SIGNAL_HANDLER
times_called += 1
#undef COMSIG_MOCK_SIGNAL