indexing description: "Tests the route advertisement" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class TEST_ROUTE_ADVERTISEMENT inherit T_ADVERTISEMENT feature -- Tests test_setters is -- Test setters/getters local ra: P2P_ROUTE_ADVERTISEMENT dapa, hapa: P2P_ACCESSPOINT_ADVERTISEMENT do -- create accesspoint advertisement dapa := an_apa create ra.make (dapa) assert_same ("destination_peer_id 1", Void, ra.destination_peer_id) assert_equal ("destination", dapa, ra.destination) assert_equal ("hops.count 1", 0, ra.hops.count) assert_same ("unique_id 1", Void, ra.unique_id) assert_same ("index_elements.count 1", 0, ra.index_elements.count) assert_false ("match DstPID 1", ra.match ("DstPID", Void)) -- set peer id ra.set_destination_peer_id (pid) assert_equal ("destination_peer_id 2", pid, ra.destination_peer_id) assert_equal ("unique_id 2", "RA-" + pid.out_short, ra.unique_id) assert_same ("index_elements.count 2", 1, ra.index_elements.count) assert_true ("match DstPID 2", ra.match ("DstPID", pid.out)) assert_true ("match DstPID 3", ra.match ("DstPID", Void)) -- add hop hapa := an_apa ra.add_hop (hapa) assert_true ("hops.has 1", ra.hops.has (hapa)) assert_equal ("hops.count 2", 1, ra.hops.count) -- remove hop ra.remove_hop (hapa) assert_false ("hops.has 2", ra.hops.has (hapa)) assert_equal ("hops.count 3", 0, ra.hops.count) end test_document is -- Test document parsing/creating local ra: P2P_ROUTE_ADVERTISEMENT source, dapaout, hapaout: STRING dapa, hapa: P2P_ACCESSPOINT_ADVERTISEMENT do dapa := an_apa dapa.document.document.root_element.set_namespace (dapa.document.namespace_empty) dapaout := dapa.out dapaout := dapaout.substring (dapa.document.xml_header.count + 1, dapaout.count) hapa := an_apa hapa.add_address (an_ea) hapa.document.document.root_element.set_namespace (hapa.document.namespace_empty) hapaout := hapa.out hapaout := hapaout.substring (hapa.document.xml_header.count + 1, hapaout.count) source := "%N% %" + pid.out + "" + dapaout + "% %" + hapaout + "" -- parse create ra.parse_from_string (source) assert_true ("is_valid", ra.is_valid) assert_equal ("destination_peer_id", pid, ra.destination_peer_id) assert_equal ("destination", dapa.out, ra.destination.out) assert_equal ("hops", 1, ra.hops.count) assert_equal ("hops.item(1)", hapa.out, ra.hops.item (1).out) -- create ra.renew_document assert_equal ("document", source, ra.document.out) end test_general is -- Test general advertisement local ra: P2P_ROUTE_ADVERTISEMENT do create ra.make (an_apa) dtest_lifetime (ra) end end