###############################################################################
#
# tkt-17045010df.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

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

runTest {test tkt-17045010df-1.1 {EnableExtensions & LoadExtension} -setup {
  setupDb [set fileName tkt-17045010df-1.1.db]
} -body {
  set connection [getDbConnection]

  lappend result [catchAndReturn {$connection EnableExtensions false}]

  lappend result [catchAndReturn {$connection LoadExtension \
      [getCoreExtensionBinaryFileName null] interop_test_extension_init}]

  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test1');"}]
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test1', '1234');"}]

  lappend result [catchAndReturn {$connection EnableExtensions true}]

  lappend result [catchAndReturn {$connection LoadExtension \
      [getCoreExtensionBinaryFileName null] interop_test_extension_init}]

  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2');"}]
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2', '5678');"}]

  set result
} -cleanup {
  freeDbConnection

  unset -nocomplain result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28\
defineConstant.System.Data.SQLite.INTEROP_TEST_EXTENSION command.sql\
compile.DATA SQLite System.Data.SQLite SQLiteInterop} -match regexp -result \
{^\{0 \{\}\} \{1 \{EXCEPTION System\.Data\.SQLite\.SQLiteException\
System\.Data\.SQLite\.SQLite3\.LoadExtension\} \{SQL logic error( or missing\
database)? -- not authorized\}\} \{1 \{EXCEPTION\
System\.Data\.SQLite\.SQLiteException System\.Data\.SQLite\.SQLite3\.Prepare\}\
\{SQL logic error( or missing database)? -- no such function: interopTest\}\}\
\{1 \{EXCEPTION System\.Data\.SQLite\.SQLiteException\
System\.Data\.SQLite\.SQLite3\.Prepare\} \{SQL logic error( or missing\
database)? -- no such function: interopTest\}\} \{0 \{\}\} \{0 \{\}\} \{0\
test2\} \{1 \{EXCEPTION System\.Data\.SQLite\.SQLiteException\
System\.Data\.SQLite\.SQLite3\.Reset\} \{SQL logic error( or missing database)?\
-- need exactly one argument\}\}$}}

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

runSQLiteTestEpilogue
runTestEpilogue
