Index: includes/schema.test
===================================================================
RCS file: includes/schema.test
diff -N includes/schema.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/schema.test	10 May 2008 20:18:04 -0000
@@ -0,0 +1,68 @@
+<?php
+// $Id: xmlrpc.test,v 1.2 2008/05/09 20:13:41 dries Exp $
+
+class SchemaApiTest extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name'  => t('Schema API tests'),
+      'description'  => t('Tests various aspects of the Schema API.'),
+      'group' => t('Database')
+    );
+  }
+
+  function testUnsignedTypes() {
+    $ret = array();
+
+    $types = array(
+      'int' => array(0, 10, -10),
+      'float' => array(0, 10.0, -10.0),
+      'numeric' => array('0.00', '10.00', '-10.00'),
+      );
+
+    foreach ($types as $type => $vals) {
+      $table = 'test_type_' . $type;
+      $schema = array(
+        'fields' => array(
+          'col_sign' => array('type' => $type, 'unsigned' => FALSE),
+          'col_unsign' => array('type' => $type, 'unsigned' => TRUE),
+          ),
+        );
+
+      if (db_table_exists($table)) {
+        db_drop_table($ret, $table);
+      }
+      db_create_table($ret, $table, $schema);
+
+      $param = db_type_placeholder($type);
+      $query = 'SELECT COUNT(*) FROM {' . $table . '} WHERE %s = ' . $param;
+
+      db_query('INSERT INTO {' . $table . "} (col_sign, col_unsign) VALUES ($vals[0], $vals[0])");
+      $this->assertIdentical('1', db_result(db_query($query, 'col_sign', $vals[0])),
+        "Signed $type can hold zero value.");
+      $this->assertIdentical('1', db_result(db_query($query, 'col_unsign', $vals[0])),
+        "Unsigned $type can hold zero value.");
+
+      db_query('INSERT INTO {' . $table . "} (col_sign, col_unsign) VALUES ($vals[1], $vals[1])");
+      $this->assertIdentical('1', db_result(db_query($query, 'col_sign', $vals[1])),
+        "Signed $type can hold positive value.");
+      $this->assertIdentical('1', db_result(db_query($query, 'col_unsign', $vals[1])),
+        "Unsigned $type can hold positive value.");
+
+      db_query('INSERT INTO {' . $table . "} (col_sign) VALUES ($vals[2])");
+      $this->assertIdentical('1', db_result(db_query($query, 'col_sign', $vals[1])),
+        "Signed $type can hold negative value.");
+
+      // On mysql, this insert succeeds but inserts a zero value.  On
+      // pgsql, it fails with a constraint violation.
+      @db_query('INSERT INTO {' . $table . "} (col_unsign) VALUES ($vals[2])");
+      $this->assertIdentical('0', db_result(db_query($query, 'col_unsign', $vals[2])),
+        "Unsigned $type cannot hold negative value.");
+      
+      db_drop_table($ret, $table);
+    }
+  }
+}
+?>
