#!/usr/bin/env python
# test has been developed by Robert Harakaly and changed for SAM by Victor Galaktionov
# get information about a LFC file or directory in the name server (lfc_statgx) 
# meta: proxy=true
# meta: preconfig=../../LFC-config

import os, lfc, sys
from testClass import _test, _ntest, _testRunner, SAM_Run, LFC_VO, TEST_HOME

class test_existing_file(_test):
    def info(self):
        return "Test root dir: "

    def test(self):
        stat=lfc.lfc_filestat()
        fileid=lfc.lfc_fileid()
        ret=lfc.lfc_statx("/",fileid, stat)
        return ((stat,fileid),ret)

    def ret(self):
       return (0, None)

    def compare(self, testVal, retVal):
        ((ret, retFileid), retRetVal) = retVal
        ((test, testFileid), testRetVal) = testVal
	return retRetVal == testRetVal

class test_nonexisting_file(_test):
    def __init__(self):
        self.retVal = -1
    def info(self):
        return "Check for nonexistent file: "
    def test(self):
        stat=lfc.lfc_filestat()
        fileid=lfc.lfc_fileid()
        ret=lfc.lfc_statx("/nonexisting",fileid,stat)
        return ((stat,fileid),ret)
    def ret(self):
        retval=lfc.lfc_filestat()
        retval.fileid=0L
        retval.filemode=0
        retval.nlink=-1
        retval.uid=0
        retval.gid=0
        retval.filesize=0L
        retval.atime=0
        retval.mtime=0
        retval.ctime=0
        retval.fileclass=0
        retval.status=' '
        fileid=lfc.lfc_fileid()
        fileid.server=""
        fileid.fileid=0L
        return (retval,fileid)
    def compare(self, testVal, retVal):
        ((ret, retFileid), retRetVal) = retVal
        ((test, testFileid), testRetVal) = testVal
        if (retRetVal == testRetVal):
            retval = True
        else:
            retval = False
        return retval



class lfc_statx_test(_testRunner):
    def __init__(self):
        self.name = "lfc_statx_test"
        self.tests=[test_existing_file,test_nonexisting_file]



#************* Interface for SAM and Python tests ***************
SAM_Run(lfc_statx_test)

