#!/usr/bin/env python

# This test suite is deprecated and is basically used for quick tests.
# Look at test-suite/ and examples/ for something useful.

import CORBA
import sys
import Fruit, Fruit__POA

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
ior = open("./test-server.ior").readline()
o = orb.string_to_object(ior)

#o.test_octseq( (0x31, 0x58, 0x68, 0x78, 0x78, 0x68) )
#o.test_octseq( "foobar")
#print map(ord, o.get_octseq())
#sys.exit(1)

try:
	o.add_fruit(Fruit.Properties(name = "orange", color = Fruit.orange))
	o.add_fruit(Fruit.Properties(name = "banana", color = Fruit.yellow))
	o.add_fruit(Fruit.Properties(name = "apple", color = Fruit.red))
	o.add_fruit(Fruit.Properties(name = "lime", color = Fruit.green))
except: pass

for fruit in o.fruit_list:
	print "%s is %s" % (fruit.name, Fruit.Color[fruit.color])

print o.fruit_list

i = o.get_instance(o.fruit_list[0])
print i
print "I've an instance of an", i.fruit.name
new_factory = i.get_factory() # test forward declaration
print "I created a new factory: ", new_factory
i.discard_factory(new_factory)
	
i.bite(50)
try: i.bite(60)
except Fruit.Instance.BigBite, exd:
	print "Got BigBite exception"
	try: i.bite(60 - exd.too_much_by)
	except Fruit.Instance.AllEaten:
		print "I'm done eating my %s; throwing it out" % i.fruit.name
		o.discard_instance(i)

print "Pi is", Fruit.Factory.pi
r = o.get_random_fruit()
print "Random fruit of the day: %s (at index %d)" % (r[1].name, r[0])

# FIXME
#union = o.test_union(Fruit.yellow)
#print "Testing union: discriminate:", union.d, "-- value:", union.v
print "Testing any:", o.test_any()

for i in range (6):
	print "Testing sequence of length "+str(i)+":", o.test_list(i)
# o.die()
