1 ! Copyright (C) 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: concurrency.combinators db.pools db.sqlite db.tuples
4 db.types kernel math random threads tools.test db sequences
5 io prettyprint db.postgresql accessors io.files.temp
6 namespaces fry system math.parser db.queries assocs ;
9 : postgresql-test-db-name ( -- string )
10 cpu name>> "-" "factor-test" 3append
11 H{ { CHAR: - CHAR: _ } { CHAR: . CHAR: _ } } substitute ;
13 : postgresql-test-db ( -- postgresql-db )
17 "thepasswordistrust" >>password
18 postgresql-test-db-name >>database ;
20 : postgresql-template1-db ( -- postgresql-db )
24 "thepasswordistrust" >>password
25 "template1" >>database ;
27 : sqlite-test-db ( -- sqlite-db )
28 "tuples-test.db" temp-file <sqlite-db> ;
30 ! These words leak resources, but are useful for interactivel testing
31 : set-sqlite-db ( -- )
32 sqlite-db db-open db-connection set ;
34 : set-postgresql-db ( -- )
35 postgresql-db db-open db-connection set ;
38 : test-sqlite ( quot -- )
40 [ ] [ sqlite-test-db _ with-db ] unit-test
43 : test-postgresql ( quot -- )
44 postgresql-template1-db [
45 postgresql-test-db-name ensure-database
49 os windows? cpu x86.64? and [
50 [ ] [ postgresql-test-db _ with-db ] unit-test
55 TUPLE: test-1 id a b c ;
58 { "id" "ID" INTEGER +db-assigned-id+ }
59 { "a" "A" { VARCHAR 256 } +not-null+ }
60 { "b" "B" { VARCHAR 256 } +not-null+ }
61 { "c" "C" { VARCHAR 256 } +not-null+ }
64 TUPLE: test-2 id x y z ;
67 { "id" "ID" INTEGER +db-assigned-id+ }
68 { "x" "X" { VARCHAR 256 } +not-null+ }
69 { "y" "Y" { VARCHAR 256 } +not-null+ }
70 { "z" "Z" { VARCHAR 256 } +not-null+ }
73 : test-1-tuple ( -- tuple )
74 f 100 random 100 random 100 random [ number>string ] tri@
77 : db-tester ( test-db -- )
88 test-1-tuple insert-tuple yield
94 : db-tester2 ( test-db -- )
104 test-1-tuple insert-tuple yield