コード例 #1
0
        public void TcpClient(bool serverShutdown)
        {
            ushort          port = TestBase.MakePort(56000, 57000);
            SimpleTcpServer cli  = new SimpleTcpServer(port, serverShutdown);

            cli.Start();

            string xml = string.Format(template, "ClientState", "TcpClient", "Host", port);

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            RunConfiguration config = new RunConfiguration();

            config.singleIteration = true;

            Engine e = new Engine(null);

            e.startFuzzing(dom, config);

            Assert.AreEqual(2, actions.Count);

            var de1 = actions[0].dataModel.find("TheDataModel.str");

            Assert.NotNull(de1);
            var de2 = actions[1].dataModel.find("TheDataModel2.str");

            Assert.NotNull(de2);

            string send = (string)de2.DefaultValue;
            string recv = (string)de1.DefaultValue;

            Assert.AreEqual("Hello World", send);
            Assert.AreEqual("Test buffer", recv);

            Assert.NotNull(cli.Result);
            Assert.AreEqual("Hello World", cli.Result);
        }
コード例 #2
0
        public void TcpTimeout()
        {
            ushort port = TestBase.MakePort(45000, 46000);
            var    cli  = new SimpleTcpServer(port, false, false);

            cli.Start();

            string xml = @"
<Peach>
	<DataModel name=""TheDataModel"">
		<Choice>
			<String value=""00"" token=""true""/>
			<String value=""01"" token=""true""/>
			<String value=""02"" token=""true""/>
			<String value=""03"" token=""true""/>
			<String value=""04"" token=""true""/>
			<String value=""05"" token=""true""/>
			<String value=""06"" token=""true""/>
			<String value=""07"" token=""true""/>
			<String value=""08"" token=""true""/>
			<String value=""09"" token=""true""/>
			<String name=""empty"" length=""0""/>
		</Choice>
	</DataModel>

	<StateModel name=""SM"" initialState=""InitialState"">
		<State name=""InitialState"">
			<Action name=""Recv"" type=""input"">
				<DataModel ref=""TheDataModel""/>
			</Action>
		</State>
	</StateModel>

<Test name=""Default"">
		<StateModel ref=""SM""/>
		<Publisher class=""TcpClient"">
			<Param name=""Host"" value=""127.0.0.1""/>
			<Param name=""Port"" value=""{0}""/>
			<Param name=""Timeout"" value=""1000""/>
		</Publisher>
	</Test>
</Peach>".Fmt(port);

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            RunConfiguration config = new RunConfiguration();

            config.singleIteration = true;

            Engine e = new Engine(null);

            var before = DateTime.Now;

            e.startFuzzing(dom, config);
            var after = DateTime.Now;

            var delta = after - before;

            Assert.Less(delta, TimeSpan.FromSeconds(2));
            Assert.Greater(delta, TimeSpan.FromSeconds(1));
        }