System.Data.SQLite
Check-in [46f407ce75]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add initial tests for the session extension support classes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 46f407ce75a794bd28a868c5d4f18b7863fd5478
User & Date: mistachkin 2017-10-10 05:22:19
Original Comment: Add initial tests.
Context
2017-10-10
20:08
Add and revise tests for the session extension support classes. check-in: ca9127aa51 user: mistachkin tags: sessions
05:22
Add initial tests for the session extension support classes. check-in: 46f407ce75 user: mistachkin tags: sessions
01:27
Use the 'getTemporaryDirectory' helper procedure in the test suite. check-in: 8ee032559b user: mistachkin tags: sessions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Setup/data/verify.lst.

781
782
783
784
785
786
787

788
789
790
791
792
793
794
  Tests/data/Uninstaller_Test_Vs2013.log
  Tests/data/Uninstaller_Test_Vs2015.log
  Tests/data/wal.db
  Tests/installer.eagle
  Tests/linq.eagle
  Tests/memory.eagle
  Tests/progress.eagle

  Tests/speed.eagle
  Tests/stress.eagle
  Tests/template/
  Tests/template/empty.eagle
  Tests/thread.eagle
  Tests/tkt-00f86f9739.eagle
  Tests/tkt-0a32885109.eagle







>







781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  Tests/data/Uninstaller_Test_Vs2013.log
  Tests/data/Uninstaller_Test_Vs2015.log
  Tests/data/wal.db
  Tests/installer.eagle
  Tests/linq.eagle
  Tests/memory.eagle
  Tests/progress.eagle
  Tests/session.eagle
  Tests/speed.eagle
  Tests/stress.eagle
  Tests/template/
  Tests/template/empty.eagle
  Tests/thread.eagle
  Tests/tkt-00f86f9739.eagle
  Tests/tkt-0a32885109.eagle

Added Tests/session.eagle.







































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
###############################################################################
#
# session.eagle --
#
# Written by Joe Mistachkin.
# Released to the public domain, use at your own risk!
#
###############################################################################

package require Eagle
package require Eagle.Library
package require Eagle.Test

runTestPrologue

###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

###############################################################################

proc getRandomText { {count 5} } {
  set items [list \
      Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel \
      India Juliet Kilo Lima Mike November Oscar Papa \
      Quebec Romeo Sierra Tango Uniform Victor Whiskey X-ray \
      Yankee Zulu]

  set result [list]

  for {set i 0} {$i < $count} {incr i} {
    lappend result [lindex $items \
        [expr {int(rand() * [llength $items])}]]
  }

  return $result
}

###############################################################################

proc createSchema { db } {
  sql execute $db {
    CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
  }
}

###############################################################################

proc makeChanges { db types } {
  foreach type $types {
    switch -nocase -- $type {
      insert {
        sql execute $db {
          INSERT INTO t1(y) VALUES(?);
        } [list param1 String [getRandomText]]
      }
      update {
        sql execute $db {
          UPDATE t1 SET y = ? WHERE x = (SELECT MAX(x) FROM t1);
        } [list param1 String [appendArgs \
            "updated: " [getRandomText]]]
      }
      delete {
        sql execute $db {
          DELETE FROM t1 WHERE x = (SELECT MIN(x) FROM t1);
        }
      }
    }
  }
}

###############################################################################

proc getChangeSetFileName { {suffix ""} } {
  return [file join \
      [getTemporaryDirectory] [appendArgs changes $suffix .bin]]
}

###############################################################################

proc arrayToList { varName } {
  upvar 1 $varName array

  if {![array exists array]} {
    error [appendArgs \" $a "\" isn't an array"]
  }

  set result [list]

  foreach name [lsort -integer [array names array]] {
    lappend result $array($name)
  }

  return $result
}

###############################################################################

proc createByteArray { list } {
  set length [llength $list]
  set result [object create -alias System.Byte\[\] $length]

  for {set index 0} {$index < $length} {incr index} {
    set element [lindex $list $index]
    set value [object invoke -create Byte Parse $element]
    $result SetValue $value $index
  }

  return $result
}

###############################################################################

runTest {test session-1.1 {basic session extension usage} -setup {
  setupDb [set fileName(0) session-1.1.db]

  set fileName(1) [getChangeSetFileName 1]
  set fileName(2) [getChangeSetFileName 2]
} -body {
  createSchema $db; makeChanges $db [list insert]

  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeChanges $db [list insert update delete]

  set byteArray null
  set changeSet(1) [$session -alias CreateChangeSet byteArray]
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set stream(1) [object create -alias \
      System.IO.FileStream $fileName(1) Create Write]

  $stream(1) Write $rawData 0 [$rawData Length]
  $stream(1) Flush; $stream(1) Close

  set stream(2) [object create -alias \
      System.IO.FileStream $fileName(2) Create Write]

  set changeSet(2) [$session -alias CreateChangeSet $stream(2)]
  $stream(2) Flush; $stream(2) Close

  list [expr {[file size $fileName(1)] > 0}] \
      [string equal [readFile $fileName(1)] [readFile $fileName(2)]]
} -cleanup {
  unset -nocomplain changeSet stream rawData byteArray session

  freeDbConnection

  unset -nocomplain connection

  cleanupFile $fileName(2)
  cleanupFile $fileName(1)

  cleanupDb $fileName(0)

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
{True True}}

###############################################################################

rename createByteArray ""
rename arrayToList ""
rename getChangeSetFileName ""
rename makeChanges ""
rename createSchema ""
rename getRandomText ""

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue