indexing description: "General advertisement tests and helper methods" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class T_ADVERTISEMENT inherit TS_TEST_CASE redefine initialize end P2P_CREATORS_SHARED feature -- Test setup initialize is -- Test setup do create gid.make_new_with_parent (id_creator.worldgroup_id.uuid) create pid.make_new_with_group (gid.uuid) end pid: P2P_PEER_ID gid: P2P_PEERGROUP_UUID feature -- Tests dtest_lifetime (adv: P2P_ADVERTISEMENT) is -- Test general lifetime/expiration methods local a_time: DT_DATE_TIME an_adv: P2P_ADVERTISEMENT do -- initial values assert_same ("lifetime_absolute 1", Void, adv.lifetime_absolute) assert_equal ("expiration_time 1", {P2P_DISCOVERY_SERVICE}.default_expiration_time, adv.expiration_time) assert_not_same ("creation_time 1", Void, adv.creation_time) assert_false ("has_expired 1", adv.has_expired) a_time := adv.creation_time.twin assert_false ("is_newer_than 1", adv.is_newer_than (a_time)) a_time.add_minutes (1) assert_false ("is_newer_than 2", adv.is_newer_than (a_time)) a_time.add_minutes (-2) assert_true ("is_newer_than 2", adv.is_newer_than (a_time)) -- set expiration time adv.set_expiration_time (500) assert_same ("expiration_time 2", {INTEGER_64} 500, adv.expiration_time) -- set lifetime adv.set_lifetime_relative (700) assert_not_same ("lifetime_absolute 2", Void, adv.lifetime_absolute) assert_same ("expiration_time 3", {INTEGER_64} 500, adv.expiration_time) adv.set_lifetime_relative (200) assert_true ("expiration_time 4", adv.expiration_time <= 200) adv.set_lifetime_absolute (0) assert_not_same ("lifetime_absolute 3", Void, adv.lifetime_absolute) assert_same ("expiration_time 5", {INTEGER_64} 0, adv.expiration_time) -- unset lifetime adv.unset_lifetime assert_same ("lifetime_absolute 4", Void, adv.lifetime_absolute) assert_same ("expiration_time 6", {INTEGER_64} 500, adv.expiration_time) -- set lifetime from other adv an_adv := adv.twin an_adv.set_lifetime_absolute (123) adv.set_lifetime_from (an_adv) assert_equal ("lifetime_absolute 5", an_adv.lifetime_absolute, adv.lifetime_absolute) end feature {NONE} -- Implementation a_xml_doc: P2P_XML_CACHE is -- A xml cache instance do create {P2P_CONFIGURATION} Result.make_with_id (pid) ensure Result_set: Result /= Void end a_mcid: P2P_MODULE_CLASS_ID is -- A MCID do create Result.make_new ensure Result_set: Result /= Void end a_msid: P2P_MODULE_SPECIFICATION_ID is -- A MSID do create Result.make_new_with_class (a_mcid.uuid) ensure Result_set: Result /= Void end an_ea: P2P_ENDPOINT_ADDRESS is -- An endpoint address do create Result.make ("tcp", "127.0.0.1:9700") ensure Result_set: Result /= Void end an_apa: P2P_ACCESSPOINT_ADVERTISEMENT is -- An accesspoint advertisement do create Result.make Result.add_address (an_ea) ensure Result_set: Result /= Void end escape_xml_chars (a_xml_source: STRING): STRING is -- Escape XML chars require Source_valid: a_xml_source /= Void do create Result.make_from_string (a_xml_source) Result.replace_substring_all ("<", "<") Result.replace_substring_all (">", ">") Result.replace_substring_all ("&", "&") ensure Result_set: Result /= Void end end