Index: /pjproject/trunk/pjsip-apps/src/test-pjsua/mod_call.py
===================================================================
--- /pjproject/trunk/pjsip-apps/src/test-pjsua/mod_call.py	(revision 2061)
+++ /pjproject/trunk/pjsip-apps/src/test-pjsua/mod_call.py	(revision 2062)
@@ -71,5 +71,5 @@
 	# Hold call by caller
 	caller.send("H")
-	caller.sync_stdout()
+	#caller.sync_stdout()
 	caller.expect(const.MEDIA_HOLD)
 	callee.expect(const.MEDIA_HOLD)
@@ -82,7 +82,7 @@
 	time.sleep(2)
 	caller.send("v")
-	caller.sync_stdout()
-	callee.expect(const.MEDIA_ACTIVE)
-	caller.expect(const.MEDIA_ACTIVE)
+	#caller.sync_stdout()
+	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
+	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
 
 	# Synchronize stdout
@@ -100,5 +100,5 @@
 	# Hold call by callee
 	callee.send("H")
-	callee.sync_stdout()
+	#callee.sync_stdout()
 	caller.expect(const.MEDIA_HOLD)
 	callee.expect(const.MEDIA_HOLD)
@@ -111,7 +111,7 @@
 	time.sleep(2)
 	callee.send("v")
-	callee.sync_stdout()
-	caller.expect(const.MEDIA_ACTIVE)
-	callee.expect(const.MEDIA_ACTIVE)
+	#callee.sync_stdout()
+	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
+	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
 
 	# Synchronize stdout
@@ -129,7 +129,7 @@
 	# UPDATE (by caller)
 	caller.send("U")
-	caller.sync_stdout()
-	callee.expect(const.MEDIA_ACTIVE)
-	caller.expect(const.MEDIA_ACTIVE)
+	#caller.sync_stdout()
+	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
+	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
 	
 	# Synchronize stdout
@@ -144,16 +144,57 @@
 	# UPDATE (by callee)
 	callee.send("U")
-	callee.sync_stdout()
-	caller.expect(const.MEDIA_ACTIVE)
-	callee.expect(const.MEDIA_ACTIVE)
-	
-	# Synchronize stdout
-	caller.sync_stdout()
-	callee.sync_stdout()
-
-	# Test that media is okay
-	time.sleep(2)
-	check_media(caller, callee)
-	check_media(callee, caller)
+	#callee.sync_stdout()
+	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
+	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
+	
+	# Synchronize stdout
+	caller.sync_stdout()
+	callee.sync_stdout()
+
+	# Test that media is okay
+	time.sleep(2)
+	check_media(caller, callee)
+	check_media(callee, caller)
+
+	# Synchronize stdout
+	caller.sync_stdout()
+	callee.sync_stdout()
+
+	# Set codecs in both caller and callee so that there is
+	# no common codec between them.
+	# In caller we only enable PCMU, in callee we only enable PCMA
+	caller.send("Cp")
+	caller.send("* 0")
+	caller.send("Cp")
+	caller.send("pcmu 120")
+	
+	callee.send("Cp")
+	callee.send("* 0")
+	callee.send("Cp")
+	callee.send("pcma 120")
+
+	# Test when UPDATE fails (by callee)
+	callee.send("U")
+	caller.expect("SIP/2.0 488")
+	callee.expect("SIP/2.0 488")
+	callee.sync_stdout()
+	caller.sync_stdout()
+	
+	# Test that media is still okay
+	time.sleep(2)
+	check_media(caller, callee)
+	check_media(callee, caller)
+
+	# Test when UPDATE fails (by caller)
+	caller.send("U")
+	callee.expect("SIP/2.0 488")
+	caller.expect("SIP/2.0 488")
+	caller.sync_stdout()
+	callee.sync_stdout()
+	
+	# Test that media is still okay
+	time.sleep(2)
+	check_media(callee, caller)
+	check_media(caller, callee)
 
 	# Hangup call
Index: /pjproject/trunk/pjsip-apps/src/test-pjsua/run.py
===================================================================
--- /pjproject/trunk/pjsip-apps/src/test-pjsua/run.py	(revision 2061)
+++ /pjproject/trunk/pjsip-apps/src/test-pjsua/run.py	(revision 2062)
@@ -62,9 +62,10 @@
 		fullcmd = G_EXE + " " + inst_param.arg + " --stdout-refresh=5 --stdout-refresh-text=" + const.STDOUT_REFRESH
 		self.trace("Popen " + fullcmd)
-		self.proc = subprocess.Popen(fullcmd, shell=G_INUNIX, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
+		self.proc = subprocess.Popen(fullcmd, shell=G_INUNIX, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=False)
 	def send(self, cmd):
 		self.trace("send " + cmd)
 		self.proc.stdin.writelines(cmd + "\n")
-	def expect(self, pattern, raise_on_error=True):
+		self.proc.stdin.flush()
+	def expect(self, pattern, raise_on_error=True, title=""):
 		self.trace("expect " + pattern)
 		r = re.compile(pattern, re.I)
@@ -89,5 +90,5 @@
 					self.trace("Timed-out!")
 					if raise_on_error:
-						raise TestError(self.name + ": Timeout expecting pattern: " + pattern)
+						raise TestError(self.name + " " + title + ": Timeout expecting pattern: \"" + pattern + "\"")
 					else:
 						return None		# timeout
