Agility eLetter July 2005

In this issue...

In this issue, we have a detailed article on Unit Testing C++ Code – CppUnit by Example.

Abstract: JUnit for Java popularized unit testing and developers using different languages are benefiting from appropriate tools to help with unit testing. In this article, I show–using examples–how to create unit tests for your C++ applications. Please visit http://www.agiledeveloper.com/download.aspx to download the complete article from the Agile Developer web site.

Message from us

If you would like any question to be addressed or topic to be discussed, please send us an email at agility@agiledeveloper.com. We love to hear from you.

 

Please send suggestions, corrections and comments to agility@agiledeveloper.com

Quiz corner

What new keyword in .NET 2.0 (C#) allows you to write coroutines?

 

Quiz from the past issue

I have a web service at http://www.agiledeveloper.com/venkat/wsmay2005/Service1.asmx. The service’s GetInfo() method simply returns a random number after a 2 seconds delay. Here is the C# code I use to talk to that web service (Thanks to Brandt for leading me into this trap on his project earlier this year J):
using System;

 

namespace CallWS

{

      class Test

      {

            static void CallService()

            {

                  wsmay2005.Service1 service =

                           new CallWS.wsmay2005.Service1();

                  int start = Environment.TickCount;

                  service.GetInfo();

                  int end = Environment.TickCount;

                  Console.WriteLine("Time elapsed {0}",

                                          (end - start)/1000);

            }

 

            static void CallServiceAsynch()

            {

                  wsmay2005.Service1 service =

                          new CallWS.wsmay2005.Service1();

                  int start = Environment.TickCount;

                  service.BeginGetInfo(

                        new AsyncCallback(CallReturned), start);

            }

 

            static void CallReturned(IAsyncResult ar)

            {

                  int end = Environment.TickCount;

                  int start = (int) ar.AsyncState;

                  Console.WriteLine("Time elapsed {0}",

                                           (end - start)/1000);

            }

 

            [STAThread]

            static void Main(string[] args)

            {

                  Console.WriteLine("Making two synchronous calls");

                  CallService();               

                  CallService();

 

                  Console.WriteLine("Making four asynchronous calls");

                  CallServiceAsynch();

                  CallServiceAsynch();

                  CallServiceAsynch();

                  CallServiceAsynch();

 

                  Console.ReadLine();

            }

      }

}


The output I get is:

Making two synchronous calls

Time elapsed 2

Time elapsed 2

Making four asynchronous calls

Time elapsed 2

Time elapsed 2

Time elapsed 4

Time elapsed 4

 

Fix the above code (minimum change) so I get the following output:

Making two synchronous calls

Time elapsed 2

Time elapsed 2

Making four asynchronous calls

Time elapsed 2

Time elapsed 2

Time elapsed 2

Time elapsed 2

There should still be two synchronous calls and four asynchronous calls. Send in your response and if your response is the first correct response, you will be the winner of the double dip bonus!

Send your response to agility@agiledeveloper.com. This year, each person with the first correct response to the quiz in each issue of Agility will win a special prize.

Answer!

Cisco earned the May Agility Special Double Dip Prize by sending the first correct response. Set System.Net.ServicePointManager.DefaultConnectionLimit = 5 or set service.ConnectionGroupName to a unique value.

Subscription Information

To subscribe or unsubscribe to the free issues of Agility eLetter, please visit http://www.agiledeveloper.com/eLetter.aspx.

Thus spake...

"It is better to light one candle than curse the darkness," Chinese Proverb.