#include "drop_item_state.h" #include "python_runtime.h" #include "eter_net/PythonNetworkStream.h" #include #include using namespace ava2; using Bytes=std::vector; void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);} void u32(Bytes& b,uint32_t value) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(value>>(8*i)));} Bytes record(const std::string& name="Wolf") { Bytes b{220,3};for(unsigned i=0;i<100;++i)b.push_back(iSetSleep(true);python.execute("drop.Open()\ndrop.SearchItem(0)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent drop request");instance->SetSleep(false); python.execute("temporary=Loader()\nref=weakref.ref(temporary)\ndrop.SetDropItemHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n"); send(control(4));send(control(5));python.execute("assert ref() is not None and ref().events==[(0,1)]\ndrop.SetDropItemHandler(None)\ngc.collect()\nassert ref() is None\nclass Broken:\n def BINARY_DROP_ITEM_LOADING(self): raise ValueError('expected failure')\ndrop.SetDropItemHandler(Broken())\n"); send(record());send(control(5));python.execute("assert drop.CountDates()==1\ndrop.SetPageSelect(99)\n"); require(stream.GetUnportedPackets().empty(),"drop receive still uses skip handler");stream.ResetConnection(); } {PythonRuntime python(argv[1],argv[2]);python.execute("import drop_item as drop\nassert drop.CountDates()==0 and drop.GetPageActual()==1\n");} std::cout<<"AVA2 drop item state, wire and Python parity passed\n"; }catch(const std::exception& e){std::cerr<