Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.770
diff -u -r1.770 common.inc
--- includes/common.inc	30 May 2008 17:41:51 -0000	1.770
+++ includes/common.inc	3 Jun 2008 16:28:51 -0000
@@ -24,6 +24,11 @@
  */
 define('SAVED_DELETED', 3);
 
+/*
+ * Simpletest user-agent regular expression.
+ */
+define('SIMPLETEST_USER_AGENT', '/^simpletest\d+$/');
+
 /**
  * Set content for a specified region.
  *
@@ -3015,6 +3020,10 @@
     'form_element' => array(
       'arguments' => array('element' => NULL, 'value' => NULL),
     ),
+    'simpletest' => array(
+      'arguments' => array('content' => NULL),
+      'template' => 'simpletest',
+    ),
   );
 }
 
@@ -3570,3 +3579,22 @@
   }
   variable_set('css_js_query_string', $new_character . substr($string_history, 0, 19));
 }
+
+/**
+ * Generate the Drupal output response. 
+ * If the simpletest user-agent is detected, a special XML output is built. 
+ * 
+ * @param $content
+ *   The output content.
+ * @return 
+ *   The themed output, depending of the HTTP user-agent detected. 
+ * 
+ */
+function drupal_response($content) {
+  if (preg_match(SIMPLETEST_USER_AGENT, $_SERVER['HTTP_USER_AGENT'])) {
+    return theme('simpletest', $content);    
+  }
+  else {
+    return theme('page', $content);
+  }
+}
\ No newline at end of file
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.424
diff -u -r1.424 theme.inc
--- includes/theme.inc	26 May 2008 17:12:54 -0000	1.424
+++ includes/theme.inc	3 Jun 2008 16:29:03 -0000
@@ -2000,3 +2000,30 @@
   $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta;
 }
 
+function template_preprocess_simpletest(&$variables) {
+  global $theme, $user;
+  
+  // Get messages but do not clear the queue so that the messages
+  // remain available to the page output. 
+  $variables['messages'] = array();
+  foreach (drupal_get_messages(NULL, FALSE) as $type => $messages) {
+    foreach ($messages as $message) {
+      $variables['messages'][] = array('type' => $type, 'message' => $message);
+    }
+  }
+  
+  $variables['base_path']         = base_path();
+  $variables['current_path']      = $_GET['q']; ;
+  $variables['path_alias']        = drupal_get_path_alias($_GET['q'], $GLOBALS['language']);
+  $variables['title']             = drupal_get_title();
+  $variables['user']              = $user->uid;
+  $variables['front_page']        = url();
+  $variables['feed_icons']        = drupal_get_feeds();
+  $variables['language']          = $GLOBALS['language'];
+  $variables['language']->dir     = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
+  $variables['site_name']         = variable_get('site_name', 'Drupal');
+  $variables['css']               = drupal_add_css();
+  $variables['scripts']           = drupal_add_js();
+  $variables['content']           = theme('page', $variables['content']);
+  
+}
\ No newline at end of file
Index: index.php
===================================================================
RCS file: /cvs/drupal/drupal/index.php,v
retrieving revision 1.94
diff -u -r1.94 index.php
--- index.php	26 Dec 2007 08:46:48 -0000	1.94
+++ index.php	3 Jun 2008 16:28:27 -0000
@@ -33,7 +33,7 @@
 }
 elseif (isset($return)) {
   // Print any value (including an empty string) except NULL or undefined:
-  print theme('page', $return);
+  print drupal_response($return); 
 }
 
 drupal_page_footer();
Index: modules/system/simpletest.tpl.php
===================================================================
RCS file: modules/system/simpletest.tpl.php
diff -N modules/system/simpletest.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/system/simpletest.tpl.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,37 @@
+<?php
+// $Id
+
+/**
+ * @file simpletest.tpl.php
+ *
+ * Theme implementation to display a XML simpletest data output.
+ *
+ * Available variables:
+ * 
+ * @TODO: Document available variables.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_simpletest()
+ */
+?>
+<simpletest>
+  <title><?php print $title; ?></title>
+  <locale lang="" dir="" negotiation=""> 
+  <base-path><?php print $base_path; ?></base-path>
+  <current-path><?php print $current_path ; ?></current-path>
+  <path-alias><?php print $path_alias; ?></path-alias>
+  <user><?php print $user; ?></user>
+  
+  <messages>
+    <?php foreach($messages as $message): ?>
+      <message type="<?php print $message['type']; ?>"><?php print $message['message']; ?></message>
+    <?php endforeach; ?>
+  </messages>
+  
+  <content>
+    <![CDATA[ 
+      <?php print $content; ?>
+    ]]>  
+  </content>
+  
+</simpletest>
