BasicTestCase.hx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package;
  2. import haxe.unit.TestCase;
  3. import sys.FileSystem;
  4. import sys.db.Connection;
  5. import sys.db.Sqlite;
  6. import sys.db.ResultSet;
  7. class BasicTestCase extends TestCase
  8. {
  9. var file : String;
  10. var cnx : Connection;
  11. public function new( )
  12. {
  13. super();
  14. file = 'basic.sqlite';
  15. }
  16. public function testOpen( ) : Void
  17. {
  18. cnx = Sqlite.open(file);
  19. assertFalse(cnx == null);
  20. assertTrue(FileSystem.exists(file));
  21. }
  22. public function testDbName( ) : Void
  23. {
  24. assertEquals("SQLite", cnx.dbName());
  25. }
  26. public function testTransaction( ) : Void
  27. {
  28. cnx.startTransaction();
  29. cnx.commit();
  30. //cnx.startTransaction();
  31. cnx.commit();
  32. assertEquals(1, 1);
  33. }
  34. public function testSelect( ) : Void
  35. {
  36. var res : ResultSet = cnx.request("SELECT 1 as a");
  37. assertFalse(res == null);
  38. assertTrue(res.hasNext());
  39. var vals = res.next();
  40. assertFalse(vals == null);
  41. assertEquals(1, vals.a);
  42. }
  43. public function testClose( ) : Void
  44. {
  45. cnx.close();
  46. assertTrue(FileSystem.exists(file));
  47. FileSystem.deleteFile(file);
  48. }
  49. }