
import os
DBNAME=os.environ.get("ODS_TEST_DB","ods:test")

from Ft.Ods import Database
from Ft.Ods.MetaData import ConstOperand
from Ft.Ods.MetaData import MetaKind
from Ft.Ods.MetaData import Constant
from Ft.Ods.MetaData import Literal
from Ft.Ods.StorageManager import Adapters
from Ft.Ods.StorageManager.Adapters import Constants
import test_operand
import test_metadata_util

def Test(tester):

    manager = Adapters.GetManager()
    adapter = Adapters.GetAdapter()
    if manager.exists(DBNAME):
        manager.reinitRepo(DBNAME,adapter)
    else:
        manager.new(DBNAME,adapter)
    
    db = Database.Database()
    db.open(DBNAME)
    
    try:
        test_operand.Test(tester,db,ConstOperand.ConstOperand)


        tester.startGroup("ConstOperand Interface %s Driver" % tester.test_data['driver'])
        test_metadata_util.test_form_drop(tester,db,ConstOperand.ConstOperand,'references',Constant.Constant)

        tester.startTest("value function")

        tx = db.new()
        tx.begin()

        l = Literal.Literal(db,None)
        l.literal_value = 1
        c = Constant.Constant(db,None)
        c.form_the_Value(l)

        co = ConstOperand.ConstOperand(db,None)
        co.form_references(c)

        tester.testResults(1,co.value(),done=0,msg="value function")

        tx.abort()

        tester.testDone()

        tester.groupDone()
    finally:
        db.close()



