Exemple #1
0
    public bool NegTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest2: The IDictionary is readonly");

        try
        {
            IDictionary iDictionary = new MyIDictionary();
            iDictionary.Remove(new MyClass());
            TestLibrary.TestFramework.LogError("103", "The NotSupportedException was not thrown as expected");
            retVal = false;
        }
        catch (NotSupportedException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
        public ProgramState Execute(ProgramState state)
        {
            MyIDictionary <int, MyPair <string, StreamReader> > fileTable = state.GetFileTab();
            MyIDictionary <string, int> symTable = state.GetSymTab();

            // 1. evaluate var_file_id to a value. If any error occurs, stop the execution
            int value;

            try
            {
                value = var_file_id.Evaluate(symTable);
            }
            catch (ExpressionEvaluationException e)
            {
                throw new MyStatementExecutionException("The file is not opened for reading.");
            }

            // 2. Use the value to get the entry into the file table and get the associated StreamReader
            // object. If there is no entry in the file table for the value, we stop the execution
            StreamReader sr;

            try
            {
                sr = fileTable.Get(value).GetSecond();
            }
            catch (InvalidKeyMyDictionaryException)
            {
                throw new MyStatementExecutionException("Error. There is no entry (" + value + ") in the file table.");
            }

            // 3. call the Close() method
            try
            {
                sr.Close();
            }
            catch (IOException e)
            {
                throw new MyStatementExecutionException("IO Error: " + e.ToString());
            }

            // 4. delete the entry from the file table
            try
            {
                fileTable.Remove(value);
            }
            catch (InvalidKeyMyDictionaryException)
            {
                throw new MyStatementExecutionException("Error. There is no entry (" + value + ") in the file table.");
            }

            // 5. return
            return(null);
        }
Exemple #3
0
        public void Remove(int fileDescriptor)
        {
            if (!fileTable.TryGetValue(fileDescriptor, out Tuple <string, TextReader> value))
            {
                throw new FileTableException("File is not in the file table!");
            }

            value.Item2.Close();

            fileTable.Remove(fileDescriptor);

            positionTable.FreePosition(fileDescriptor);
        }
    public bool NegTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest2: The IDictionary is readonly");

        try
        {
            IDictionary iDictionary = new MyIDictionary();
            iDictionary.Remove(new MyClass());
            TestLibrary.TestFramework.LogError("103", "The NotSupportedException was not thrown as expected");
            retVal = false;
        }
        catch (NotSupportedException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }