telephonyserverplugins/common_tsy/test/component/ussdtestclient/src/ussdtestclient.cpp
branchopencode
changeset 85 96b4f933d69a
parent 35 6fbc08ed9c42
--- a/telephonyserverplugins/common_tsy/test/component/ussdtestclient/src/ussdtestclient.cpp	Tue Oct 19 18:11:09 2010 +0300
+++ b/telephonyserverplugins/common_tsy/test/component/ussdtestclient/src/ussdtestclient.cpp	Thu Nov 04 20:30:45 2010 +0200
@@ -18,7 +18,6 @@
 #include <e32debug.h>
 #include <e32math.h> 
 
-
 CCTsyUssdMessagingTestClient::CCTsyUssdMessagingTestClient()
     {
     }  
@@ -32,7 +31,7 @@
 @SYMTestExpectedResults Pass
 @SYMTestType CT
 */
-TInt CCTsyUssdMessagingTestClient::ReceiveMessageL(TBool aAcceptDialogue, TBool aReceiveTimeout, TReal aAfterTimePeriod)
+TInt CCTsyUssdMessagingTestClient::ReceiveMessageL(TBool aAcceptDialogue, TBool aReceiveTimeout, TReal aAfterTimePeriod, TBool aMO)
     {
     // Create a cleanup stack object
     CTrapCleanup* cleanup=CTrapCleanup::New();
@@ -114,30 +113,39 @@
     User::WaitForRequest(requestStatus);     
     //RDebug::Printf("%x << WaitForRequest", User::Identity());
     //RDebug::Printf("%x requestStatus = %d", User::Identity(), requestStatus.Int());
-    
-
+        
     if (aAfterTimePeriod)
         {
         //RDebug::Printf("%x Waiting for %f seconds", User::Identity(), aAfterTimePeriod);
         // Wait, mimic a bad client taking too long...
         User::After(aAfterTimePeriod * 1000000);
         }
-        
-    if (aAcceptDialogue)
+    
+    if(EFalse == aMO)
+    	//network initiated dialog
         {
-        //RDebug::Printf("%x >> AcceptIncomingDialogue", User::Identity());
-        // Client wants the dialogue
-        ret = ussdMessaging.AcceptIncomingDialogue(); 
-        //RDebug::Printf("%x << AcceptIncomingDialogue", User::Identity());
+    	//RDebug::Printf("NI Dialog");
+		if (aAcceptDialogue)
+			{
+			//RDebug::Printf("%x >> AcceptIncomingDialogue", User::Identity());
+			// Client wants the dialogue
+			ret = ussdMessaging.AcceptIncomingDialogue(); 
+		   //RDebug::Printf("%x << AcceptIncomingDialogue", User::Identity());
+			}
+		else
+			{
+			// Client not interested
+			//RDebug::Printf("%x >> RejectIncomingDialogue", User::Identity());
+			ret = ussdMessaging.RejectIncomingDialogue();   
+			//RDebug::Printf("%x << RejectIncomingDialogue", User::Identity());
+			}
         }
     else
-        {
-        // Client not interested
-        //RDebug::Printf("%x >> RejectIncomingDialogue", User::Identity());
-        ret = ussdMessaging.RejectIncomingDialogue();   
-        //RDebug::Printf("%x << RejectIncomingDialogue", User::Identity());
-        }
-    
+    	{
+    	//RDebug::Printf("MO Dialogue");
+    	ret = requestStatus.Int();    	
+    	}
+    //RDebug::Printf("%x Received Message: %S", User::Identity(), &name);
     User::After(2 * 1000000);
 
     ussdMessaging.Close();
@@ -199,17 +207,11 @@
         phone.Close();
         return ret; 
         }
-    
-    //RDebug::Printf(">> SendMessage");
+        
     ussdMessaging.SendMessage(requestStatus, msgData, msgAttributes);
-    //RDebug::Printf("<< SendMessage");
-    //RDebug::Printf(">> WaitForRequest");
-    User::WaitForRequest(requestStatus);     
-    //RDebug::Printf("<< WaitForRequest");
+    User::WaitForRequest(requestStatus);
     ret = requestStatus.Int();
-    //RDebug::Printf("requestStatus = %d", ret);
-
-
+    
     User::After(2 * 1000000);
 
     ussdMessaging.Close();
@@ -220,6 +222,74 @@
     return KErrNone;
     }
 
+TInt CCTsyUssdMessagingTestClient::SendMessageDefaultHandlerL()
+    {
+    // Create a cleanup stack object
+    CTrapCleanup* cleanup=CTrapCleanup::New();
+    if (cleanup==NULL)
+        return KErrNoMemory;    
+    
+    RTelServer server;
+    RMobilePhone phone;
+
+   TInt ret = server.Connect();
+   if (ret != KErrNone)
+	   {
+	   server.Close();
+	   return ret; 
+	   }
+
+   RDebug::Printf(">> server.Connect() SUCCESS!");
+       ret = phone.Open(server,KMmTsyPhoneName);
+       if (ret != KErrNone)
+           {
+           server.Close();
+           phone.Close();
+           return ret; 
+           }
+   RDebug::Printf(">> phone.Open() SUCCESS!"); 
+   TRequestStatus requestStatus;
+
+   TUint32 flags = 100;
+   RMobileUssdMessaging::TMobileUssdDataFormat format = RMobileUssdMessaging::EFormatUnspecified;
+   RMobileUssdMessaging::TMobileUssdMessageType type  = RMobileUssdMessaging::EUssdMORequest;
+   TUint8 dcs = 200;
+
+   RMobileUssdMessaging::TMobileUssdAttributesV1 attributes;
+   TPckg<RMobileUssdMessaging::TMobileUssdAttributesV1> msgAttributes(attributes);
+	
+	attributes.iFlags  = flags;
+	attributes.iFormat = format;
+	attributes.iType   = type;
+	attributes.iDcs   = dcs;
+    
+    TName name = _L("Name1");
+    TPckg<TName> msgData(name);
+    
+    RMobileUssdMessaging ussdMessaging;
+    ret = ussdMessaging.Open(phone);
+    if (ret != KErrNone)
+        {
+        server.Close();
+        phone.Close();
+        return ret; 
+        }
+    RDebug::Printf(">> ussdMessaging.Open() SUCCESS!"); 
+            
+    ussdMessaging.SendMessage(requestStatus, msgData, msgAttributes, RMobileUssdMessaging::ETransferToDefaultHandler);    
+    User::WaitForRequest(requestStatus);
+    ret = requestStatus.Int();
+    RDebug::Printf(">> ret = %d", ret);
+    
+    User::After(2 * 1000000);
+
+    ussdMessaging.Close();
+    phone.Close();
+    server.Close();
+    
+    delete cleanup;
+    return ret;
+    }
 TInt CCTsyUssdMessagingTestClient::RandomLoopL()
     {
     // Create a cleanup stack object
@@ -333,6 +403,8 @@
 _LIT(KAcceptOption,"-A");
 _LIT(KTimerOption,"-T");
 _LIT(KRandomOption,"-Random");
+_LIT(KDefaultOption,"-D");
+_LIT(KMOOption,"-M");
 TInt ParseCommandLine(TReal& aAfterTimePeriod)
     {
     TBuf<256> c;
@@ -363,6 +435,14 @@
             {               
             option |= EOptionAccept;
             }
+        else if (nextToken == KDefaultOption)
+			{               
+			option |= EOptionDefault;
+			}
+        else if (nextToken == KMOOption)
+			{               
+			option |= EOptionMO;
+			}
         else if (nextToken == KTimerOption)
             {               
             nextToken.Set(l.NextToken());
@@ -401,7 +481,7 @@
     CCTsyUssdMessagingTestClient ussdClient;
     if (option & EOptionReceive)
         {
-        TRAPD(err, ret = ussdClient.ReceiveMessageL((option & EOptionAccept), (option & EOptionReceiveTimeout), afterTimePeriod));
+        TRAPD(err, ret = ussdClient.ReceiveMessageL((option & EOptionAccept), (option & EOptionReceiveTimeout), afterTimePeriod, (option & EOptionMO)));
         }
     
     if (option & EOptionSend)
@@ -409,6 +489,11 @@
         TRAPD(err, ret = ussdClient.SendMessageL());
         }
     
+    if (option & EOptionDefault)
+		{
+		TRAPD(err, ret = ussdClient.SendMessageDefaultHandlerL());
+		}
+    
     if (option & EOptionRandom)
         {
         TRAPD(err, ret = ussdClient.RandomLoopL());