###############################################################################
#
# remoting-server.eagle --
#
# Extensible Adaptable Generalized Logic Engine (Eagle)
#
# Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: $
#
###############################################################################

source [file join [file normalize [file dirname [info script]]] prologue.eagle]

###############################################################################
# MONO: Due to lack of full support for remoting, some tests are disabled on
#       Mono.
###############################################################################

runTest {test remotingServer-1.1 {remoting server start} -setup {
  set uri remoteObject
  set error null
} -body {
  set interp [object invoke Interpreter GetActive]

  list [object invoke -alias Eagle._Tests.Default TestRemoting $interp 6000 \
      $uri SingleCall error] \
      [expr {[string length $error] > 0 ? [$error ToString] : ""}]
} -cleanup {
  unset -nocomplain uri error interp
} -constraints \
{eagle compile.TEST shell monoToDo Eagle._Tests.Default.TestRemoting} -result \
{Ok {}}}

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

runTest {test remotingServer-1.2 {remoting server simple call} -setup {
  set uri tcp://localhost:6000/remoteObject
} -body {
  list [set obj [object get -alias Eagle._Tests.Default+RemoteObject $uri]] \
      [set now [$obj -create Now]] [unset obj]
} -cleanup {
  unset -nocomplain uri obj now
} -constraints \
{eagle compile.TEST shell monoToDo Eagle._Tests.Default.TestRemoting} -match \
regexp -result {^RemoteObject#\d+ System#DateTime#\d+ {}$}}

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

runTest {test remotingServer-1.3 {remoting server complex call} -setup {
  set uri tcp://localhost:6000/remoteObject
  set result null
} -body {
  list [set obj [object get -alias Eagle._Tests.Default+RemoteObject $uri]] \
      [$obj -alias Evaluate [list return 1] None All Engine All result] \
      [expr {[string length $result] > 0 ? [$result ToString] : ""}] \
      [unset obj]
} -cleanup {
  unset -nocomplain uri obj result
} -constraints \
{eagle compile.TEST shell monoToDo Eagle._Tests.Default.TestRemoting} -match \
regexp -result {^RemoteObject#\d+ Ok 1 {}$}}

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

runTest {test remotingServer-1.4 {remoting server exit call} -setup {
  set uri tcp://localhost:6000/remoteObject
} -body {
  list [set obj [object get -alias Eagle._Tests.Default+RemoteObject $uri]] \
      [$obj Exit] [unset obj]
} -cleanup {
  unset -nocomplain uri obj
} -constraints \
{eagle compile.TEST shell monoToDo Eagle._Tests.Default.TestRemoting} -match \
regexp -result {^RemoteObject#\d+ True {}$}}

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

source [file join [file normalize [file dirname [info script]]] epilogue.eagle]
