DB Drivers test
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
new file mode 100644
index 0000000..fb40f06
--- /dev/null
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -0,0 +1,36 @@
+<?php
+
+class DB_driver_test extends CI_TestCase {
+
+	// ------------------------------------------------------------------------
+
+	public function test_initialize()
+	{
+		$config = Mock_Database_DB::config(DB_DRIVER);
+		$driver_name = current(explode('/', DB_DRIVER));
+		$driver = $this->$driver_name($config[DB_DRIVER]);
+
+		$this->assertTrue($driver->initialize());
+	}
+
+	protected function pdo($config)
+	{
+		return new Mock_Database_Drivers_PDO($config);
+	}
+
+	protected function mysql($config)
+	{
+		return new Mock_Database_Drivers_Mysql($config);
+	}
+
+	protected function sqlite($config)
+	{
+		return new Mock_Database_Drivers_Sqlite($config);
+	}
+
+	protected function pgsql($config)
+	{
+		return new Mock_Database_Drivers_Postgre($config);
+	}
+	
+}
\ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd59292..2244813 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -53,13 +53,24 @@
 			$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
 			$class = $subclass;
 		}
+		elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
+		{
+			$driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+			$dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+			$file = $dir.$m[1].'_'.$m[2].'.php';
+		}
+		elseif (strpos($class, 'CI_DB') === 0)
+		{
+			$dir = BASEPATH.'database'.DIRECTORY_SEPARATOR;
+			$file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php';
+		}
 		else
 		{
 			$class = strtolower($class);
 		}
 	}
 
-	$file = $dir.$class.'.php';
+	$file = (isset($file)) ? $file : $dir.$class.'.php';
 
 	if ( ! file_exists($file))
 	{
@@ -71,7 +82,7 @@
 		{
 			return FALSE;
 		}
-
+		var_dump($file);
 	    throw new InvalidArgumentException("Unable to load $class.");
 	}
 
diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/mocks/database/config/ci_test.sqlite
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index c6827b4..1e5043b 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -6,16 +6,19 @@
 	'pdo/sqlite' => array(
 		'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
 		'dbdriver' => 'pdo',
+		'pdodriver' => 'sqlite',
 	),
 
 	// Database configuration with failover
 	'pdo/sqlite_failover' => array(
 		'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite',
 		'dbdriver' => 'pdo',
+		'pdodriver' => 'sqlite',
 		'failover' => array(
 			array(
 				'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
 				'dbdriver' => 'pdo',
+				'pdodriver' => 'sqlite',
 			),
 		),
 	),
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d39..c30e6d2 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -45,6 +45,8 @@
 		);
 
 		$config = array_merge($this->config[$group], $params);
+		$pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
+		$failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
 
 		if ( ! empty($config['dsn']))
 		{
@@ -57,7 +59,11 @@
 
 		}
 
+		// Build the parameter
 		$other_params = array_slice($config, 6);
+		$other_params['dsn'] = $dsn;
+		if ($pdodriver) $other_params['pdodriver'] = $pdodriver;
+		if ($failover) $other_params['failover'] = $failover;
 
 		return $dsn.'?'.http_build_query($other_params);
 	}
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
new file mode 100644
index 0000000..9bf5231
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,36 @@
+<?php
+
+class Mock_Database_DB_Driver extends CI_DB_driver {
+	
+	/**
+	 * @var object The actual Driver
+	 */
+	protected $ci_db_driver;
+
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($driver_class, $config = array())
+	{
+		if (is_string($driver_class)) $this->ci_db_driver = new $driver_class($config);
+	}
+
+	/**
+	 * Overloading method, emulate the actual driver method (multiple inheritance workaround)
+	 */
+	public function __call($method, $arguments)
+	{
+		if ( ! is_callable(array($this->ci_db_driver, $method)))
+		{
+			throw new BadMethodCallException($method. ' not exists or not implemented');
+		}
+
+		return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
+	}
+}
+
+class CI_DB extends CI_DB_Driver {}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
new file mode 100644
index 0000000..34a74e2
--- /dev/null
+++ b/tests/mocks/database/drivers/mysql.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_mysql_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
new file mode 100644
index 0000000..590e195
--- /dev/null
+++ b/tests/mocks/database/drivers/pdo.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_pdo_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
new file mode 100644
index 0000000..0df9059
--- /dev/null
+++ b/tests/mocks/database/drivers/postgre.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_postgre_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
new file mode 100644
index 0000000..49c68c5
--- /dev/null
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_sqlite_driver', $config);
+	}
+}
\ No newline at end of file